Running Through Eclipse Works But Not IntelliJ after Migrating to JPMS
Answered
My company recently migrated to JPMS and we also use Eclipse as our standard IDE. I am the lone IntelliJ user (trying to convince others to move over too), so everyone I work with has not run into this. Prior to the move to JPMS, everything worked fine - I would just import the Eclipse projects to IntelliJ and it was great. However, after we recently moved to JPMS - I am seeing runtime exceptions related to classpath/modulepaths not being set correctly.
Here is what the command line cmd is for Eclipse:
C:\Program Files\AdoptOpenJDK\jdk-11.0.4.11-hotspot\bin\javaw.exe -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:55790 "-javaagent:D:\eclipse-jee-2019-09-R-win32-x86_64\eclipse\configuration\org.eclipse.osgi\412\0\.cp\lib\javaagent-shaded.jar" -Dfile.encoding=Cp1252 -p "<path_to_src>\src\Codes\GRAIL\build\java;<path_to_src>\src\Codes\Common\build\java;<path_to_src>\src\ThirdParty\lib\poi\poi-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-ooxml-4.1.1.jar;<path_to_src>\src\CommonUtilities\build\java;<path_to_src>\src\ThirdParty\lib\jdom2-2.0.6.jar;<path_to_src>\src\ThirdParty\lib\jaxb-api-2.3.1.jar;<path_to_src>\src\ThirdParty\lib\javax.activation-1.2.0.jar;<path_to_src>\src\CommonDataModel\build\java;<path_to_src>\src\ThirdParty\lib\geotools\gt-opengis-21.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\jts-core-1.16.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-metadata-21.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-referencing-21.0.jar;D:\eclipse-jee-2019-09-R-win32-x86_64\eclipse\plugins\org.junit_4.12.0.v201504281640\junit.jar;D:\eclipse-jee-2019-09-R-win32-x86_64\eclipse\plugins\org.hamcrest.core_1.3.0.v20180420-1519.jar;<path_to_src>\src\ThirdParty\lib\zip4j-1.3.3.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\mailapi.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\smtp.jar;<path_to_src>\src\ThirdParty\lib\commons-io-2.1.jar;<path_to_src>\src\ThirdParty\lib\JFreeChart\jfreechart-1.5.0.jar;<path_to_src>\src\ThirdParty\lib\JFreeChart\jcommon-1.0.23.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-core-2.9.10.jar;<path_to_src>\src\ThirdParty\lib\log4j-1.2.16.jar;<path_to_src>\src\ThirdParty\lib\CodeModel\codemodel-2.4.jar;<path_to_src>\src\ThirdParty\lib\commons-math3-3.6.1.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-main-21.0.jar;<path_to_src>\src\ThirdParty\lib\commons-lang3-3.8.1.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-shapefile-21.0.jar;<path_to_src>\src\ThirdParty\lib\commons-collections-3.2.2.jar;<path_to_src>\src\CommonCalculation\build\java;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-databind-2.9.10.3.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-annotations-2.9.10.jar;<path_to_src>\src\ThirdParty\lib\JUnit\junit-4.12.jar;<path_to_src>\src\CapabilityEngines\NuCSEngine\NuCSEngineCommon\build\java;<path_to_src>\src\ThirdParty\lib\WorldWindNightly\worldwind.jar;<path_to_src>\src\ThirdParty\lib\jaxb-runtime-2.3.1.jar;<path_to_src>\src\CapabilityEngines\NuCSEngine\InfrastructureEngine\build\java;<path_to_src>\src\Codes\PDCALC\build\java" -classpath "<path_to_src>\src\ThirdParty\lib\log4j-1.2.16.jar;<path_to_src>\src\ThirdParty\lib\poi\commons-collections4-4.4.jar;<path_to_src>\src\ThirdParty\lib\poi\commons-compress-1.19.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-scratchpad-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-ooxml-schemas-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\xmlbeans-3.1.0.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\dsn.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\imap.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\pop3.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-databind-2.9.10.3.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-annotations-2.9.10.jar;<path_to_src>\src\ThirdParty\lib\javax.annotation-api-1.3.0.jar;<path_to_src>\src\ThirdParty\lib\jaxb-runtime-2.3.1.jar;<path_to_src>\src\ThirdParty\lib\istack-commons-runtime.jar;<path_to_src>\src\ThirdParty\lib\GRAIL\commons-beanutils-1.9.2.jar;<path_to_src>\src\ThirdParty\lib\GRAIL\commons-logging-1.1.jar;<path_to_src>\src\ThirdParty\lib\commons-io-2.1.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-main-21.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-shapefile-21.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-opengis-21.0.jar;<path_to_src>\src\ThirdParty\lib\JUnit\hamcrest-core-1.3.jar;<path_to_src>\src\ThirdParty\lib\commons-lang-2.6.jar;<path_to_src>\src\ThirdParty\lib\commons-logging-1.1.jar;<path_to_src>\src\ThirdParty\lib\hsqldb.jar;<path_to_src>\src\ThirdParty\lib\jackcess-2.0.8.jar;<path_to_src>\src\ThirdParty\lib\ucanaccess-2.0.9.4.jar" -m sims.GRAIL/sims.GRAIL.GRAILVerification VERIFY_XML
And here is IntelliJ:
"C:\Program Files\AdoptOpenJDK\jdk-11.0.4.11-hotspot\bin\java.exe" -javaagent:C:\Users\USERNAME\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.7846.76\lib\idea_rt.jar=55128:C:\Users\USERNAME\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.7846.76\bin -Dfile.encoding=UTF-8 -p <path_to_src>\src\Codes\GRAIL\build\java;<path_to_src>\src\Codes\Common\build\java;<path_to_src>\src\ThirdParty\lib\log4j-1.2.16.jar;<path_to_src>\src\ThirdParty\lib\poi\commons-collections4-4.4.jar;<path_to_src>\src\ThirdParty\lib\poi\commons-compress-1.19.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-scratchpad-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-ooxml-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\poi-ooxml-schemas-4.1.1.jar;<path_to_src>\src\ThirdParty\lib\poi\xmlbeans-3.1.0.jar;<path_to_src>\src\CommonUtilities\build\java;<path_to_src>\src\ThirdParty\lib\jdom2-2.0.6.jar;<path_to_src>\src\ThirdParty\lib\jaxb-api-2.3.1.jar;<path_to_src>\src\ThirdParty\lib\javax.activation-1.2.0.jar;<path_to_src>\src\CommonDataModel\build\java;<path_to_src>\src\ThirdParty\lib\geotools\gt-opengis-21.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\jts-core-1.16.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-metadata-21.0.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-referencing-21.0.jar;C:\Users\USERNAME\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\201.7846.76\lib\junit-4.12.jar;<path_to_src>\src\ThirdParty\lib\zip4j-1.3.3.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\mailapi.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\smtp.jar;<path_to_src>\src\ThirdParty\lib\commons-io-2.1.jar;<path_to_src>\src\ThirdParty\lib\JFreeChart\jfreechart-1.5.0.jar;<path_to_src>\src\ThirdParty\lib\JFreeChart\jcommon-1.0.23.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-core-2.9.10.jar;<path_to_src>\src\ThirdParty\lib\CodeModel\codemodel-2.4.jar;<path_to_src>\src\ThirdParty\lib\commons-math3-3.6.1.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-main-21.0.jar;<path_to_src>\src\ThirdParty\lib\commons-lang3-3.8.1.jar;<path_to_src>\src\ThirdParty\lib\geotools\gt-shapefile-21.0.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\dsn.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\imap.jar;<path_to_src>\src\ThirdParty\lib\JavaMail\pop3.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-databind-2.9.10.3.jar;<path_to_src>\src\ThirdParty\lib\SEPTR\jackson-annotations-2.9.10.jar;<path_to_src>\src\ThirdParty\lib\javax.annotation-api-1.3.0.jar;<path_to_src>\src\ThirdParty\lib\jaxb-runtime-2.3.1.jar;<path_to_src>\src\ThirdParty\lib\istack-commons-runtime.jar;<path_to_src>\src\ThirdParty\lib\commons-collections-3.2.2.jar;<path_to_src>\src\CommonCalculation\build\java;<path_to_src>\src\ThirdParty\lib\GRAIL\commons-beanutils-1.9.2.jar;<path_to_src>\src\ThirdParty\lib\GRAIL\commons-logging-1.1.jar;<path_to_src>\src\ThirdParty\lib\JUnit\hamcrest-core-1.3.jar;<path_to_src>\src\ThirdParty\lib\JUnit\junit-4.12.jar;<path_to_src>\src\CapabilityEngines\NuCSEngine\NuCSEngineCommon\build\java;<path_to_src>\src\ThirdParty\lib\WorldWindNightly\worldwind.jar;<path_to_src>\src\CapabilityEngines\NuCSEngine\InfrastructureEngine\build\java;<path_to_src>\src\Codes\PDCALC\build\java;<path_to_src>\src\ThirdParty\lib\commons-lang-2.6.jar;<path_to_src>\src\ThirdParty\lib\commons-logging-1.1.jar;<path_to_src>\src\ThirdParty\lib\hsqldb.jar;<path_to_src>\src\ThirdParty\lib\jackcess-2.0.8.jar;<path_to_src>\src\ThirdParty\lib\ucanaccess-2.0.9.4.jar -m sims.GRAIL/sims.GRAIL.GRAILVerification VERIFY_XML
The error I get from IntelliJ is here:
[ERROR] 2020-06-05 08:34:04:578 GenericSerializer - GenericSerializer::59::Could not create Serializer for /xsd/Codes/GRAIL/xsd/COE_GRAIL.xsd
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
at java.xml.bind/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:177)
at java.xml.bind/javax.xml.bind.ContextFinder.find(ContextFinder.java:364)
at java.xml.bind/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:508)
at java.xml.bind/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:465)
at java.xml.bind/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:366)
at common.datamodel/common.utilities.JAXBSerializer.<init>(JAXBSerializer.java:76)
at common.datamodel/common.datamodel.GenericSerializer.get(GenericSerializer.java:54)
at common.datamodel/common.datamodel.GenericSerializer.readFile(GenericSerializer.java:109)
at sims.GRAIL/sims.GRAIL.GRAILVerification.pullRunOutput(GRAILVerification.java:280)
at sims.GRAIL/sims.GRAIL.GRAILVerification.appendRunData(GRAILVerification.java:157)
at sims.GRAIL/sims.GRAIL.GRAILVerification.pullRunData(GRAILVerification.java:68)
at sims.GRAIL/sims.GRAIL.GRAILVerification.pullRunData(GRAILVerification.java:31)
at sims/sims.verification.CodeModelVerification.pullDatabase(CodeModelVerification.java:507)
at sims/sims.verification.CodeModelVerification.verify(CodeModelVerification.java:184)
at sims.GRAIL/sims.GRAIL.GRAILVerification.main(GRAILVerification.java:46)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.xml.bind/javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at java.xml.bind/javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at java.xml.bind/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
... 14 more
And here is the .classpath from Eclipse:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="java"/>
<classpathentry kind="src" path="test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/Code">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/CommonDataModel">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/CommonUtilities">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/log4j-1.2.16.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/CommonCalculation">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/SEPTR/jackson-core-2.9.10.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/SEPTR/jackson-databind-2.9.10.3.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/SEPTR/jackson-annotations-2.9.10.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/GRAIL/commons-beanutils-1.9.2.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/GRAIL/commons-logging-1.1.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/commons-io-2.1.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/geotools/gt-main-21.0.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/geotools/gt-shapefile-21.0.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/geotools/gt-opengis-21.0.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/JUnit/hamcrest-core-1.3.jar"/>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/JUnit/junit-4.12.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="/NuCSEngineCommon">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="ENV_VAR/ThirdParty/lib/jaxb-api-2.3.1.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="/InfrastructureEngine">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build/java"/>
</classpath>
Please advise. Thanks!
Please sign in to leave a comment.
If it is a Maven or Gradle project I recommend you to import it from Maven/Gradle in IntelliJ IDEA instead of as an Eclipse project. IDE will take dependencies and compiler settings from Maven/Gradle then.
One thing I noticed from command line is that in Eclipse it consists of the module path (-p) and the classpath (-classpath). And the jaxb-runtime-2.3.1.jar is included in both: module path and classpath.
Does the project have module-info.java files? If you run code from a module with a module-info.java file, IntelliJ IDEA will automatically use the -p argument (module path) instead of -classpath. See related blog posts about JPMS support in IntelliJ IDEA:
https://blog.jetbrains.com/idea/2017/09/java-9-and-intellij-idea
https://blog.jetbrains.com/idea/2017/03/support-for-java-9-modules-in-intellij-idea-2017-1/
See also related request IDEA-171320:
>CURRENT SOLUTION
It does have a module-info. Unfortunately, we do not use Maven or Gradle. It is a legacy project that needs to catch up with the times, but we will get there someday.
Here is the module-info:
Also FWIW, I am using 2020.1.2.
Can you check in which dependency is the com.sun.xml.internal.bind.v2.ContextFactory class located? If this dependency is included into a module path I'm not sure why would not it work.
They say that the default factory should be configured: https://stackoverflow.com/a/60286701/2000323
That is in jaxb-runtime-2.3.1.jar, which is on the module path.
To me the behavior looks correct: IDE adds dependencies to the module path for this module since it modularized. Perhaps it is wrong class?
But the question is why Eclipse additionally specifies the -classpath in command line. Is there a project that could be checked? For uploading you can use ftp://ftp.intellij.net/.uploads / https://uploads.services.jetbrains.com or any file sharing service.