How to get the path to the executable when using launch4j?

I use start4j to wrap the jar executable in my Windows application, but I need to pass links to some of its libraries through JVM arguments. The corresponding libraries are located in the application installation directory and are always in the same place with respect to the executable file.

I would like to tell launch4j to use executable compatible paths in JVM options. I know this information is available at the Windows script package level, but how do you configure start4j to extract it?

Edit for clarification: I am looking specifically for how to make paths relative to the binary itself, not how to make them relative to the current working directory. These two do not necessarily match.

+8
java launch4j
source share
5 answers

You can add launch4j to the configuration

... <jre> ... <opt>-Djna.library.path="%EXEDIR%\\path\\to\\lib"</opt> <opt>-Djava.library.path="%EXEDIR%\\path\\to\\lib"</opt> ... </jre> ... 

If you need more than a, you can select several paths with a half column, as usual.

<opt> Additionally, accepts everything that you usually pass java / javaw launcher: approval parameters, system properties and X options. Here you can map the environment and special variables EXEDIR (exe runtime directory), EXEFILE (full path to the EXE file) of the system property. All variable references should be surrounded by percent signs and quoted.

Source: http://launch4j.sourceforge.net/docs.html

+11
source share

Set -Djna.library.path=<relative path of native libraries> (if using JNA) and -Djava.library.path=<relative path of native libraries> .

Alternatively, this can be done in Java code as: System.setProperty("jna.library.path","<relative path of native libraries>") and System.setProperty("java.library.path","<relative path of native libraries>") . You can add as many paths to be referenced. On Windows use ; to separate the paths.

This setting only affects the JVM runtime of this Java application (not globally, like LD_LIBRARY_PATH on Linux.)

Or you can put this in the list of JVM Launch4J options under the JRE tab. This is what I do in my projects.

+3
source share

One configuration option is to allow the chdir executable directory. This will be ser user.dir in the same directory as exe, which you can use to find other application paths.

 <chdir> 

Additionally. Change the current directory to an arbitrary path relative to the executable file. If you omit this property or leave it blank, this will have no effect.

Installation will change the current directory to the same directory as the executable ... will change it to the parent directory, etc.

 <chdir>.</chdir> <chdir>../somedir</chdir> 

The code that finds the actual path to the executable will be OS dependent (readlink, GetModuleFileName, etc.). Make sure that you are really testing the target OS.

+2
source share

If I understand your question correctly, you have the launch4j executable and the built-in library in the installation directory:

 /launch.exe /bin/lib.dll /lib/app.jar 

Now you want to start the app.jar application using the generated launch (launch.exe). The application loads lib.dll.

You can paste the file into your app.jar (marker.txt). Now you can use ClassLoader

http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String )

 getResource("marker.txt); 

This will give you something like:

 file://c://installdir/lib/app.jar!marker.txt 

This line can be parsed. But in fact, I think there should be a better solution to this problem.

+1
source share

You can simply include the directory (e.g. .. \ lib) where the libraries are on the classpath tab in Launch4j. At least it worked for me.

+1
source share

All Articles