无法自定义Eclipse JUnit调试配置的类路径。

huangapple go评论98阅读模式
英文:

Cannot customize the classpath of Eclipse JUnit Debug Configuration

问题

在VS Code中,我成功配置了在settings.json"java.test.config" / "classPaths"部分运行测试的类路径。我将"testKind""设置为"junit",并在"classPaths"数组中添加了jar文件的列表。我感到非常高兴,它起作用了。

我尝试从Eclipse中做同样的事情,我认为可以使用调试配置来完成。我尽力在Dependencies选项卡中添加所需的jar文件,但完全不起作用。当我点击“Show Command”时,我看到了来自Maven依赖项的大量classpath条目。无论我做什么,当我调试时,我发现执行过程都会进入Maven下的错误jar文件。

问题是,我如何确保运行测试时不需要的jar文件从类路径中移除?

我尝试添加了快照以澄清情况,但图像链接似乎已损坏。我将尝试稍后修复它。

英文:

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.

无法自定义Eclipse JUnit调试配置的类路径。

答案1

得分: 0

我通过定制引用项目的类路径解决了这个问题。主项目A正在引用项目B。我必须从A和B的pom.xml中删除不需要的依赖项,并在项目B中添加了一个名为userlib的文件夹,其中包含所需的jar文件,因为出现问题的类位于项目B中。从Java Build Path/Libraries/Add Library/User Library 中配置了用户库以指向主项目文件夹下包含所需jar的userlib文件夹。

之后,类路径在.classpath文件中成功更新如下:

<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/userlib"/>

然后,它就像魔术般地运行了。无需在调试配置框中更新任何类路径。现在,我可以运行来自项目A的测试,它将调用项目B中的类/方法,并且测试成功通过。

我遇到了这个问题,因为在本地Maven仓库中安装的所需jar文件不正确,所以我必须从本地环境中的一个正确工作的实例中选择正确的jar文件。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月14日 01:15:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681849.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定