I have been through many posts but none of those helped! I am getting the following error while running JUnit tests for a test class:
java.lang.ClassNotFoundException: com.company.project.abc.pqr.AbcTest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:499)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Its running the tests through console but since I want to debug the tests, I need to do that through Eclipse. Can you pleas suggest what can I do?
I tried:
Build Again
Disable Maven Nature and then Enable Maven Nature
Maven Update Project
mvn eclipse:eclipse
mvn eclipse:clean
Added this to .project file
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
EDIT:
Added Run Configuration for the test class:
.classpath file:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes"
path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes"
path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con"
path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.
launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="GROOVY_DSL_SUPPORT">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
I want to add the packaging in my pom is jar.
jar
Related
https://tokkan.net/spring/mvc.html
I'm following this tutorial to create my first SpringMVC project.
It's in Japanese. You don't need to read it.
I will describe the procedures
Step 1. create a "Dynamic Web Project"
Step 2. convert it to a Maven project
When create the project, I noticed that the source folder in the tutorial is simply "src" but however it's "src\main\app" on my Eclipse
I tried to "Edit" it as "src" and found out it was not allowed ("Cannot nest source folder "src/main/java" inside source folder "src"")
I wouldn't mind this if it didn't come back and bite me
When creating the "Controller" class, I created a package (spring.test) first as per the tutorial. But when I started writing the class, all the imported packages (org.springframework) and annotations are underlined in red, implying that the dependencies are missing
But I have already successfully added all the dependencies in pom.xml. Something tells me it has something to do the src folder.
So I copied the file to src folder (from "src\main\app\spring\test" to "src") and the red underlines disappeared
I also tried "src\spring\test" and it also works fine
So exactly which folder should be the correct src folder (into which the controller.class file is stored? ) and is this setting configurable in one of the xml files?
The .classpth files is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
The pom.xml is as follows (same as in the tutorial except for the project name, etc):
<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>PeterMVC4</groupId>
<artifactId>PeterMVC4</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
<!--追加-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
You probably needed to update the pom.xml contents shown in the tutorial from
<sourceDirectory>src</sourceDirectory> to <sourceDirectory>src/main/java</sourceDirectory>.
The default folder path has changed (that tutorial was written for Apache Tomcat 8.0), but you can make it anything you want on the second page of the Dynamic Web Project wizard. I'd be surprised if it had any problem with the new default, as that's what the Maven archetype would create.
Using Eclipse STS 4.10 / linux .
I have a multimodule project like :
-rootFolder
-web (web app)
-dataservice (services, domain logic)
-datadef (model,repositories)
web has dataservice as a dependency
build.gradle shows:
dependencies {
compile project(':dataservice')
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
///
}
dataservice has datadef as a dependency
build.gradle shows:
dependencies {
compile project(':datadef')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
///
}
What I cannot achieve is datadef-1.0.0-SNAPSHOT.jar being included in dataservice-1.0.0-SNAPSHOT.jar file . Both are getting included in web.app though.
Sometimes eclipse "looses" reference on dataservice the datadef project and treat anything from datadef as an error.
Pasting dataservice project .classpath file. It shows the dependency on datadef.
<classpath>
<classpathentry kind="output" path="bin/default"/>
<classpathentry output="bin/main" kind="src" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry output="bin/main" kind="src" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry output="bin/test" kind="src" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="src" path="/datadef">
...```
Thank you.
I hate having to switch to the Navigator view just to see what was built. For example, if I want to see if my *.properties files getting moved, etc.
I tried removing all of the Filters... from Package Explorer's dropdown menu, but it is still not displaying the contents of my "target" folder.
Am I missing something?
I attached my .classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
As far as I know, only the Project Explorer view (not Package Explorer) can display output folders.
In that (Project) view, you should see a small down arrow at the top right of the view:
Choose the option Customize View option.
Uncheck the 'Java output folders' option in the filters list.
You would see the same process to see .class files produced by a classic java build.
A certain 'svn diff' on a '.classpath' file gives me the following output. I don't see any difference between the working copy (+) and the pristine copy (-) (do you?). The problem is I haven't changed these files (i.e. I haven't tried to change the build path of the project) but they seem to be modified during build. I use STS 3.3.0.RELEASE, and no 'svn' plugin. I do use maven plugin for eclipse for build.
It would be nice if they were left untouched. Is there a way, I can ensure this? On the other hand, if my '.classpath' file in question is untouched then why is 'svn diff' giving me this output?
Thanks.
## -1,29 +1,29 ##
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
The suspicion raised by #JimLewis and others in the comments below the question was indeed true. Saving the output of the said command into a file and doing a cat -v on that file produced the following output:
## -1,34 +1,34 ##
-<?xml version="1.0" encoding="UTF-8"?>^M
-<classpath>^M
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>^M
- <classpathentry kind="src" output="target/classes" path="src/main/java">^M
- <attributes>^M
- <attribute name="optional" value="true"/>^M
- <attribute name="maven.pomderived" value="true"/>^M
- </attributes>^M
- </classpathentry>^M
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">^M
- <attributes>^M
- <attribute name="optional" value="true"/>^M
- <attribute name="maven.pomderived" value="true"/>^M
- </attributes>^M
- </classpathentry>^M
- <classpathentry kind="src" path="src/main/resources"/>^M
- <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.io"/>^M
- <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.config"/>^M
- <classpathentry exported="true" kind="lib" path="jars-not-in-maven-repo/eventful.jar"/>^M
- <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.nlp"/>^M
- <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.attrs"/>^M
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">^M
- <attributes>^M
- <attribute name="maven.pomderived" value="true"/>^M
- </attributes>^M
- </classpathentry>^M
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">^M
- <attributes>^M
- <attribute name="maven.pomderived" value="true"/>^M
- <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>^M
- </attributes>^M
- </classpathentry>^M
- <classpathentry kind="output" path="target/classes"/>^M
-</classpath>^M
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.io"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.config"/>
+ <classpathentry exported="true" kind="lib" path="jars-not-in-maven-repo/eventful.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.nlp"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/net.holisticlabs.libs.attrs"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
The original '.classpath' was generated on a Windows machine, that uses CRLF newline character while maven on my unix machine replaced them with LF newline characters. As also was suggested, svn:ignore or 'svn revert' could be used to handle such cases.
The sources are downloaded in the Gradle cache and the classpath-entries for the source files looks ok, but Eclipse does not show the source files for 3rd party libs.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin/main"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry output="bin/test" kind="src" path="src/test/java"/>
<classpathentry output="bin/test" kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container" exported="true"/>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/source/bc9c347358c5d59998b27e8a13c75106c3d0696/spring-webmvc-3.1.2.RELEASE-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/jar/e02f3e5aa91c8caa37b2e9b780229d27e76c0f2e/spring-webmvc-3.1.2.RELEASE.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/source/19e4dedbb956cdc3bb1d34d61a351229b653029a/spring-data-jpa-1.2.0.BUILD-SNAPSHOT-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/jar/2a3cfc2ea0b2c8d87f32166e16bb56e1f092568b/spring-data-jpa-1.2.0.BUILD-SNAPSHOT.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/source/49e8d929d835d4ba4556ba9d138488ecc083a794/spring-security-web-3.1.2.RELEASE-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/jar/e43e7683289f08c1e073564a94e6f26298ec4f59/spring-security-web-3.1.2.RELEASE.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/source/7a561191db2203550fbfa40d534d4997624cd369/validation-api-1.0.0.GA-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/jar/b6bd7f9d78f6fdaa3c37dae18a4bd298915f328e/validation-api-1.0.0.GA.jar" exported="true">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
</classpath>
That's a weird behavior in Eclipse with the generated .classpath-file. Just put the 'Web App Libraries' entry at the bottom of your classpath file (-> Java Build Path -> Order and Export).
The best solution is to enhance your gradle.build file (then you don't need to reorder your build path each time you generate the classpath file via gradle):
...
eclipse.classpath.file {
// Classpath entry for Eclipse which changes the order of classpathentries; otherwise no sources for 3rd party jars are shown
withXml { xml ->
def node = xml.asNode()
node.remove( node.find { it.#path == 'org.eclipse.jst.j2ee.internal.web.container' } )
node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])
}
}