I have a maven project with unit tests, and I get a large exception trace when running "mvn install". Surprisingly -- this stacktrace actually doesn't result in failure of the task ! It appears that it is related to the availability of Junit libraries...
1) Id like to know how to fix this (obviously) for this project so that the libraries are available and the tests run (yes, Junit4 is in the pom.xml dependencies).
2) What the best way to definitively debug this and find the root cause is ?
3) Why does Maven say "build success" when clearly the surefire utility threw a nasty exception ?
org.apache.maven.surefire.util.SurefireReflectionException:
java.lang.reflect.InvocationTargetException; nested exception is
java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
Caused by: java.lang.NoClassDefFoundError: Test at
java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2427) at
java.lang.Class.getMethod0(Class.java:2670) at
java.lang.Class.getMethod(Class.java:1603) at
org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:57)
at
org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:65)
at
org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:60)
at
org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:55)
at
org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(JUnit4TestChecker.java:52)
at
org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses(DefaultDirectoryScanner.java:80)
at
org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:174)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:83)
... 9 more Caused by: java.lang.ClassNotFoundException: Test at
java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 21 more
POM is below
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rudolf</groupId>
<artifactId>r1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>r1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.9.1.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.4.0a</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
</project>
This is definetly a perfect storm of silliness:
1) My Test Classes is not named according to the default surefire regular expressions See related Maven does not find JUnit tests to run. So the tests weren't really running.
2) The Test that DID run was actually doing some JVM hacking, using classes like "Unsafe" - causing a segmentation fault. This segmentation fault mucks with the overall Maven build, corrupting the result of the maven output.
The take home lessons are:
1) (not 100% sure, but it appears ) -- If some odd low level failure occurs in the JVM during a mvn build, one might expect strange results at the end which dont simply indicate errors/failures in the proper manner
2) Default Junit test case for surefire behaviour doesnt just run all #Test methods in a package automatically - classes have to be named appropriately or you have to manually edit the surefire pattern filters.
I've run into a problem like this with TestNG integration tests (fail-safe). A similarly really cryptic error caused me to lose an entire day (argh! - please, Eclipse/TestNG, if you're going to give us errors, make them helpful). In my case it was because the accessor on the test method was private and needed to be public.
I hope someone else find this useful before an entire day is wasted.
Related
I want to create a executable jar file so anyone can run it from their computer with least install require components.
I found several tutorial but none of them a work.
When I execute jar file I've built they are return error like:
Error: Could not find or load main class fully.qualified.MainClass
Caused by: java.lang.ClassNotFoundException: fully.qualified.MainClass
OR like this:
Error: Could not find or load main class io.cucumber.core.cli.Main
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.cli.Main
My project run from Intellij with no problem.
Here my project structure
https://i.stack.imgur.com/NcQzf.png
And my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>CucumberSelenium</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>7.6.0</cucumber.version>
<selenium.version>4.8.0</selenium.version>
<webdrivermanager.version>5.2.1</webdrivermanager.version>
<junit.jupiter.version>5.9.0</junit.jupiter.version>
<apache.common.version>2.4</apache.common.version>
<projectlombok.version>1.18.24</projectlombok.version>
<maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
<maven.surefire.plugin.version>3.0.0-M7</maven.surefire.plugin.version>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>${cucumber.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit Platform -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- Web Driver Manager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdrivermanager.version}</version>
</dependency>
<!-- Apache Common -->
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>${apache.common.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${projectlombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<properties>
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
<debugForkedProcess>true</debugForkedProcess>
<forkCount>0</forkCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>io.cucumber.core.cli.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I've run mvn clean compile assembly:single, it's output a CucumberSelenium-1.0-SNAPSHOT-jar-with-dependencies.jar file, but it wont runs.
I just came across a similar issue and, despite trying the ubiquitous
java -cp . org.example.Main
(while on current directory being where the Main.class is), I kept getting this dreaded
"Error: Could not find or load main class"
I eventually resorted to comparing the actual command with parameters invoked by IntelliJ (on IntelliJ IDEA's debug log) with mine, and discovered that the following solves the issue:
java -cp C:\Users\WebViwer\IdeaProjects\MyProj\target\classes org.example.Main
I am guessing that once the fully qualified class name is specified, the current directory (where the class resides) is no longer valid as a classpath: Only the top level classes directory should be specified (in this org.example, 2 levels up).
You have a a few problems going on.
The maven-assembly-plugin should not be a in the dependencies section. It is not a dependency used by the runtime code of your project.
Your step definitions, feature files and glue code located in src/test are not included in the jar file build by the assembly plugin.
Your test scoped dependencies will also not be included by the assembly plugin either.
You must configure the containerDescriptorHandler of the assembly plugin with metaInf-services or the plugin will not merge files in META-INF/services correctly.
You can verify most of these by opening the generated jar file (it's a .zip file in disguise).
My project run from Intellij with no problem.
When running tests in Intelij you are using the test scope, the jar file only includes runtime scoped code.
For a more comparable test you must create a new run configuration that invokes the main method.
I found several tutorial but none of them a work.
It appears that you are relatively new to Java and Maven. It would be prudent to follow a proper course first rather than tutorials. You are missing fundamental knowledge that is generally not taught in tutorials.
I want to create a executable jar file so anyone can run it from their computer with least install require components.
It's also prudent to consider why you are doing this.
Tests will typically change as quickly as the source code they are testing does. Manually distribution of jar files won't keep up with this.
This means it's generally better to integrate the tests and the test source code into the automated build pipeline of the project they test.
This also means that you don't need to distribute your tests as a jar. Rather you should expect (and possibly train) people to use Maven, GIT and Java.
I'm trying to install the Deeplearning4j library ( https://deeplearning4j.org/index.html) but I don't understand how to use install the lib correctly with IntelliJ and Maven so that I can build a .jar file from it.
As long as I'm running the program from IntelliJ everything seems to work.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>DeepLearning</groupId>
<artifactId>deeplearning</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-core -->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-api</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native-platform -->
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>0.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MLPClassifierLinear</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
I am not sure if everything is set up correctly because it's the first time I use maven.
When I run the maven install command and start the .jar file I get an error that says that a JNI error has occurred and a NoClassDefFoundError.
This is the exact error message:
Error: A JNI error has occurred, please check your installation and
try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/deeplearning4j/nn/conf/layers/Layer at java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at
java.lang.Class.privateGetMethodRecursive(Class.java:3048) at
java.lang.Class.getMethod0(Class.java:3018) at
java.lang.Class.getMethod(Class.java:1784) at
sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
org.deeplearning4j.nn.conf.layers.Layer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more
Can somebody explain me how to use maven correctly so I can build .jar files without getting errors?
Thank you :)
Simple recipe for getting most things done:
deeplearning4j-core, nd4j-native-platform, maven shade plugin
deeplearning4j-core gives you most dependencies people use on simple desktop.
nd4j-native-platform bundles all operating system native dependencies so you don't have to worry about multi OS deployments/binaries. This also makes sbt and gradle actually..usable since they can't handle classifiers.
maven shade plugin handles building the jar properly.
https://github.com/deeplearning4j/dl4j-examples/blob/94568e78e86c56807c03fe17d6a2f89f0b0df377/dl4j-spark-examples/dl4j-spark/pom.xml#L98
Also, please don't use the term "install". You aren't installing anything. You're setting up a set of libraries using a dependency manager. It's not installing in the sense of the OS like ruby and python tend to do.
Beyond that: Specific critiques about your pom. nd4j-native here is redundant. You don't need that. You only use nd4j-native if you are using snapshots or building from source.
Datavec-api isn't needed because it's already brought in by deeplearning4j-core. Please read up on maven transitive dependencies to understand how this works.
If you aren't sure on how any of these things get resolved, look at using
mvn dependency:tree
I'm porting a project to Maven. It seems that I'm almost done, though there's still a strange problem. I have an enum:
package cz.autoclient.settings;
public enum Setnames {
SETTING1("s1", false),
SETTING2("s2", 666),
;
public final String name;
public final Object def;
Setnames(String n, Object d) {
name = n;
def = d;
}
}
I use this particular enum to avoid re-creation of String whenever some setting is loaded from the database. And to store default values.
In my old project, this was valid:
import cz.autoclient.settings.Setnames;
In Maven, there's a problem:
Exception in thread "main" java.lang.NoClassDefFoundError: cz/autoclient/settings/Setnames
at cz.autoclient.Gui.createTabs(Gui.java:326)
at cz.autoclient.Gui.initComponents(Gui.java:165)
at cz.autoclient.Gui.<init>(Gui.java:58)
at cz.autoclient.Main.startGUI(Main.java:71)
at cz.autoclient.Main.<init>(Main.java:32)
at cz.autoclient.Main.main(Main.java:98)
Caused by: java.lang.ClassNotFoundException: cz.autoclient.settings.Setnames
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)
Gui.java:326 is the line where I first use Setnames. I've been googling and what I got that you've got to use $ when naming enums somehow.
But I've no idea where should I put that $ in my case - other people allways had this problem when enum was hidden within a class.
Here's what it looks like in my IDE:
Here's the project pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.autoclient</groupId>
<artifactId>autoclient</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<src.dir>src/</src.dir>
<test.dir>test/</test.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<testSourceDirectory>${test.dir}</testSourceDirectory>
<sourceDirectory>${src.dir}</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<name>Auto Client</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
</project>
This is the command line NetBeans is using to compile the project:
cd C:\MYSELF\programing\java\AutoCall\AutoClient; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_31" cmd /c "\"\"C:\\Users\\Jakub\\AppData\\Roaming\\NetBeans\\7.4\\maven\\bin\\mvn.bat\" -Dexec.args=\"-classpath %classpath cz.autoclient.Main\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_31\\bin\\java.exe\" -DnetbeansProjectMappings= -Dmaven.ext.class.path=C:\\Users\\Jakub\\AppData\\Roaming\\NetBeans\\7.4\\maven-nblib\\netbeans-eventspy.jar org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
You created a maven project and moved your class from cz.autoclient.settings.Setnames to cz.autoclient.PVP_net.Setnames. Now you're getting an NoClassDefFoundError which means that java simply can't find your class. Why? Because it's moved to another place, but this has nothing to do with maven it has just happened after creating a maven project.
Please check your whole project for imports like:
import cz.autoclient.settings.Setnames;
an replace them by something like:
import cz.autoclient.PVP_net.Setnames;
I hope that helps you.
Turned out it was some kind of glitch in the project. I have no idea how it happened.
Refactoring the packages with problematic classes fixed the problem.
Currently my NetBeans 8.0 has been doing the strangest thing.
I have a multimodule project. Usually I did not even have to have the projects opened or even downloaded, if the modules were in maven repository. Currently, some of my modules however need to be opened and built, so that "target" folder is in the project directory filled with classes. If it is not, I get a NoClassDefFoundError.
The error looks like this:
Exception in thread "main" java.lang.NoClassDefFoundError: SOME/CLASS/THAT/IS/EXPECTED/IN/TARGET/FOLDER/OF/SOME/MODULE/THAT/IS/A/DEPENDENCY
at ...
Caused by: java.lang.ClassNotFoundException: com.example.SOME.CLASS.THAT.IS.EXPECTED.IN.TARGET.FOLDER.OF.SOME.MODULE.THAT.IS.A.DEPENDENCY
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
My POM looks like this:
<parent>
<groupId>some</groupId>
<artifactId>parent</artifactId>
<version>0.9-SNAPSHOT</version>
</parent>
<scm>
<developerConnection>scm:svn:https://someconnection</developerConnection>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<tagBase>sometagbase/tags</tagBase>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>myModuleGroupId</groupId>
<artifactId>somModule1</artifactId>
<version>1.2.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
...... many of these here
</dependencies>
Why does it suddenly require a target folder with classes? Is it not supposed to get them from the dependencies? From the repository?
Open maven tab at right side of the editor and run double click all options of life cycle and try to see if folder finally generated
SOLVED: My class resource was named TestCounter... maven was trying to test it. Renamed it to CounterSwitch and build was successful.
I'm very new to maven, please bear with me... I have some tests that run great in eclipse, but fail during a maven build.
The tests are in: src/test/java/main/*.java
The tests use test-only classes in: src/test/java/**/*.java
The tests also require access to resources located in: src/test/resources/packages/etc...
Within my resources are .java source files that I am not compiling, but am using for JaCoCo analysis tests. I'm loading these resources using relative pathed File objects since resource loader insists on using absolute pathing and causes my tests to fail.
Common sense says that the relative pathing changes post-build and that's why maven's throwing NoClassDefFoundError, but it's also throwing the exception when it encounters one of the .java files... it may be trying to compile it or it may just be a coincidence.
However, the solution may be more convenient as it is not necessary for me to run these tests during the maven lifecycle, they're functional tests that are used more for the results they produce and less for their assertions but I have no idea how to blacklist them.
I have two questions: how do I segregate those files from my maven build that are undesirable, and how do I include those files into my maven build that are?
I'd appreciate any help I can get... here's a relevant representation of my pom.xml (plugins make it quite lengthy) for reference, it's almost a default configuration as I have no idea where to begin with it:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.genericpackage</groupId>
<artifactId>genericartifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>genericartifact</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Stack Trace:
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.NoClassDefFoundError: mockprocesses/itclient-counter/bin/main/TestCounter (wrong name: main/TestCounter)
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 org.apache.maven.surefire.util.DefaultDirectoryScanner.loadClass(DefaultDirectoryScanner.java:98)
at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses(DefaultDirectoryScanner.java:78)
at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:174)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:83)
... 9 more
Fixed it, the problem was obvious... the class/java files were named TestCounter... surefire was trying to test them. Renamed them to CounterSwitch and the build went off without a hitch.
Had same issue, fixed it including the file as part of maven-surefire-plugin configuration, as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>src/main/java/mockprocesses/itclient-counter/bin/main/TestCounter.java</include>
</includes>
</configuration>
</plugin>