简体   繁体   中英

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). 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). The MANIFEST file points to the Main class correctly.

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.

Check your project build path (since you're using eclipse, right-button click on your project's folder, then Build Path > Configure Build Path). 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. You could use a wrapper to fix this issue, since it encapsulates all needed information in a .exe, for example.

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

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. 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; Variable Value = directory where java is installed > OK > Click on PATH > Edit... > add JAVA_HOME\bin to PATH > OK

When the Java Runtime Environment (JRE) is not installed, the JAR won't be open and won't show you any message. Try installing JRE into the other computer and try again.

You need to install a Java Runtime Environment (JRE) first, then you can directly run the .jar files on your computer. The Java Development Kit (JDK) download package contains it's corresponding JRE, so that's fine to install too.

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. 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. 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. 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.
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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