【发布时间】:2017-02-21 05:07:17
【问题描述】:
我正在开发一个应用程序,它接受一些参数、向服务器发送一些数据并接收响应。它只会被另一个应用程序调用,并且只使用 CLI 界面。它的依赖关系由 Maven 解决。我需要将它打包成一个 .exe(遗留原因)。此外,我的应用程序的一个依赖项使用了一些 Bouncy Castle jar,这些 jar 无法使用 Maven 程序集插件正常打包,因为它们丢失了签名。
作为一个解决方案,在另一个问题中,我使用 Maven 的 Launch4j 插件来排除 BC jar 并构建 exe,这对我来说是 suggested。但是,我一生都无法弄清楚如何正确配置它。我什至不知道从哪里开始寻找排除 BC jar 的方法,我也不知道如何处理插件的类路径相关怪癖。该插件的 readme 文档太少,我对 Maven 的掌握有限。
目前的 POM 既不构建 .exe,也不提供任何错误消息,这使得查明错误变得更加困难。 /target 中 .jar 的大小与之前相同,暗示构建过程似乎与添加插件之前没有任何不同。
有人可以看看 POM 并提出一些改进以使应用程序按预期构建吗?任何帮助,尤其是解释为什么不正确的部分会按原样更改,将不胜感激。
当前 POM:
<?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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<dontWrapJar>true</dontWrapJar>
<headerType>console</headerType>
<jar>eet-demo-maven-1.0-SNAPSHOT-eet-sender.jar</jar>
<outfile>target\EETSender.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>true</stayAlive>
<restartOnCrash>true</restartOnCrash>
<manifest></manifest>
<icon></icon>
<singleInstance>
<mutexName>EETMutex</mutexName>
<windowTitle></windowTitle>
</singleInstance>
<classpath>
<mainClass>cz.tomasdvorak.eetdemo.Main</mainClass>
<postCp>\lib\bcprov-jdk15on-1.55.jar;\eet-demo-maven-1.0-SNAPSHOT-eet-sender.jar;\eet-demo-maven-1.0-SNAPSHOT.jar</postCp>
</classpath>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.6.0_1</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>cz.tomasdvorak.eetdemo.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
<groupId>cz.tomasdvorak</groupId>
<artifactId>eet-demo-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.todvora</groupId>
<artifactId>eet-client</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>
assembly.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>eet-sender</id>
<formats>
<format>.jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/package</directory>
<outputDirectory>/target</outputDirectory>
<includes>
<include>*.exe</include>
</includes>
<excludes>
<exclude>org/bouncycastle/*.*</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
那么,什么是正确的配置,以确保最后有一个 .exe,当使用正确的参数运行时,它会执行其预期的功能?
【问题讨论】:
-
你为什么要使用胖罐子?你可以简单地把你所有的库放到
lib,它就可以工作了。 -
我将如何一步一步地做到这一点?项目中的任何地方都没有库文件夹。无论如何,我会下载所有库及其依赖项吗?以前从未这样做过,Maven 刚刚为我弄到了它们。
标签: java maven jar pom.xml launch4j