简体   繁体   English

可执行 jar 在其他计算机上不起作用

[英]Executable jar not working on other computers

I've created a program using Eclipse and exported as an executable jar (I've tried all 3 library handling options).我使用Eclipse创建了一个程序并导出为executable jar (我已经尝试了所有 3 个库处理选项)。 It runs perfectly on the computer it was written and exported on, but when I try and run it on other machines it does nothing at all.它在编写和导出它的计算机上完美运行,但是当我尝试在其他机器上运行它时,它什么也没做。 It brings up no errors, nothing at all.它没有带来任何错误,什么都没有。 I've got several people to try it for my with no luck, and I've tried running it on my laptop (ensuring that Java is the latest version, the same as the machine that it was written on).我有几个人为我尝试它,但没有运气,我尝试在我的笔记本电脑上运行它(确保 Java 是最新版本,与编写它的机器相同)。 The MANIFEST file points to the Main class correctly. MANIFEST文件正确指向 Main 类。

Does anyone know how I can solve this issue?有谁知道我该如何解决这个问题?

It's incredibly frustrating!真是令人沮丧! If any more info is needed, I can supply it.如果需要更多信息,我可以提供。

That happened to me a lot of times when I started writing java distributed applications.当我开始编写 Java 分布式应用程序时,这种情况发生在我身上很多次。

Check your project build path (since you're using eclipse, right-button click on your project's folder, then Build Path > Configure Build Path).检查您的项目构建路径(因为您使用的是 eclipse,所以右键单击您的项目文件夹,然后构建路径 > 配置构建路径)。 If any of the paths that are specified there are custom *ie C:\User\daMachineMaster\Java\jre\bin or whatever, it won't work on any other machine because the application will always look for that path, which won't exist in no other machine than daMachineMaster 's computer.如果其中指定的任何路径是自定义 *ie C:\User\daMachineMaster\Java\jre\bin或其他任何路径,它将无法在任何其他机器上运行,因为应用程序将始终查找该路径,这将不会t 存在于daMachineMaster的计算机之外的其他机器中。 You could use a wrapper to fix this issue, since it encapsulates all needed information in a .exe, for example.例如,您可以使用包装器来解决此问题,因为它将所有需要的信息封装在 .exe 中。

If that still isn't your issue, search your code for any links to your local directories.如果这仍然不是您的问题,请在您的代码中搜索任何指向本地目录的链接。 For example,例如,

String style = main.screens.ScreenFramework.class.getResource("C:\Users\Dwayne\Music\cool\DarkTheme.css");

After you've located these kinds of hard links, the solution is changing them to be relative links.找到这些类型的硬链接后,解决方案是将它们更改为相对链接。 Check How to define a relative path in java检查如何在java中定义相对路径

In the above case, it would mean changing to something like:在上述情况下,这意味着更改为:

String style = main.screens.ScreenFramework.class.getResource("DarkTheme.css").toExternalForm();

Also, as mentioned in other answers, check if the other computers hava java installed.另外,如其他答案中所述,请检查其他计算机是否安装了 java。 I don't think that they need any environment variables defined to run a runnable jar but if you want to run your app in the cmdline with something like java -jar yourapp.jar then you need to go to the windows explorer (assuming you're using windows), right-click Computer, then click Advanced System Settings > Environment Variables > New... > Variable Name = JAVA_HOME;我认为他们不需要定义任何环境变量来运行可运行的 jar,但是如果您想在命令行中使用java -jar yourapp.jar之类的东西运行您的应用程序,那么您需要转到 Windows 资源管理器(假设您重新使用 Windows),右键单击计算机,然后单击高级系统设置 > 环境变量 > 新建... > 变量名 = JAVA_HOME; Variable Value = directory where java is installed > OK > Click on PATH > Edit... > add JAVA_HOME\bin to PATH > OK变量值 =安装 java 的目录> 确定 > 单击 PATH > 编辑... > 将 JAVA_HOME\bin 添加到 PATH > 确定

When the Java Runtime Environment (JRE) is not installed, the JAR won't be open and won't show you any message.未安装 Java 运行时环境 (JRE) 时,JAR 将不会打开并且不会显示任何消息。 Try installing JRE into the other computer and try again.尝试将 JRE 安装到另一台计算机中,然后重试。

You need to install a Java Runtime Environment (JRE) first, then you can directly run the .jar files on your computer.您需要先安装Java 运行时环境 (JRE) ,然后才能直接在计算机上运行.jar文件。 The Java Development Kit (JDK) download package contains it's corresponding JRE, so that's fine to install too. Java Development Kit (JDK) 下载包包含它对应的 JRE,所以也可以安装。

Sorry for the late reply.这么晚才回复很抱歉。 Thanks for all your answers, but it turned out there was an error in my code that simply stopped it running without showing any errors.感谢您的所有回答,但事实证明我的代码中有一个错误,只是停止了它的运行而没有显示任何错误。

I got this problem several times.我多次遇到这个问题。 The issue was the jar file runs on the computer where I have packaged.问题是 jar 文件在我打包的计算机上运行。 But in another computer it is not running, some time it shows running if I check the javaw.exe process in cmd but nothing is served.但是在另一台计算机上它没有运行,如果我在 cmd 中检查 javaw.exe 进程但没有提供任何服务,有时它会显示运行。 The solution here is to make sure the following are set correctly.这里的解决方案是确保正确设置以下内容。

  1. Make sure the version of java in another computer match the jar file.确保另一台计算机中的 java 版本与 jar 文件匹配。 In some case if you defined java16 in the pom file, make sure the computer has java16 or higher installed and the JAVA_HOME environment is set correct to point to this version.在某些情况下,如果您在 pom 文件中定义了 java16,请确保计算机安装了 java16 或更高版本,并且 JAVA_HOME 环境设置正确以指向此版本。
  2. Make sure the dependent variables are set correctly.确保因变量设置正确。 For example if the package depends on database driver or database connection consider installing and creating database例如,如果软件包依赖于数据库驱动程序或数据库连接,请考虑安装和创建数据库

For me it worked after changing the java version in the pom file to the oddest ie.the second computer use java 16 then packaged jar file to use java 11.对我来说,在将 pom 文件中的 java 版本更改为最奇怪的 ie 后它起作用了。第二台计算机使用 java 16,然后打包 jar 文件以使用 java 11。

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

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