Generated Runnable jar: Could not find main class

I always used the Export → Runnable jar parameter for Eclipse, and it worked fine, but today it seems that in all running jars I create the following error when I run them : (Edit: run them by double-clicking the file.)

Java Virtual Machide Launcher

Could not find the main class: (class). Program will exit.

I tried everything in the last two hours, but it still doesn't work.

  • I can still run banks that I created in the past without a problem.
  • The manifest file looks exactly like in these banks that the work and all the .class files appear in place ...
  • I tried to export using Package required libraries into generated jar , but the file still does not work. It does not show an error, although double-clicking on a file does nothing.

Change Running the jar file with cmd works fine, but double-clicking on it gives this error. (Bragboy)

Edit 2: The contents of the manifest file from the jar that works: (Obviously they are the same, I just wanted to avoid confusion.)

Manifest Version: 1.0
Class path :.
Main-Class: defender.DefenderComponent (+ two blank lines)

And the contents of the manifest file from the jar, which does not work: (when opening the file directly)

Manifest Version: 1.0
Class path :.
Main-Class: pixel.Entry (+ two blank lines)

Both files of the main class are confirmed to be in the appropriate places.

+4
source share
3 answers

In the end, the only thing that fixed this was to switch from JRE 1.7 to JRE 1.6.

+2
source

When exporting a jar file, it is important to indicate which one is the main one. You can do this in the eclipse wizard. To go to this screen, you just need to export only as a jar, not a Runnable jar.

enter image description here

Another option to find out about the error, try to open a command prompt (in windows) or a terminal (in linux / mac) and pass this command java -jar your_jar.jar. this will show a detailed error about what is happening.

Since your jar works correctly when launched through the command line, it will be a certain culprit to open the default program for the .jar extension in Windows. To avoid this, you will probably have to right-click on the bank and try to open it using a jar-executable file that is compatible with the version of java that you used on the command line.

+3
source

I know this is a bit of a necropolis, but I had the same problem. What finally worked for me was fixing the% JAVA_HOME% path in environment variables. It turns out that he was still pointing to release 1.6, and so nothing has worked since I installed 1.7, except through Eclipse, where I fixed all the links to point to the correct release.

0
source

Source: https://habr.com/ru/post/1387934/


All Articles