I have launch4j configure for my project. I used it back, when i developed on windowsXP, where it worked. Now i need it to build on mac as well:
My 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>
I get the following output:
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/fabian/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
When i add bindir="tools/launch4j/bin"
to the launch4j-execution, ld and windres are found, and the output changes to:
create-exe:
[launch4j] Compiling resources
[launch4j] Linking
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/crt2.o: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./head/guihead.o: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./head/head.o: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libmingw32.a: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libgcc.a: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libmsvcrt.a: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libkernel32.a: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libuser32.a: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libadvapi32.a: No such file or directory
[launch4j] /Users/fabian/dev/rsys-client/tools/launch4j/bin/ld: cannot find ./w32api/libshell32.a: No such file or directory
BUILD FAILED
/Users/fabian/dev/rsys-client/create-win32-exe.xml:9: net.sf.launch4j.BuilderException: net.sf.launch4j.ExecException: Exec failed (1): /Users/fabian/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/fabian/dev/rsys-client/Kassa.exe
Total time: 6 seconds
I was facing the same problem and couldn´t set the path/classpath properly but as a workaround I create the Ant build within the launch4j directory and I was able to get it work generating the executable file.
For those that experience the:
error=2, No such file or directory
issue when running windres on 64-bit Linux, you will need to install 32-bit libraries. On Linux Mint I installed the package ia32-libs with:
sudo apt-get install ia32-libs
This error occurs when your current directory is not the launch4j directory, as Leo noted.
Launch4j attempts to find its own install directory by looking on the classpath for launch4j.properties. This is done in Util.java, at the top of the getJarBaseDir() method. It was changed recently to have these lines:
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('!'));
The problem is uri.getPath() does not return the "file:" part for local file URIs--it only returns the path portion of the URI beginning with /. I changed those last two lines to this, and it started working:
if (path.startsWith("/")) {
String jarPath = path.substring(0, path.lastIndexOf('!'));
Note the 5 -> 0 in substring because we don't need to remove "file:" part anymore. I had to rename build.xml.prod to build.xml in order to compile launch4j, but other than that it worked fine.
I also had this problems and I fixed it by modifying the launch4j code.
In the Class Launch4JTask.java I replaced the line
final Builder b = new Builder(Log.getAntLog());
with this one
final Builder b = new Builder(Log.getAntLog(), new File(getOwningTarget().getProject().getProperty("launch4j.bindir")));
Through this change i could specify the path to Launch4j inside my ant build script like that
<property name="launch4j.bindir" location="../tools/launch4j/" />
Greetings, -chris-
I had similar problem with building launch4j in Maven:
...
[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)
...
it started working normally after cleaning system variable ComSpec:
was: ComSpec=%SystemRoot%\system32\cmd.exe;c:\Program Files (x86)\NSIS\NSIS.exe
now: ComSpec=%SystemRoot%\system32\cmd.exe
It seems like NSIS inserted itself there, not me.
来源:https://stackoverflow.com/questions/14319358/launch4j-windres-how-to-set-paths-correctly