2015-05-18 52 views
4

我需要使用maven构建exe文件。我听说这个gradle更适合这个目的,但我什至不知道它。我的当前.pom文件:需要帮助配置maven .pom来构建.exe文件

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.ediagent.edi</groupId> 
    <artifactId>javafx</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>exe</packaging> 

    <name>javafx</name> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <mainClass>com.myapp.Main</mainClass> 
    </properties> 

    <organization> 
     <!-- Used as the 'Vendor' for JNLP generation --> 
     <name>Your Organisation</name> 
    </organization> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.6</version> 
       <executions> 
        <execution> 
         <id>unpack-dependencies</id> 
         <phase>package</phase> 
         <goals> 
          <goal>unpack-dependencies</goal> 
         </goals> 
         <configuration> 
          <excludeScope>system</excludeScope> 
          <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds> 
          <outputDirectory>${project.build.directory}/classes</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <id>unpack-dependencies</id> 

         <phase>package</phase> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
         <configuration> 
          <executable>${java.home}/../bin/javafxpackager</executable> 
          <arguments> 
           <argument>-createjar</argument> 
           <argument>-nocss2bin</argument> 
           <argument>-appclass</argument> 
           <argument>${mainClass}</argument> 
           <argument>-srcdir</argument> 
           <argument>${project.build.directory}/classes</argument> 
           <argument>-outdir</argument> 
           <argument>${project.build.directory}</argument> 
           <argument>-outfile</argument> 
           <argument>${project.build.finalName}.jar</argument> 
          </arguments> 
         </configuration> 
        </execution> 
        <execution> 
         <id>default-cli</id> 
         <goals> 
          <goal>exec</goal>        
         </goals> 
         <configuration> 
          <executable>${java.home}/bin/java</executable> 

         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <compilerArguments> 
         <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath> 
        </compilerArguments> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.16</version> 
       <configuration> 
        <additionalClasspathElements> 
         <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement> 
        </additionalClasspathElements> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>native-maven-plugin</artifactId> 
       <extensions>true</extensions> 
       <configuration> 
        <executable>${java.home}/bin/java</executable> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

建筑物.exe是否有足够的信息?如果不是我需要添加的内容以及接下来要做什么?

+0

如果提取的信息你想要一个.exe,Java不是这个工作的正确语言。如果你仍然需要它,有足够的工具可以从.jar生成一个.exe文件,但首先,问问你自己:为什么? – Stultuske

+0

@Stultuske为什么? 1)主要的要求是在java上编写项目。 2)java - 是我目前唯一知道的语言 –

+0

Java是独立于平台的。通过创建一个exe文件,你不会添加.jar文件无法提供的任何功能,但是由于.exe是一个Windows本机操作系统,因此您可以使其与平台相关。 – Stultuske

回答

4

要创建一个.exe文件,我建议你以下Maven插件:

阴影插件。 http://maven.apache.org/plugins/maven-shade-plugin/

  <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <createDependencyReducedPom>false</createDependencyReducedPom> 
          <filters> 
           <filter> 
            <artifact>*:*</artifact> 
            <excludes> 
             <exclude>META-INF/*.SF</exclude> 
             <exclude>META-INF/*.DSA</exclude> 
             <exclude>META-INF/*.RSA</exclude> 
             <exclude>.settings/**</exclude> 
             <exclude>*.classpath</exclude> 
             <exclude>*.project</exclude> 
             <exclude>*.txt</exclude> 
            </excludes> 
           </filter> 
          </filters> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

并创建一个完整的.exe包括全部或.exe其推出的所有一个.jar,使用launch4j插件https://github.com/lukaszlenart/launch4j-maven-plugin

  <plugin> 
       <groupId>com.akathist.maven.plugins.launch4j</groupId> 
       <artifactId>launch4j-maven-plugin</artifactId> 
       <version>1.5.2</version> 
       <executions> 
        <execution> 
         <id>l4j-gui</id> 
         <phase>package</phase> 
         <goals> 
          <goal>launch4j</goal> 
         </goals> 
         <configuration> 
          <headerType>gui</headerType> 
          <outfile>target/Project.exe</outfile> 
          <jar>target/${project.artifactId}-${project.version}.jar</jar> 
          <!-- if <dontWrapJar>true</dontWrapJar> change to this conf <jar>${project.artifactId}-${project.version}.jar</jar> --> 
          <dontWrapJar>false</dontWrapJar> 
          <errTitle>Error in launch4j plugin</errTitle> 
          <classPath> 
           <mainClass>path.Main</mainClass> 
          </classPath> 
          <icon>Project.ico</icon> 
          <jre> 
           <minVersion>1.5.0</minVersion> 
           <maxVersion>1.6.0</maxVersion> 
           <initialHeapSize>512</initialHeapSize> 
           <maxHeapSize>1024</maxHeapSize> 
          </jre> 
          <versionInfo> 
           <fileVersion>1.0.0.0</fileVersion> 
           <txtFileVersion>1.0.0.0</txtFileVersion> 
           <fileDescription>des</fileDescription> 
           <copyright>Copyright (c) 2014 </copyright> 
           <companyName>comp</companyName> 
           <productVersion>3.0.0.0</productVersion> 
           <txtProductVersion>${project.version}</txtProductVersion> 
           <productName>Project</productName> 
           <internalName>Project</internalName> 
           <originalFilename>Project.exe</originalFilename> 
          </versionInfo> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

我从Clean and Build a Maven Project with Netbeans - Compilation failure