Trouble setting Classpath for Cpsuite with Maven - maven

Using Maven I am creating a jar-with-dependencies for a project that uses ClasspathSuite to create a JUnit test suite. When running the jar from the command line I am running into an issue where the project classpath isn't being supplied like it would be in Eclipse.
Exception in thread "main" java.lang.NoClassDefFoundError: com/<dir>/BaseCategoryRunner
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException: com.<dir>.BaseCat
egoryRunner
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
I need the project classpath so that ClasspathSuite can scan my files to build a junit class suite. I have been searching a number of ways to allow maven to include the classpath in my pom such as <additionalClasspathElements> or <Class-Path> but I cannot get the value to appear in the system property java.class.path. At this point I am unsure if I am just walking down a rabbit hole that isn't going to work.
Is it possible to have a classpath in my jar's manifest that will point to one of the jar's directory? In this case ./com/....
How can I have this classpath referenced so that maven will include it when the jar is executed?

Related

Error, when using ELKIs data generator

Maybe it is because of my skills in handling the terminal, but I don't understand why I get an exception here.
I have extracted the folders. And I think the paths are right.
db#computer:~/Desktop/elki-0.7.0~20150828/elki$ java -cp elki-0.7.0~20150828.jar de.lmu.ifi.dbs.elki.application.GeneratorXMLSpec -app.out 0.txt -bymodel.spec 1.xml
Exception in thread "main" java.lang.NoClassDefFoundError: gnu/trove/list/TIntList
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: gnu.trove.list.TIntList
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
db#computer:~/Desktop/elki-0.7.0~20150828/elki$
Your Java classpath is incomplete.
Specifically, it does not include the Trove library required.

Gradle not satisfying dependencies?

I'm trying to build this project from github:
https://github.com/tomakehurst/wiremock
The thing is, when I download it and run gradle build, I don't think all the required jar files are being loaded onto the class path. I get this error when I actually try to run the thing:
Exception in thread "main" java.lang.NoClassDefFoundError: joptsimple/OptionParser
at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.<init>(CommandLineOptions.java:75)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:49)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:110)
Caused by: java.lang.ClassNotFoundException: joptsimple.OptionParser
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
What gives? Isn't grade supposed to have downloaded this dependency by itself?
Try to execute gradle clean build jarAll
See this github issue for reference
From what I see in the build code, the task jarAll handles the joptsimple classes (and various others)

Running mvn shade on a pre-existing uber jar

I have a uber jar that's already generated (not via Maven; I just have the jar). I need to use it along with another jar, which has dependency conflicts. I'd like to shade all the libs in the first uber jar, except for a few classes which need to be public.
What is the setup to take an existing jar, and use Maven shade plugin to rename most (except for a whitelist) of its classes, generating a new uber jar?
You can do a "rename-all" type of activity with maven-shade-plugin. For example:
<relocations>
<relocation>
<pattern></pattern>
<shadedPattern>relocated.</shadedPattern>
<excludes>
<exclude>com.myfirm.level1.level2.*</exclude>
</excludes>
</relocation>
</relocations>
Will essentially move every package a.b.c to relocated.a.b.c (except for the explicit pattern I excluded).
It appears that the relocation process moves all references to classes that match that pattern, regardless if that class is defined within a dependency used to construct the jar.
The following stack trace (obtained from trying to run a main() defined in a jar that was constructed using the relocation above) shows that a reference to java.lang.Object was renamed to relocated.java.lang.Object, and that (obviously) the relocated. version can't be found.
java.lang.NoClassDefFoundError: relocated/java/lang/Object
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException: relocated.java.lang.Object
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
Exception in thread "main"

Failure running JavaFX 2.2 using Maven

I use Zen's Maven plugin to develop my JavaFX 2.2 application using Maven. The following is the plug-in declaration.
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
I fixed the classpath using the following command:
mvn com.zenjava:javafx-maven-plugin:2.0:fix-classpath
and the fixing probably succeeded.
The compilation also worked but the process did not generate JavaFX main files such as the following:
/com/javafx/main/Main$1.class
/com/javafx/main/Main$2.class
/com/javafx/main/Main.class
/com/javafx/main/NoJavaFXFallback.class
Running the project produces the following exceptions:
java.lang.NoClassDefFoundError: javafx/application/Application
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
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:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
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:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
What is going wrong and how can I fix it?
The main jar doesn't contain these classes, but the plugin generates an additional jar in the "target/jfx" directory (or something like this). Use that jar to start your application.

Issue creating concordion-extensions-demo with Maven

I am trying to create the concordion-extensions-demo (located at http://concordion.org/Download.html) project with Maven.
When I run the command mvn test I receive errors ...
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
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)
In the POM there are variables for ..
concordion.version, concordion-extensions.version and slf4j.version.
Do I need to update these tags with actual version numbers?
As is probably obvious I am not an experienced software devoloper or have much experience with Maven. Does anyone have an idea as to what the problem could be and how I could resolve this?
Thanks.
Tam.

Resources