Issue
In VS Code, I managed to configure the classpath for running the tests using settings.json
section "java.test.config" / "classPaths"
. I set the "testKind""
to "junit"
and added the list of jar files in the array "classPaths"
. I was so happy that it worked.
I tried to do the same from Eclipse, and I thought the way to do that is using Debug Configuration. I did my best to add the needed jars the Dependencies
tab, and it is not working at all. When I click "Show Command", I see a huge list of classpath entries which are coming from Maven Dependencies. No matter what I do, when I debug, I see that the execution is going to a wrong jar under Maven.
The question is how I can ensure that the unwanted jars are removed from the classpath when running the test?
I tried to add the snapshot to clarify and the link to the image appears to be broken. I will try to fix it later.
Solution
I was able to solve the problem by customizing the classpath for the referenced projects. The main project A was referencing project B. I had to remove unwanted dependencies from pom.xml in A and B and added a userlib
(folder) with the needed jar files to project B since the failing classes were in project B. From Java Build Path/Libraries/Add Library/User Library. Configure the userlib to point to a userlib folder under the main project folder with the needed jars.
After that, the classpath was updated successfully in the .classpath
file as follows:
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/userlib"/>
Then, it worked like a charm. There was no need to update any classpath in the Debug Configuration box. Now, I am able to run the test from Project A that will call the classes/method in Project B and it passed successfully.
I faced this problem because the needed jar files which are installed in the local Maven repositories are not the correct ones, so I had to pick the correct ones from a proper working instance in the local environment.
Answered By - tarekahf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.