【问题标题】:Launch4j / windres: how to set paths correctly?Launch4j / windres:如何正确设置路径?
【发布时间】:2013-01-14 13:30:25
【问题描述】:

我为我的项目配置了 launch4j。当我在 windowsXP 上开发时,我使用了它,它在那里工作。现在我也需要它在 mac 上构建:

我的 build.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create-exe">

    <property name="platform" value="win32"/>
    <property name="launch4j.dir" location="${basedir}/tools/launch4j/" />

    <include file="create-jar.xml" as="sub"/>

    <target name="create-exe" depends = "sub.create-jar">
        <launch4j configFile="launch4j-config.xml" />
        <delete file="client.win32.jar"/>
    </target>

    <taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask">
        <classpath>
            <pathelement path="tools/launch4j/launch4j.jar"/>
            <pathelement path="tools/launch4j/lib/xstream.jar"/>
        </classpath>
    </taskdef>
</project>

我得到以下输出:

create-exe:
 [launch4j] Compiling resources
 [launch4j] Generated resource file...
 [launch4j] LANGUAGE 0, 1
 [launch4j] 2 RCDATA BEGIN "1.6.0\0" END
 [launch4j] 18 RCDATA BEGIN "0\0" END
 [launch4j] 25 RCDATA BEGIN "512\0" END
 [launch4j] 27 RCDATA BEGIN "1024\0" END
 [launch4j] 21 RCDATA BEGIN "http://java.com/download\0" END
 [launch4j] 20 RCDATA BEGIN "32\0" END
 [launch4j] 9 RCDATA BEGIN "true\0" END
 [launch4j] 101 RCDATA BEGIN "An error occurred while starting the application.\0" END
 [launch4j] 102 RCDATA BEGIN "This application was configured to use a bundled Java Runtime Environment but the runtime is missing or corrupted.\0" END
 [launch4j] 103 RCDATA BEGIN "This application requires a Java Runtime Environment\0" END
 [launch4j] 104 RCDATA BEGIN "The registry refers to a nonexistent Java Runtime Environment installation or the runtime is corrupted.\0" END
 [launch4j] 17 RCDATA BEGIN "true\0" END

BUILD FAILED
/Users/f*/dev/rsys-client/create-win32-exe.xml:9: net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: java.io.IOException: Cannot run program "./bin/windres": error=2, No such file or directory

当我在launch4j-execution中添加bindir="tools/launch4j/bin"时,找到了ld和windres,输出变为:

create-exe:
 [launch4j] Compiling resources
 [launch4j] Linking
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/crt2.o: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./head/guihead.o: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./head/head.o: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libmingw32.a: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libgcc.a: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libmsvcrt.a: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libkernel32.a: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libuser32.a: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libadvapi32.a: No such file or directory
 [launch4j] /Users/f*/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libshell32.a: No such file or directory

BUILD FAILED
/Users/f*/dev/rsys-client/create-win32-exe.xml:9: net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: Exec failed (1): /Users/f*/dev/rsys-client/tools/launch4j/bin/ld -mi386pe --oformat pei-i386 --dynamicbase --nxcompat --no-seh --subsystem windows -s ./w32api/crt2.o ./head/guihead.o ./head/head.o /var/folders/n5/44dkvyzd00z0h5mklk_pwtch0000gn/T/launch4j3026065429236284429o ./w32api/libmingw32.a ./w32api/libgcc.a ./w32api/libmsvcrt.a ./w32api/libkernel32.a ./w32api/libuser32.a ./w32api/libadvapi32.a ./w32api/libshell32.a -o /Users/f*/dev/rsys-client/Kassa.exe

Total time: 6 seconds

【问题讨论】:

    标签: build path launch4j


    【解决方案1】:

    对于那些体验过的人:

    error=2, No such file or directory
    

    在 64 位 Linux 上运行 windres 时的问题,您需要安装 32 位库。在 Linux Mint 上,我安装了 ia32-libs 包:

    sudo apt-get install ia32-libs
    

    【讨论】:

    • 在 Amazon EC2 上的 Centos 构建机器上遇到这个问题,不得不使用它来修复:yum install glibc-2.12-1.149.el6.i686
    • 似乎那些已经过时了。在 Ubuntu 16.04 上,它建议以下可行的方法:sudo apt-get install lib32ncurses5 lib32z1
    【解决方案2】:

    如 Leo 所述,当您的当前目录不是 launch4j 目录时会发生此错误。

    Launch4j 尝试通过查看 launch4j.properties 的类路径。这是在 Util.java 中完成的,位于 getJarBaseDir() 方法。最近更改为具有以下几行:

    URI uri = new URI(Util.class.getClassLoader()
        .getResource(Launch4jProperties)
        .getFile());
    
    String path = uri.getPath();
    
    if (path.startsWith("file:")) {
      String jarPath = path.substring(5,path.lastIndexOf('!'));
    

    问题是 uri.getPath() 不返回本地文件 URI 的“file:”部分——它只返回以 / 开头的 URI 的路径部分。我把最后两行改成这样,它开始工作了:

    if (path.startsWith("/")) {
      String jarPath = path.substring(0, path.lastIndexOf('!'));
    

    请注意子字符串中的 5 -> 0,因为我们不再需要删除 "file:" 部分。 为了编译launch4j,我不得不将build.xml.prod 重命名为build.xml,但除此之外它工作得很好。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题,无法正确设置路径/类路径,但作为一种解决方法,我在 launch4j 目录中创建了 Ant 构建,我能够让它生成可执行文件。

      【讨论】:

      • 今天也发现了。谢谢。
      • @Leo:您能解释一下“在 launch4j 目录中创建 Ant 构建”是什么意思吗?我有这个问题,我很茫然。我正在 Netbeans 中构建。
      • 将 ant-buildfile 放入 launch4j-dir 并更改所有路径以解决此问题。
      【解决方案4】:

      我也遇到了这个问题,我通过修改 launch4j 代码解决了这个问题。
      在 Class Launch4JTask.java 中,我替换了这一行

      final Builder b = new Builder(Log.getAntLog());
      

      这个

      final Builder b = new Builder(Log.getAntLog(), new File(getOwningTarget().getProject().getProperty("launch4j.bindir")));
      

      通过这个更改,我可以像这样在我的 ant 构建脚本中指定 Launch4j 的路径

      <property name="launch4j.bindir" location="../tools/launch4j/" />
      

      你好,-克里斯-

      【讨论】:

      • 不错。你提交给 launch4j 开发者了吗?
      【解决方案5】:

      我在 Maven 中构建 launch4j 时遇到了类似的问题:

      ...
      [INFO] launch4j: (longPathIn.m2Repository)\windres.exe: can't popen `type  (longPathToTemp)\Temp\launch4j8580185391499327059rc': No error
      [ERROR] 
      net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: Exec failed(1): [Ljava.lang.String;@9f1fb5
      at net.sf.launch4j.Builder.build(Builder.java:145)
      ...
      

      清理系统变量ComSpec后开始正常工作:

      was: ComSpec=%SystemRoot%\system32\cmd.exe;c:\Program Files (x86)\NSIS\NSIS.exe
      now: ComSpec=%SystemRoot%\system32\cmd.exe
      

      似乎是 NSIS 自己插入了那里,而不是我。

      【讨论】: