Launch4J - 如何将依赖的 jars 附加到生成的 exe [英] Launch4J - how to attach dependent jars to generated exe

查看:22
本文介绍了Launch4J - 如何将依赖的 jars 附加到生成的 exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 java 项目,它需要外部 jars.我用 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>

但它似乎是类路径,它是我唯一可以引用我的额外 jar 的地方.

but it seems to be classpath, and it is the only place I can refer to my extra jars.

创建exe文件后,我在exe中找不到依赖库(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:

将所有依赖的 jar 放在一个主 jar 中.

我花了一些时间才找到我该怎么做的信息.

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.

  1. 以下文章来自 http://mavistechchannel.wordpress.com/2010/08/17/how-to-build-a-single-jar-file-with-external-libs/ 我创建了构建一个的 ant 脚本-jar-app 给我.然后我可以通过 Launch4J 手动创建 exe

  1. 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

综合起来,我附上了我的蚂蚁构建脚本,包括点 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 - 如何将依赖的 jars 附加到生成的 exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆