我有一个java应用程序并尝试创建一个exe文件以在Windows计算机上运行它。但是,我花了两个小时才能让它运转起来。
我的maven构建插件如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</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>
<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>com.calculator.Application</mainClass>
</classPath>
<jre>
<minVersion>1.8.0</minVersion>
<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>
</plugins>
</build>
当我运行mvn clean install命令时,会创建所有exe,jar和其他文件。但是当我从命令行运行Project.exe时,就会发生这种情况。
我的应用程序类如下:
@Configuration
@ComponentScan("com.calcutor.*")
public class Application implements ApplicationContextAware{
private static ApplicationContext applicationContext;
public static void main(String[] args) {
System.out.println("Works");
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
@Override
public void setApplicationContext(ApplicationContext
applicationContext) throws BeansException {
Application.applicationContext = applicationContext;
}
}
我无法看到我失踪的东西;