I am attempting to run Xstream in a netbeans proof of concept project. I have the following code.
XStream xstream = new XStream();
FileOutputStream fis = new FileOutputStream("Test.xml");
xstream.toXML(company, fis);
The program is crashing on the first line of code with the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
at com.thoughtworks.xstream.XStream.<init>(XStream.java:336)
at Parser.XParser.Parse(XParser.java:24)
at rejaxbtest.REJAXBTest.main(REJAXBTest.java:39)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
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)
... 3 more
Java Result: 1
I have seen one other thread with this problem, but the answer that was given was put the jar in the project lib directory, but netbeans has already correctly finished that task. Any other possible thing that would cause java not to recognize the Xstream class at runtime even though it is fine at compile time?
Thanks
Jimmy
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
It seems you are missing required jars in classpath.
Make sure all jars required (the jars you have at compile time) are in runtime classpath (if it is web application, copy those jars to lib folder)
Use different constructor
i.e.
new Xstream(new StaxDriver())
see
XStream XmlPullParserException
Related
I am working on a vanilla Eclipse project and trying to avoid using Maven.
I have added Jackson modules to the module path as an external jar. When I do so, the import statement no longer shows an error but when I run my program I get the following error
Exception in thread "main" java.lang.NoClassDefFoundError:
com/fasterxml/jackson/databind/ObjectMapper at
bitcoin.PriceConverter.getJsonFromUrl(PriceConverter.java:48) at
bitcoin.PriceConverter.main(PriceConverter.java:26) Caused by:
java.lang.ClassNotFoundException:
com.fasterxml.jackson.databind.ObjectMapper at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
Line 48 in PriceConverter is ObjectMapper objMapper = new ObjectMapper();
I have googled extensively and found that my classpath is potentially broken however, all of the answers are from outdated versions of Eclipse and I cannot work out how to fix this problem.
I tried the same thing with Gson and had the same problem however, yesterday I added the json-20210307.jar and it worked fine.
Can anyone explain what is happening here and guide me on how to fix it?
Exclaimer: I am pretty much a complete noob when it comes to eclipse and java, but I am learning! :D Thanks for your help
I am using the apache commons io to create an external server log that is saved in a file along with showing in the server console itself. I added the right file to the external jar library and it all works inside eclipse, but when I export it and try to run it on it's own, I get these errors
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/output/TeeOutputStream
at com.josh.chat.server.ServerMain.<init>(ServerMain.java:10)
at com.josh.chat.server.ServerMain.main(ServerMain.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.TeeOutputStream
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
What is going on? How do I fix this, or at least is there another way for me to use the console AND save a log of that console to a text file?
EDIT: I didn't change anything (at least I don't think I did...) and tried to run it again and then got this different error, what did I do?
no main manifest attribute, in InstantChatServer.jar
Probably your issue might have been fixed by now but on broader scope if you need further dependencies/libraries to be there then you will have to edit the class path and also the client(the one who is doing the java -jar ... stuff) needs to have those dependencies be present in his box.What if there are hundred such dependencies. Ideally you should prefer a build tool like maven,gradle etc. and bundle the jars/dependencies with your code. So that the client need not have to bother about having the libraries in local box.
I have received an IntelliJ project from someone else, but it won't run even the simplest classes for me.
As a quick example, the following class will throw a ClassNotFoundException without compiler errors:
package myPackage;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("Soon our GUI will start from here!");
System.exit(0);
}
}
This will throw the following error:
Exception in thread "main" java.lang.ClassNotFoundException: myPackage.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Process finished with exit code 1
The file structure is as follows:
<git root>/src/myPackage/Main.java
I have set the 'src' folder as the 'source folder'. My application has no compiler errors.
I have invalidated the caches several times, but with no effect whatsoever.
In my module settings my module dependencies contain <Module source> and jdk 1.8.
I can't seem to find the answer around here (google) anywhere, and to me it seems like this error has to do with the way IntelliJ handles the project. When I first pulled the project, the src folder had NOT been set to be the source folder, which probably means I may be missing out on other settings as well.
Zack Newsham's suggestion helped me. Here is what I did:
Deleted .iml file
File > New > Project, specified the existing folder with code
completed project setup (Manifest, artifacts).
Now the project runs.
Of course there may be other reasons for ClassNotFound. However when everything seems ok or if the error comes up after it worked before, try these simple steps.
I'm using NetBeans. I have a simple project, which prints in a fancy format some data sent as arguments.
This is the code that throws an Exception:
JasperDesign design = JRXmlLoader.load("Certificate.jrxml");
JasperReport report = JasperCompileManager.compileReport(design);
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), new ClientList(args).getClients());
JPanel panel= new JRViewer(print);
These Exceptions are thrown whenever a Jasper class is created.
I also tried System.getProperty("java.class.path") and it includes the "jasperreports-5.0.1.jar" file..
What am I doing wrong? I know these Exceptions are thrown whenever a class is available at compile time, but not at runtime.. But the jar is there!
Requested Stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
at certificado.Certificado.main(Certificado.java:31)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.Digester
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
Java Result: 1
You may be compiling against the Jasper jar ok, but at runtime that jar has its own dependencies, and you should include those too.
According to your stacktrace you need Apache Commons Digester. I would perhaps build using Maven, and let Maven (hopefully) resolve the set of dependencies for you. You can use a Jar search engine to find these dependencies, but they won't determine matching versions of those jars for you.
Your library (Jasper?) seems to have a (run-time) dependency on another library.
Meaning, it requires some other JAR to be present on classpath when being executed.
The missing classname is org/apache/commons/digester/Digester. Thus you can guess the missing library is commons-digester. Make sure the Digester library is available on Classpath too.
I face same problem, I just add commons-digester-2.0.jar and problem get solved.
I am using eclipse 32bit in my office and developing a java code to parse JavaAST, but when I try to run the program at home I am getting a getting this exception.
I am also providing where the Exception is occurred.
How can I Resolve this exception?
Exception Line
ASTParser parser = ASTParser.newParser(AST.JLS3);
Security Exception
Exception in thread "main" java.lang.SecurityException: class "org.eclipse.core.runtime.Plugin"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:943)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:657)
at java.lang.ClassLoader.defineClass(ClassLoader.java:785)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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)
at org.eclipse.jdt.core.dom.ASTParser.initializeDefaults(ASTParser.java:235)
at org.eclipse.jdt.core.dom.ASTParser.<init>(ASTParser.java:218)
at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java:118)
at tester.runTest.main(runTest.java:33)
Please refer to this page on Java documentation: Sealing Packages within a JAR File. That is the probable cause of the error you're seeing.
In short, when a jar file is sealed the JVM assumes every class from that jar's packages must be defined inside that jar. If there is some code in other parts of your project that belongs to the same package, it will treat is as a security exception.
Check if the code you're running at home is structured similarly to what you're running in the office. You might have some classes defined in regular .java files, accessible from your CLASSPATH, that belongs to the same package(s) defined in that jar file. Try removing any unnecessary dependencies from your project (so it looks as closely as possible to your working envirnment) and see if that solves your problem.
Edit: I might have mistaken signed for sealed; the relevant docs, then, is Signing and Verifying JAR Files. The probable cause and possible solution remains the same, though...
This error is caused by adding jars twice. If you add more than one jar which share some classes it will end in the error you are seeing now.
I suggest you try remove the concurrent jar and then test your code.
Hope this helps!