简体   繁体   English

通过Eclipse创建一个包含.exe文件的可运行JAR

[英]Creating a runnable JAR which includes .exe files via eclipse

Hey guys - I've looked through a plethora of forums online as well as asked many professional java developers but I was unable to find adequate assistance in creating a standalone runnable jar file of a financial application that I am currently finishing up. 大家好-我浏览了许多在线论坛,并询问了许多专业的Java开发人员,但是在创建我正在完成的金融应用程序的独立可运行jar文件时,我找不到足够的帮助。 The application uses two external programs; 该应用程序使用两个外部程序。 an ImageMagick file conversion program called convert and an OCR program called gocr045. 一个名为convert的ImageMagick文件转换程序和一个名为gocr045的OCR程序。 I developed this application via eclipse and have attempted numerous times to package the contents with eclipse's automated runnable jar file creation wizard. 我通过eclipse开发了此应用程序,并尝试了无数次使用eclipse的自动可运行jar文件创建向导来打包内容。 All works well on my machine and my app functions as it is supposed to, but for some reason whenever the app is run on a different computer it compiles and the GUI displays but the two external functions do not work. 一切都可以在我的机器上正常运行,并且我的应用程序可以正常运行,但是由于某种原因,每当该应用程序在另一台计算机上运行时,它都会编译并显示GUI,但两个外部功能不起作用。 I have had these functions installed on the other machines but so far the only workaround that I have found to this issue is to manually create runnable jars on the machines via eclipse. 我已经在其他计算机上安装了这些功能,但是到目前为止,我发现此问题的唯一解决方法是通过eclipse在计算机上手动创建可运行的jar。 This will unfortunately not work because the app is to be commercialized upon completion and I can't go around installing eclipse then installing the app for every user that buys it. 不幸的是,这将无法正常工作,因为该应用程序将在完成时实现商业化,而且我无法四处安装eclipse,然后为购买该应用程序的每个用户安装该应用程序。 I suspect it is some trivial issue and Java experts such as yourselves will hopefully be able to resolve it for me in no time. 我怀疑这是一个小问题,希望Java专家(例如您自己)能够立即为我解决。 Does it possibly have something to do with signing the jar file? 可能与签名jar文件有关吗?

Thanks and I hope to hear back from you soon, 谢谢,希望很快能收到您的回音,

Mark Kogan KoganApps (www.koganapps.com) Mark Kogan KoganApps(www.koganapps.com)

Have the seperate exes been added to the PATH on your machine? 是否已将单独的exe添加到计算机的PATH中? If you aren't specifiying the full path to the exe when you invoke the Runtime.exec() method you might be picking up the location from the system path. 如果在调用Runtime.exec()方法时未指定exe的完整路径,则可能是从系统路径中提取了位置。

I would 我会

  1. Confirm exes located in known location relative to jar location 确认exe位于相对于jar位置的已知位置
  2. Runtime.exec() method uses this known relative location Runtime.exec()方法使用此已知的相对位置
  3. Ensure exes are not held inside the jar (I don't think it will work if they are) 确保未将exe放在罐子中(如果它们存在,我认为它不会起作用)

I don't think signing would have anything to do with it. 我认为签署与之无关。

Rafe-ultimately the goal is for the app to run on both Windows and Mac. 最终,Rafe的目标是使该应用程序同时在Windows和Mac上运行。 I will use some sort of external software to convert the exe files on the mac to ones that will run on mac os x. 我将使用某种外部软件将Mac上的exe文件转换为将在Mac OS X上运行的文件。 Subsequently I will invoke the Runtime.exec() method on these converted files 随后,我将在这些转换后的文件上调用Runtime.exec()方法

Mike - I suspected that this was the case as I am not specifying a direct path to the external programs and the system path is probably being inferred when the jar is not running on my computer. 迈克-我怀疑是这种情况,因为我没有指定到外部程序的直接路径,并且当我的计算机上没有运行jar时,可能会推断出系统路径。 The app consists of a JApplet wrapped in a JFrame, however; 该应用程序由包裹在JFrame中的JApplet组成。 could the security restrictions on an applet have anything to do with the issues I'm having? applet的安全限制可能与我遇到的问题有关吗? And, of course, my exes are located outside the jar in an external folder from which they are invoked because the ClassLoader cannot run external programs in the same jar file where it is instantiated 而且,当然,我的exe位于jar外部的外部文件夹中,因为ClassLoader无法在实例化该jar文件的同一jar文件中运行外部程序

Thanks for the help guys and I will get back to you shortly on my results - hopefully things work out now 感谢您的帮助,我会尽快与您联系以取得满意的结果-希望现在一切顺利

As you have said there is a JApplet wrapped in a JFrame so it could be a security exception. 正如您已经说过的there is a JApplet wrapped in a JFrame因此它可能是安全性异常。 Normally when you have a JDK installed on your system and you are using eclipse, it picks up the JRE inside the JDK folder. 通常,当您的系统上安装了JDK并使用eclipse时,它将在JDK文件夹中拾取JRE。 Once you bundle it as an runnable jar and try to execute it on a different system then there is a chance that it is picking up java.exe from c:\\program files\\java\\jre\\bin .. if this is the case then your app won't work, unless properly signed and given required access rights. 一旦将其捆绑为可运行的jar并尝试在其他系统上执行,则有可能它从c:\\program files\\java\\jre\\bin ..中拾取java.exe ,如果是这种情况,那么您的应用程序将无法运行,除非已正确签名并获得了必需的访问权限。

So, do the following check: 因此,请执行以下检查:

  1. which jre is being used on your system. 您的系统上正在使用哪个jre。 whether it is inside jdk or c:\\program files\\java\\jre\\bin 是否在jdk或c:\\program files\\java\\jre\\bin
  2. check the same on the other systems where you have deployed your app 在已部署应用程序的其他系统上进行检查

Note : I have assumed that you have set all the necessary path variables. 注意 :我假设您已经设置了所有必需的路径变量。

Suggestion : 建议

  1. In case you have access to the source code of the ImageMagick and JOCR then make a dll out of it and use JNA ( https://jna.dev.java.net/ ) to call them. 如果您可以访问ImageMagickJOCR的源代码,则可以JOCR制作一个dll并使用JNAhttps://jna.dev.java.net/ )对其进行调用。
  2. Use JPanel in place of JApplet 使用JPanel代替JApplet

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

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