-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoClassDefFoundError when running test in project with classifiers #775
Comments
Hi @lkachun9129, Would you mind to provide a sample project for this issue? With that project we can do some investigation about this issue. |
I tried to reproduce the case by creating two simple maven projects but in vain. Is there any log file I can provide for the investigation? |
Yes there are some places to get the log. See: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting Besides, based on your comments: I guess this might be an issue related with the Language Server. Anyway, let's first check if we can have more information about the issue... |
I will get you the log tomorrow. The reason Project B is missing from the dependency viewer might be due to classes are directly loaded from the workspace instead of JAR file from the maven repository. |
Good morning. I have checked the log of Language Server and discovered the following [Trace - 9:06:48 AM] Sending request 'workspace/executeCommand - (35)'.
Params: {
"command": "vscode.java.test.runtime.classpath",
"arguments": [
[
"/app/home/ronaldlee/files/gitrepo-openjdk/project-a/src/test/java/a/b/c/d/e/RegistrationServiceTest.java"
]
]
}
[Trace - 9:06:48 AM] Received response 'workspace/executeCommand - (35)' in 106ms.
Result: [
"/app/home/ronaldlee/files/gitrepo-openjdk/project-a/target/test-classes",
"/app/home/ronaldlee/files/gitrepo-openjdk/project-a/target/classes",
// expected to see classes from project-b but it doesn't
// followed by a brunch of JAR files from maven repository, details skipped for simplicity
"/app/home/ronaldlee/.m2/repository_openjdk/********.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/********.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/********.jar"
] Maybe the Language Server failed to include classes of workspace dependencies into the class path. |
I check the same log from the two sample projects, class path is constructed correctly. [Trace - 9:26:09 AM] Sending request 'workspace/executeCommand - (57)'.
Params: {
"command": "vscode.java.test.runtime.classpath",
"arguments": [
[
"/app/home/ronaldlee/files/gitrepo-openjdk/project-a/src/test/java/projecta/ServiceATest.java"
]
]
}
[Trace - 9:26:09 AM] Received response 'workspace/executeCommand - (57)' in 32ms.
Result: [
"/app/home/ronaldlee/files/gitrepo-openjdk/project-a/target/test-classes",
"/app/home/ronaldlee/files/gitrepo-openjdk/project-a/target/classes",
"/app/home/ronaldlee/.m2/repository_openjdk/junit/junit/4.12/junit-4.12.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-test/4.3.7.RELEASE/spring-test-4.3.7.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-core/4.3.7.RELEASE/spring-core-4.3.7.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/commons-logging/commons-logging/1.2/commons-logging-1.2.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-context/4.3.16.RELEASE/spring-context-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-beans/4.3.16.RELEASE/spring-beans-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-expression/4.3.16.RELEASE/spring-expression-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-aop/4.3.16.RELEASE/spring-aop-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-webmvc/4.3.16.RELEASE/spring-webmvc-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-web/4.3.16.RELEASE/spring-web-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-orm/4.3.16.RELEASE/spring-orm-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-jdbc/4.3.16.RELEASE/spring-jdbc-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/.m2/repository_openjdk/org/springframework/spring-tx/4.3.16.RELEASE/spring-tx-4.3.16.RELEASE.jar",
"/app/home/ronaldlee/files/gitrepo-openjdk/project-b/target/classes"
] I think I should pass this issue to Language Server for their follow-up. |
I see. Basically the test runner will ask Language Server for the classpath (as you can see in the log). Something wrong must happen inside that, which also cause the @lkachun9129 it will still be useful if there is a sample project which can repro this issue. Then I can go deep to see what's happening inside the Language Server. I'll try to make a project to repro this |
Sorry, could you explain more about: |
I tried to create two simple maven projects to replicate the issue. However, the class path issue could not be found on the two simple projects. The first log comes from my original projects, which is currently affected by the class path issue. The second log comes from the two simple projects, which is not affected by the class path issue. |
I see. Are all the dependency scope of the dependencies the same from the origin project and the sample project? |
Yes. |
After checking once again, I can finally reproduce the issue. The issue happens when the classifier is marked as <dependency>
<groupId>sample</groupId>
<artifactId>project-b</artifactId>
<version>1.0.0</version>
<classifier>classes</classifier>
</dependency> Sample projects attached below: |
Project A and Project B are separate web applications. That's why they are packed as a WAR instead of JAR. Since Project A requires some services defined in Project B, only classes of Project B are included in Project A and hence Project B is marked as |
I see. But from the sample project, if I run |
Oh I missed the <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<attachClasses>true</attachClasses>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin> However, this missing config is not the cause of the problem. Here is the updated sample project: |
Yes I can repro it now. Just curious that have you run the tests in other platforms, do they work as expect? |
Tried on both RedHat Linux and Windows, both failed to run. |
Ah, I mean, other IDEs? |
No |
Ok, let's see if we can solve it from upstream first. |
@jdneo any update on this? Our projects are relying on the classifier. |
I have same issue. A war provides some classes which are needed in another submodule. I also use the classes classifier.
Have we any progress for a fix? |
I guess this may require the upstream issue to be fixed first |
VSCode version: 1.37.0
Java Test Runner version: 0.19.0
The workspace contains two projects, i.e. A and B. Project A depends on Project B.
When executing an unit test of Project A, the test failed due to a missing Java class definition from Project B.
When browsing the dependency of Project A using
Java Dependency Viewer
, Project B is missing from Maven Dependencies.If I remove Project B from the workspace, Project B re-appears in the dependency list under Maven Dependencies. At this moment, the test runs perfectly fine without any issue.
I am not sure whether there are some issues on resolving classpath in mutli-project workspace.
The text was updated successfully, but these errors were encountered: