.jar doesnt run on debian - java

Im trying to execute a .jar file i have like 3 days trying to run it and nothing i tried right clink and run with java and nothing happens, i tried like a million ways in the console but nothing, the programs runs fine on NetBeans but when i compile i get nothing i checked the manifest and its ok and when i run with the console i get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: dist/ModuloControlAcceso
Caused by: java.lang.ClassNotFoundException: dist.ModuloControlAcceso
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: dist.ModuloControlAcceso. Program will exit.
The path of my project is /home/user/NetBeansProjects/ModuloControlAcceso/dist
The manifest is:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
Class-Path: /home/victor/NetBeansProjects/ModuloControlAcceso/dist/lib/mysql-connector-java-5.1.18-bin.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: modulocontrolacceso.ModuloControlAcceso
Im sorry im a noob in java this is my first program and my english isn't good either so i would apreciatte a full explanation to solve my problem.

if you are using eclipse then first clean all files using following steps
project->clean->select clean all -> and then click on
after that right click on your project
Export->click on Runnable jar->click next next and then finish
Problem will be solve.

Related

Jar file with Jaudiotagger, NoClassDefFoundError

I made a java class using the library Jaudiotagger, and it runs without problems. I then made a jar out of it and I got NoClassDefFoundError. Here's how it went:
I put the main class id3tag.java and the library jaudiotagger-2.0.3.jar in a folder and compiled using the command line. The program ran smoothly without problems.
javac -cp .;jaudiotagger-2.0.3.jar id3tag.java
java -cp .;jaudiotagger-2.0.3.jar id3tag
I then created the manifest and the jar file.
echo Main-Class: id3tag >manifest.txt
jar cvfm id3tag.jar manifest.txt id3tag.class jaudiotagger-2.0.3.jar
I got the following output:
added manifest
adding: id3tag.class(in = 5952) (out= 2997)(deflated 49%)
adding: jaudiotagger-2.0.3.jar(in = 811441) (out= 740599)(deflated 8%)
I then ran the jar file, and got "A Java Exception has occurred.". I also tried:
java -jar id3tag.jar
And I got the output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/tag/
FieldDataInvalidException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.tag.FieldDataInval
idException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
I then replaced all (both) error classes used from Jaudiotagger with Exception and recreated the jar. Now the same thing happens as for seemingly all other jar files when I run them (with Java(TM) Platform SE binary, or through writing id3tag.jar in the command prompt) - nothing. java -jar, however, works and gave me a runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/audi
o/AudioFileIO
at id3tag.tagSong(id3tag.java:112)
at id3tag.tagAlbum(id3tag.java:82)
at id3tag.tagArtist(id3tag.java:40)
at id3tag.main(id3tag.java:170)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.audio.AudioFileIO
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
It seems like the entire library just doesn't do shit for me. How do I fix this, and how do I get jar files to run without java -jar? (Also, how do I get the full pile'o'errors in case someone needs it, rather than just having it say "x more"?)
I'm not very savvy with this kinda shit so the more specific the answer, the better. Thanks.
I'm on windows 8 and latest java (1.7.0_17).
this is informing you that you have no main class, as you might or might not already know all programs in almost all non web based programming languages must have a main class to start from. In java it looks like this
public static int main(String[] args){
}
The message is informing you that this class is no longer there, this could be a compiler error or something entirely different.
please try downloading the library again, and downloading eclipse ide for java ee developers.
this ide has a built in compiler that will work better than a command line sometimes.
i hope this helped.
I worked around it by including the org folder from jaudiotagger in my .jar instead of the actual .jar file, and I then used a .bat file to run it instead of running the .jar directly. Feel free to add your own answer if you find a better solution, and I'll check back.
I extracted jaudiotagger-2.0.3.jar with winrar so that the org folder was in the same folder as my main class. Then I could compile and run the main class simply by:
javac id3tag.java
java id3tag
I then created the manifest file the same way as before, and created the jar:
jar cvfm id3tag.jar manifest.txt id3tag.class org
The jar file worked with java -jar id3tag.jar, but simply writing id3tag.jar still did nothing. Turns out it's because jar files are by default run by the javaw.exe file, so you have to right click the jar file -> open with -> choose default program and navigate to the java.exe file in your java folder (just search the folder). Running the .jar then gets you "Error: Could not find or load main class path\id3tag.jar". I worked around this by using a .bat file. I entered
java -jar path\id3tag.jar
into Notepad and saved as whatevername.bat (save as type: all files).
I created a new question for getting the .jar file to work properly. See .jar error - could not find or load main class.

"Exception in thread 'main'" error with Apache Ant on CentOS 6.4

I'm attempting to run Apache Ant for the purpose of compiling OpenGTS. While attempting to run any "ant" command I'm getting the following output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
Previously I was getting a message stating "JAVA_HOME is not defined correctly" and after reading several forum threads, was able to solve that by updating the path:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
Another thread stated a "CLASS PATH" issue but if I'm able to run "ant" anywhere in the terminal, wouldn't the path be correct? Thanks in advance.
Make sure to set ANT_HOME to the directory where you installed ant. Refer to Installling Apache Ant.
You need to export ANT_HOME too, just make sure it is installed first on your system
export ANT_HOME="/usr/local/ant";
In my case it was a wrong permission on /opt/ant/lib folder.

Jsoup error at run time: Exception in thread "main" java.lang.NoClassDefFoundError

I am getting the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
Now what I have done so far:
I created a libs folder in my project folder and added the Jsoup.jar there. Then in eclipse I click properties, add external Jar and added it. I see the referenced library.
But the issue still persist. I dont get compilation errors. So this is a runtime issue. Appreciate the help.
Edit:
I have found the following
If I compile using
javac -classpath /path/to/jsoup.jar myclass.java
and then
java -classpath /path/to/jsoup.jar myclass
It runs perfect.
Now. This is not working for me because I am going to use my application on a computer that does not have Jsoup. So how to I resolve this runtime issue?
Go to Run configurations... menu and check classpath for Run task. It looks like you add library for Compilation step, but it doesn't set at Run step.
Edit (after comment)
I dove into the issue and found that this dependency is needed for application container. So you just need to add this library to classpath of your app server. If you use Tomcat, just put the library to the %CATALINA_HOME%\lib directory.

Cannot get -javaagent to run without error

I'm trying to create a simple Java Agent program before I implement the real thing. I cannot get it to run. Clearly I have some sort of configuration or class path problem. No amount of looking and trying has lead to me the problem.
If I run:
java -cp ./demoAgent.jar -javaagent:./demoAgent.jar com.kingtigerbooks.demoMod.Main
I get the following error:
Exception in thread "main" java.lang.ClassNotFoundException: com.kingtigerbooks.demoAgent.Agent
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:280)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:338)
FATAL ERROR in native method: processing of -javaagent failed
Abort trap
I'm running this on my Mac. The jar file with the agent is in the current directory. The manifest for the jar file looks like this:
Manifest-Version: 1.0
Premain-class: com.kingtigerbooks.demoAgent.Agent
Can-Redefine-Classes: true
If smells like a class path problem, but as you can see I have included the jar on the class path. Any help would be appreciated. Its a very simple project.
Problem solved. I had a bad jar file. The agent jar file did not contain the agent class. By building the correct jar file and putting the fully qualified path to the jar on in the javaagent parameter it all works.
when you run an agent, you do not add the agent jar to the normal classpath.
as a side note, you can add -verbose:class to the command line to get info about the class loading process.

Java - Jar could not find included libraries and main class

I am currently trying to make a Jar with all my libraries included. What I have done, I have created folders like this :
eancopy (which contain all my classes)
lib (containing all my libraries : mongo, jedis...)
META-INF/MANIFEST.MF
My main class is named process (within the package eancopy)
My manifest is like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Class-Path: lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Main-Class: eancopy.process
I have generated the JAR with this command :
jar cvmf META-INF/MANIFEST.MF EANcopy.jar eancopy/*.class lib/*.jar
My problem : When executing the JAR by java -jar EANcopy.jar, it works when it is executed in the place where I have generated the JAR but in another place I have the message :
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
Caused by: java.lang.ClassNotFoundException: com.mongodb.DBObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: eancopy.process. Program will exit.
Any ideas ? Thanks
This exception shows you the cause of the problem:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
You haven't specified these libs lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar in your CLASSPATH environment variable, hence why it fails when run in other places.

Categories