简体   繁体   中英

Exception in thread “main” java.lang.ExceptionInInitializerError Caused by: javax.xml.bind.DataBindingException: javax.xml.bind.JAXBException

Apologies if my question isn't in the right format or is missing info. Please let me know and I'll edit as needed.

I'm a biologist trying to use a java tool for analyzing data ( https://omics.pnl.gov/software/ms-gf ). I have no experience programming in java. I run the program with the following command:

java -classpath /path/to/MSGFPlus.jar -Xmx3500M -jar /path/to/MSGFPlus.jar -s /path/to/datafile1 -d /path/to/datafile2

The program runs but fails at the final stage, and produces the error below. From googling I found this explanation: "the Exception in thread "main" java.lang.NoClassDefFoundError: means, that the class which you are trying to run was not found in the classpath. Solution: you need to add the class or .jar file which contains this class into the java classpath."

I followed the advice and added the jar file to the classpath using both export CLASSPATH="/path/to/MSGFPlus.jar" and by declaring it in the java call above. Neither fixed the error.

Any insight into how I can fix this?

Exception in thread "main" java.lang.ExceptionInInitializerError
    at uk.ac.ebi.jmzidml.model.utils.ModelConstants.<clinit>(ModelConstants.java:50)
    at uk.ac.ebi.jmzidml.xml.jaxb.marshaller.MarshallerFactory.initializeMarshaller(MarshallerFactory.java:35)
    at uk.ac.ebi.jmzidml.xml.io.MzIdentMLMarshaller.marshal(MzIdentMLMarshaller.java:100)
    at uk.ac.ebi.jmzidml.xml.io.MzIdentMLMarshaller.marshal(MzIdentMLMarshaller.java:91)
    at edu.ucsd.msjava.mzid.MZIdentMLGen.writeResults(MZIdentMLGen.java:143)
    at edu.ucsd.msjava.mzid.MZIdentMLGen.writeResultsOriginal(MZIdentMLGen.java:130)
    at edu.ucsd.msjava.mzid.MZIdentMLGen.writeResultsCleanerTempFile(MZIdentMLGen.java:214)
    at edu.ucsd.msjava.mzid.MZIdentMLGen.writeResults(MZIdentMLGen.java:113)
    at edu.ucsd.msjava.ui.MSGFPlus.runMSGFPlus(MSGFPlus.java:399)
    at edu.ucsd.msjava.ui.MSGFPlus.runMSGFPlus(MSGFPlus.java:106)
    at edu.ucsd.msjava.ui.MSGFPlus.main(MSGFPlus.java:57)
Caused by: javax.xml.bind.DataBindingException: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    at javax.xml.bind.JAXB.unmarshal(JAXB.java:186)
    at uk.ac.ebi.jmzidml.MzIdentMLElement.loadProperties(MzIdentMLElement.java:1102)
    at uk.ac.ebi.jmzidml.MzIdentMLElement.<init>(MzIdentMLElement.java:989)
    at uk.ac.ebi.jmzidml.MzIdentMLElement.<clinit>(MzIdentMLElement.java:39)
    ... 11 more
Caused by: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:241)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:455)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:652)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
    at javax.xml.bind.JAXB$Cache.<init>(JAXB.java:127)
    at javax.xml.bind.JAXB.getContext(JAXB.java:154)
    at javax.xml.bind.JAXB.unmarshal(JAXB.java:183)
    ... 14 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:573)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:239)
    ... 20 more

Surprisingly, I managed to fix it!

For anyone encountering the same problem, the solution was to follow the advice here How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9 . Specifically, adding --add-modules java.xml.bind .

The final call that ended up working was

java --add-modules java.xml.bind -classpath /path/to/MSGFPlus.jar -Xmx3500M -jar /path/to/MSGFPlus.jar -s /path/to/datafile1 -d /path/to/datafile2 

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