10

I'm using Launch4J to start my Java application and if an x64 JRE is present on the system, Launch4J seems to prefer it.

Unfortunately my application cannot run on a 64 bit JVM because I'm loading a 32 bit DLL, which is not possible and leads to an UnsatisfiedLinkError.

Is there any way to force/trick Launch4J to use a 32 bit JVM only?

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
  • it's almost 2012, and there seems to have been an update in February 2011 and this issue still doesn't seem to have been fixed after reading the message board. – KJW Dec 03 '11 at 08:56
  • If you point Launch4j to use the 32-bit windows cmd.exe shell in the SYSWOW64 directory, then it would not be possible to run a 64-bit JVM from that shell. Just a thought... – djangofan Sep 24 '12 at 17:45

8 Answers8

10

I have exactly the same problem : Into 64 bits environment if both 32 ans 64 bits JDK/JRE are installed this tools always detect the 64 bits version. I have patched the source (java + C++) code to make my own version and re-compile all. I add a check box to FORCE the 32 bits JDK/JRE detection into 64 bits windows environment. Just donwload the version and use it as the original one.

Version : launch4j-3.0.2-win32_Java32bitsDetection

Feneck91
  • 101
  • 1
  • 2
  • Thanks mate, best solution on this page so far! – Edgar Nov 20 '12 at 17:18
  • 3
    Great job... Did you consider submitting your patch to the launch4j developers? They have an open issue for this: http://sourceforge.net/tracker/?func=detail&aid=2813453&group_id=95944&atid=613100 – jumar Jan 21 '13 at 15:42
5

I had this exact problem about a year ago, using Lauch4J to wrap a small Java program that required a 32-bit DLL (swt-win32.dll, as it happened).

I found that if there were 32-bit and 64-bit JVMs installed, Launch4J would always favour the 64-bit one. It would only work if the 64-bit JVM was uninstalled, which was obviously not a practical solution.

I found no way of getting Launch4J to prefer (and require) the 32-bit JVM, after searching quite a bit and posting questions on its forum.

Therefore, I evaluated a good number of alternative JRE converters (I used this list: http://www.excelsior-usa.com/articles/java-to-exe.html).

I ended up settling on Jar2Exe, which was the only one that had the features I needed. It's not free, though there is an evaluation version, and I think it wasn't expensive.

Hope this helps!

Irish Buffer
  • 852
  • 1
  • 8
  • 11
1

I encountered the same problem some time ago and forked the project, so that the User interface exposes an option to force that a 32bit JVM ought to be found, you can grab the installer of launch4j 3.0.3 with the patch from:

http://fbergmann.github.io/launch4j/files/SetupLaunch4j_3.0.3.exe

and read more here:

http://frank-fbergmann.blogspot.de/2012/11/launch4j-for-32bit.html
http://fbergmann.github.io/launch4j/

Frank
  • 1,122
  • 9
  • 12
1

I don't know Launch4J, but you can get the Information about 32/64 by reading System.getProperty("os.arch");. If you encounter a 64-bit system you may quit the installer with a nice message, to tell the User to install a 32-bit JVM.

You may Wrap your startUp-Code with an Wrapper to show a Message-Box to the user.

public static void main(String[] args]){

   String architecture = System.getProperty("os.arch");
   // Did not test the return value of this property,,but should work
   if("64".equals(architecture)){
       // Show a dialog, or print a logmessage
       System.exit(-1);
   }
   // Start my APP
   com.something.startup.main(args);
}
Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79
  • 1
    this is a good suggestion but http://stackoverflow.com/questions/807263/how-do-i-detect-which-kind-of-jre-is-installed-32bit-vs-64bit suggests that `"os.arch"` returns inconsistent results. – KJW Dec 03 '11 at 08:58
  • I don't think this actually addresses the original question, though. – mhucka Apr 11 '13 at 13:40
1

This is an old question and Launch4J has been updated since it was asked. Now there is a dedicated user-interface control for selecting which version of the JVM to prefer. The options currently are:

  • 64-bit only
  • First 64-bit, then 32-bit
  • First 32-bit, then 64-bit
  • 32-bit only

The last, one of course, is exactly what the OP requested.

Launch4J JVM Selection Dialog

drwatsoncode
  • 4,721
  • 1
  • 31
  • 45
1

If you don't mind including a copy of JDK with your app, try passing these arguments (in the MyApp.ini) to launch4j:

-D32 -Djava.home=d:\MyApp\JDK32 -Djava.ext.dirs=d:\MyApp\JDK32\jre\lib\ext 

There are also other things going on here that you could use:

If you don't package the JRE, you can set the Launch4j option to use "jreOnly" and then, using the DOS environment variable called "%ProgramFiles%" you can locate the 32-bit or the 64-bit JRE in the expected location, depending on whether you used the SysWOW64 32-bit cmd.exe shell or the regular 64-bit shell. Then you can pass these options to the JVM:

-D32 -Djava.home=%ProgramFiles%\Java\JREDIR -Djava.ext.dirs=%ProgramFiles%\Java\JREDIR\lib\ext 

or

-D32 -Djava.home=%ProgramFiles(x86)%\Java\JREDIR -Djava.ext.dirs=%ProgramFiles(x86)%\Java\JREDIR\lib\ext 
djangofan
  • 28,471
  • 61
  • 196
  • 289
0

For any users of Launch4j applications like Areca that get stung by this one, and need a quick work around, look in the directory where the application is launched and you will find a complete java command line to run your program inside a file named launch4j.log. Just make a bat file or script using the java vm you prefer and run it with the full command line in the log.

WizardsOfWor
  • 2,974
  • 29
  • 23
0

You will have to add a JVM parameter while configuring.

It is shown in the below post on how to add it:

http://www.technimi.com/index.php?do=/group/java/forum/building-an-exe-using-launch4j-for-32-bit-jvm/

Matthieu
  • 2,736
  • 4
  • 57
  • 87
javangelo
  • 27
  • 2
  • As far as I know, this option -D32 was supported in earlier versions of the JVM, but is not documented for Java SE6 and does not appear to work. However, let us know if it works for you! – Irish Buffer Nov 10 '10 at 18:49
  • "Sorry, the page you were looking for in this blog does not exist.". Please avoid link-only answers... – Matthieu Jun 04 '15 at 15:08