On a Windows machine I had this problem when trying to run a certain unit test. While everything worked fine with a Maven build and also my colleagues had no problems.
Since this is a legacy project doing much stuff with reflection and resource loading.
Shorten command did not help me by using an argfile.
I was getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/TestDescriptor
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at com.intellij.rt.junit.JUnitStarter.getAgentClass(JUnitStarter.java:241)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:222)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.TestDescriptor
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 5 more
In the run configuration when I changed shorten commandline to JAR Manifest the application was trying to start but could not find certain resources from the classpath.
Solution
You might have too many dependencies causing a commandline command which is too long. Every dependency is added as classpath argument by it's absolute path. So if you have a long username your .m2 path will look like this:
C:\Users\LastnameFirstname\.m2\repository
I solved it by moving my .m2\repository
to C:\.m2\r
.
Changed the local repository path in my C:\Users\<name>\.m2\settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C://.m2/r</localRepository>
...
</settings>
Verify your maven repository in IntelliJ Maven settings.