I built a Java project in eclipse. It runs fine from within eclipse. I've exported it as a jar before and it's worked fine. It's been a while since the last export, though. This time, when I exported and clicked on the jar, nothing happened.
Running it from the command line reveals the following error:
C:\>java -jar "C:\Users\Quinn\Desktop\think.jar"
Exception in thread "main" java.lang.IllegalAccessException: Class org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader can not access a member of class think.Main with modifiers "public static"
What does this error mean? Are there any reasons why this could happen? I haven't been able to find any mention of it online.
Thanks a lot.
EDIT:
when I unzip the jar, the contents looks like this:
the manifest (in META-INF) looks like this: (yes, it has an extra empty line)
Manifest-Version: 1.0
Rsrc-Class-Path: ./ substance-6.1.jar trident.jar
Class-Path: .
Rsrc-Main-Class: think.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Well, this is awkward. It turns out that, although my main method was public static, the containing class was not public. Everything is now fixed :)
JarRsrcLoader is included in the Jar when you use Export > Runnable JAR file. It deals with nested jar files in the jar.
JarRsrcLoader is trying to find your main method of think.Main but can't find a method called main which is public static.
Related
64x Intel processor
Kubuntu 19.04 on Linux 5.0.0-27
OpenJDK 1.8.0_222
In the last hour I have set up my project folder, created scripts for automatic compiling and for back-ups etc...
Finally I got it working, I get the JAR file. The problem is that I can't run it. I know that this is very common problem, but I don't see any compiling errors, mistakes nor typos. I'm totally lost.
Even using java -jar TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint and java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint show the same error.
Error: Could not find or load main class com.ydsoftware.taskcalender.EntryPoint
My source file structure:
com
ydsoftware
taskcalender
EntryPoint.java (contains main method)
My JAR file structure:
META-INF
MANIFEST.MF
com
ydsoftware
taskcalender
EntryPoint.class (contains main method)
MANIFEST.MF contents (inside the JAR file):
Manifest-Version: 1.0
Created-By: 1.8.0_222 (Private Build)
Main-Class: com.ydsoftware.taskcalender.EntryPoint
Class-Path: lib/MX%20Engine.jar
/ blank /
/ blank /
Can you try below in CMD or through batch file as per your convenience
Generic:
java -cp your_jar_name.jar package_name.classname
as per your class:
java -cp TaskCalender.jar com.ydsoftware.taskcalender.EntryPoint
SOLVED
The problem was that Class-Path: lib/MX%20Engine.jar was missing because my computer had shut down unexpectably (because our power was cut off for some reason) and the changes to MANIFEST.MF were lost. Didn't even notice.
Still, it should say something along the lines of Class not found or unexcepted token instead of saying Could not find or load main class which made finding the problem harder.
Thank you to everyone who tried to help me!
Before you mark this as a duplicate, I'd like to say that I've visited probably every thread made on the subject and still can't find a solution. I tried reinstalling JRE, configuring my classpath, etc. I've tried every solution I found but it still doesn't work. I can launch the program just fine using my IDE but it won't launch when trying to execute the jar file. I tried launching it with a .bat file and via command prompt. Here is my Manifest file:
Manifest-Version: 1.0
Class-Path: C:\Users\Badr\IdeaProjects\JavaGame1\src\com\rsp\game\Game.java
Main-Class: com.rsp.game.Game
And yes, I do have the main method included in my Game class. I've heard that the main class shouldn't be included in a package but I don't know if that's true or not.
Your Class-Path is incorrect; it needs to be set to the folder that contains com (because the directory structure is part of the fully qualified class name), and you need to compile your .java source files to class files.
I've heard that the main class shouldn't be included in a package but I don't know if that's true or not.
That is not true, but the main class name must be fully qualified (and Main-Class: com.rsp.game.Game is).
So I wrote a project in Eclipse and when I click on the green run button it works fine. When I export it into a jar and I double click on it a quick command prompt appears saying "cannot find or load main class...". I tried everything. I tried renaming registry keys, reinstalling java, changing environment variables and of course turning it on and off again. I read all the other threads on stack and tried everything they suggested. Here is my Manifest file:
Manifest-Version: 1.0
Class-Path: .
Main-Class: main.Main
My Main class is in a package called main.
I'd like to suggest to change the package name into something other than main.
don't forget to make a run configuration, which specifies the name of your main class.
package all the related other jar files into the same package.
run the executable.jar as java -jar YourExecutable.Jar
And if it does not solve your problem, just see my MANIFEST.MF file in my Executable jar file. Maybe it can give you some clue.
Manifest-Version: 1.0
Rsrc-Class-Path: ./ concurrentlinkedhashmap-lru-1.2.jar slf4j-api-1.7.
5.jar org.simpleframework.jar openflowj-0.3.7-SNAPSHOT.jar mongo-java
-driver-2.11.2.jar netty-3.9.0.Final.jar guava-15.0.jar org.restlet.e
xt.jackson.jar logback-classic-1.0.13.jar joda-time-2.2.jar org.codeh
aus.jackson.core.jar org.codehaus.jackson.mapper.jar openflowj-0.3.7-
SNAPSHOT-sources.jar org.restlet.jar logback-core-1.0.13.jar org.rest
let.ext.slf4j.jar org.restlet.ext.simple.jar openflowj-0.3.7-SNAPSHOT
-javadoc.jar
Class-Path: .
Rsrc-Main-Class: etri.sdn.controller.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
I'm developing a program with three classes and also includes some external jar archives and classes. When I run it in Eclipse it works properly, but I need to try with some other programs, so I need to run it at the console. I save all of it in a folder, which contains another two folders, one with the .class created by me and the other one with the .java and .jar archives and a folder with the external classes. I've tried to creat a .jar archive containing this folder and the manifest, where I told where's the main class.
When I run it I receive "Exception in thread "main" java.lang.NoClassDefFoundError", so it doesn't found the class where the main is, but I don't know why. I've tried some different ways to define it at the manifest and changing the classpath and it still doesn't work.
Any solutions or advices?
Thanks!
Try to use JarSplice, it will let you define the main class.
NoClassDefFoundError means that the file existed during compile time, but it was not found during run time. Since there were no compilation issues, the jar was created, but at run time, while using command like java -jar jarfilename fullyqualifiedclassname it threw this exception. Check the classpath variable, validate that you are executing the command from the right folder location in command window.
I had always referred the below link for such errors and it worked for me
http://javaeesupportpatterns.blogspot.in/2012/06/javalangnoclassdeffounderror-how-to.html
when creating a project for example ABC the IDE normally Netbeans creates the source folder and creates the main class as ABC.java which contains the main class. In Netbeans IDE let you mention your main class if it is not ABC or if not you must create an instance of the class you want to run when application executes in ABC.java class.
In one of my projects I ran also in the same situation. The problem was always a missunderstanding of mine with this error message.
The reason in my case was that the computer could not found the declared jar file. The use of the parameter -cp let me became happy. So try
java -jar -cp ./Server.jar
Edit:
I forgot to mention that I had also to mention the full qulified name of class which contains the main class.
This:
The stacktrace is "Exception in thread "main" java.lang.NoClassDefFoundError: /bin/TextClient
looks to me like your Manifest is wrong. To correct it, you can use:
jar -uvfe Server.jar full.name.of.your.MainClass
Note: not the file/path name of some class file!
This will create a MANIFEST that tells that full.name.of.your.MainClass is your main class.
In addition, if your jar contains entries like:
bin/Foo.class
bin/...
you created the JAR file probably from the wrong place (unless your TLD is bin).
If your main class is named org.adepts.Main, then a top level entry should be:
org/adepts/Main.class
(This is where it will be searched.)
I finally solved it by using the Eclipse "Export" option and not creating it manually.
I'm making a program in java which is just a basic J based gui program. when i compile it in eclipse using the play button, it runs perfectly and there are no bugs or errors to be seen.
But when i export it and run it, it just returns an error saying the main class cannot be found, there shouldn't be a problem because i have the launch configurations set up correctly and for some reason this only happens when im programming in java 1.7, when i do it in 1.6 it compiles and runs perfectly. even when i export it.
How I export
I just run it by opening to jar file
Inside my MANIFEST.MF file:
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: net.undeadminecraft.wgh.main.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
The error message i get
My packages (if it helps)
Run your JAR on the console (java -jar yourjar.jar) and post the full stack trace. Also post output of java -version and javac -J-version.
My guess is that your default Java is Java6, and if you build with Java7, you are using the new Java7 class file format, or your main class contains a reference to a class not present in Java6 (in a place where verification cannot be deferred).
EDIT: Use Process Explorer or another task manager that shows exe paths and that can find process for a window, and show which javaw.exe exactly shows you that error message. Then try the java.exe in same directory to reproduce the error message. Or uninstall all your JRE (JDK may stay) but one, so it is clear which one is running.
I would suggest to set your main class as the "Main-Class" in the MANIFEST.MF:
Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Main-Class: net.undeadminecraft.wgh.main.Main
Could solve your problem, as the main class you had in there is an internal class by Eclipse.
Your main method signature is not correct. Please verify that it's like below :
public static void main(String args[]){
}
You may be missing something. Otherwise please give us your method declaration.