Launch4J - 如何将依赖jar附加到生成的exe [英] Launch4J - how to attach dependent jars to generated exe
问题描述
我有一个简单的java项目,需要外部jar。
我使用netbeans构建它,在Clean and Build命令之后,我可以在dist目录中找到以下结构:
I have a simple java project, which requires external jars. I build this with netbeans and after Clean and Build command, I can find in dist directory the following structure:
-myApp.jar
-lib/
library1.jar
library2.jar
典型的,我想说。
现在,我想将依赖库的myApp.jar作为一个exe分发。
这可能吗?我正在尝试使用Launch4J。在GUI中我创建配置文件, cp 部分中有一些选项
Now, I'd like to distribute myApp.jar with dependent libraries as one exe. Is this possible? I am trying to use Launch4J. In the GUI I create the config file, there are some options in cp section
<cp>lib/swing-layout-1.0.4.jar</cp>
但它似乎是类路径,它是我可以引用我的额外罐子的唯一地方。
but it seems to be classpath, and it is the only place I can refer to my extra jars.
创建exe文件后,我在exe中找不到dependend libs(exe可以用winrar打开),因此我的应用程序崩溃了。
After exe file is created, I can't find dependend libs in the exe (exe can be opened with winrar) and thus my application crashes.
如何才能正确制作exe文件?
How can I make the exe file properly then?
感谢您的帮助。
推荐答案
由于经常无法解决我在StackOverflow上发布的问题......在发布问题后不久我就明白了。
As it often happens being unable to solve the problem I published it on StackOverflow ... and pretty soon after publishing the question I got an idea.
所以我的问题的答案是:
So the answer to my question is:
将所有相关的罐放入一个主罐中。
花了一些时间才找到信息我该怎么做。
It took me some time to find info how can I do that.
为了帮助别人我决定在此发布详细说明 - 它们基于Netbeans 7.4。
To help people I decided to publish detailed instruction here - they are based on Netbeans 7.4.
-
以下文章来自 http://mavistechchannel.wordpress.com/2010/08/17/how-to-build-a- single-jar-file-with-external-libs / 我创建了为我构建one-jar-app的ant脚本。
然后我可以通过Launch4J手动创建exe
Following article from http://mavistechchannel.wordpress.com/2010/08/17/how-to-build-a-single-jar-file-with-external-libs/ I created the ant script that build one-jar-app for me. I could then manually create exe via Launch4J
然后我决定我想要更多自动化任务,我这样做了,Ant为我构建exe (通过Launch4J)
I then decided that I want more automated task, and I did that, Ant builds exe for me (via Launch4J)
然后我意识到我必须在自动化任务之前清理并构建(第2点)/我决定要干净并且构建在exe构建之前自动完成
Then I realized that I must do "clean and build" before my automated task (in point 2)/ I decided that I want clean and build to be done automatically before the exe build
将所有内容放在一起我附加了由点组成的ant构建脚本1,2,3:
Putting all together I am attaching my ant build script consisting of points 1,2,3:
需要编辑build.xml并将下面的内容放在project结束标记之前
It is required to edit build.xml and put the content found below before "project" end tag
<target name="package-for-launch4j" depends="clean,compile,jar">
<property name="launch4jexe.dir" location="C:\Program Files (x86)\Launch4j" />
<taskdef name="launch4j"
classname="net.sf.launch4j.ant.Launch4jTask"
classpath="${launch4jexe.dir}/launch4j.jar
:${launch4jexe.dir}/lib/xstream.jar" />
<property name="launch4j.jar.name" value="MyAppJarName"/>
<property name="launch4j.dir" value="exe"/>
<property name="launch4j.jar" value="${launch4j.dir}/${launch4j.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${launch4j.jar}"/>
<delete dir="${launch4j.dir}"/>
<mkdir dir="${launch4j.dir}"/>
<jar destfile="${launch4j.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${launch4j.jar}">
<zipfileset src="${launch4j.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${launch4j.dir}/temp_final.jar"/>
<launch4j configFile="misc/l4j-myapp.xml" />
</target>
然后在Netbeans中右键单击build.xml并选择:
运行目标/其他目标/ package-for-launch4j
then in Netbeans rightclick on the build.xml and choose: Run Target / Other Targets / package-for-launch4j
exe文件在exe文件夹中已准备就绪: - )
exe file is ready in exe folder :-)
这篇关于Launch4J - 如何将依赖jar附加到生成的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!