简体   繁体   English

将Launch4J配置为仅使用32位JVM

[英]Configure Launch4J to use 32-bit JVM only

I'm using Launch4J to start my Java application and if an x64 JRE is present on the system, Launch4J seems to prefer it. 我正在使用Launch4J来启动我的Java应用程序,如果系统上存在x64 JRE,则Launch4J似乎更喜欢它。

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. 不幸的是我的应用程序无法在64位JVM上运行,因为我正在加载32位DLL,这是不可能的,并导致UnsatisfiedLinkError。

Is there any way to force/trick Launch4J to use a 32 bit JVM only? 有没有办法强制/欺骗Launch4J只使用32位JVM?

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. 我有完全相同的问题:如果安装了32位64位JDK / JRE,则进入64位环境,此工具始终检测64位版本。 I have patched the source (java + C++) code to make my own version and re-compile all. 我修补了源代码(java + C ++)代码来制作我自己的版本并重新编译所有代码。 I add a check box to FORCE the 32 bits JDK/JRE detection into 64 bits windows environment. 我添加了一个复选框,将32位JDK / JRE检测强制转换为64位窗口环境。 Just donwload the version and use it as the original one. 只需下载该版本并将其用作原始版本。

Version : launch4j-3.0.2-win32_Java32bitsDetection 版本: launch4j-3.0.2-win32_Java32bitsDetection

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). 大约一年前我遇到了这个问题,使用Lauch4J来包装一个需要32位DLL的小型Java程序(swt-win32.dll,因为它发生了)。

I found that if there were 32-bit and 64-bit JVMs installed, Launch4J would always favour the 64-bit one. 我发现如果安装了32位和64位JVM,Launch4J总是支持64位JVM。 It would only work if the 64-bit JVM was uninstalled, which was obviously not a practical solution. 它只有在卸载64位JVM时才有效,这显然不是一个实用的解决方案。

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. 我发现没有办法让Launch4J更喜欢(并要求)32位JVM,经过大量搜索并在论坛上发布问题。

Therefore, I evaluated a good number of alternative JRE converters (I used this list: http://www.excelsior-usa.com/articles/java-to-exe.html ). 因此,我评估了大量替代JRE转换器(我使用此列表: 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. 我最终选择了Jar2Exe,这是唯一一个拥有我需要的功能的人。 It's not free, though there is an evaluation version, and I think it wasn't expensive. 它不是免费的,虽然有一个评估版本,我认为它并不昂贵。

Hope this helps! 希望这可以帮助!

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: 我前段时间遇到了同样的问题并分叉了项目,因此用户界面公开了一个强制应该找到32位JVM的选项,你可以使用以下补丁获取launch4j 3.0.3的安装程序:

http://fbergmann.github.io/launch4j/files/SetupLaunch4j_3.0.3.exe 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://frank-fbergmann.blogspot.de/2012/11/launch4j-for-32bit.html
http://fbergmann.github.io/launch4j/ http://fbergmann.github.io/launch4j/

I don't know Launch4J, but you can get the Information about 32/64 by reading System.getProperty("os.arch"); 我不知道Launch4J,但你可以通过阅读System.getProperty("os.arch");获得有关32/64的信息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. 如果遇到64位系统,可以使用一条好消息退出安装程序,告诉用户安装32位JVM。

You may Wrap your startUp-Code with an Wrapper to show a Message-Box to the user. 您可以使用包装器包装startUp-Code以向用户显示消息框。

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);
}

This is an old question and Launch4J has been updated since it was asked. 这是一个老问题,Launch4J自被问及以来已经更新。 Now there is a dedicated user-interface control for selecting which version of the JVM to prefer. 现在有一个专用的用户界面控件,用于选择要使用哪个版本的JVM。 The options currently are: 目前的选项是:

  • 64-bit only 仅限64位
  • First 64-bit, then 32-bit 首先是64位,然后是32位
  • First 32-bit, then 64-bit 首先是32位,然后是64位
  • 32-bit only 仅限32位

The last, one of course, is exactly what the OP requested. 当然,最后一个正是OP所要求的。

Launch4J JVM选择对话框

If you don't mind including a copy of JDK with your app, try passing these arguments (in the MyApp.ini) to launch4j: 如果您不介意在您的应用程序中包含JDK的副本,请尝试将这些参数(在MyApp.ini中)传递给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. 如果不打包JRE,可以将Launch4j选项设置为使用“jreOnly”,然后使用名为“%ProgramFiles%”的DOS环境变量,可以找到预期的32位或64位JRE位置,具体取决于您使用的是SysWOW64 32位cmd.exe shell还是常规的64位shell。 Then you can pass these options to the JVM: 然后,您可以将这些选项传递给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 

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 . 对于像Areca这样受到攻击的Launch4j应用程序的任何用户,并且需要快速解决,请查看启动应用程序的目录,您将找到一个完整的java命令行来在名为launch4j的文件中运行程序。记录 Just make a bat file or script using the java vm you prefer and run it with the full command line in the log. 只需使用您喜欢的java vm创建一个bat文件或脚本,然后使用日志中的完整命令行运行它。

You will have to add a JVM parameter while configuring. 配置时必须添加JVM参数。

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/ http://www.technimi.com/index.php?do=/group/java/forum/building-an-exe-using-launch4j-for-32-bit-jvm/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM