Home » Language IDEs » Java Development Tools (JDT) » Eclipse can't find the test class files for one particular project
Eclipse can't find the test class files for one particular project [message #1822404] |
Thu, 05 March 2020 17:11 |
David M. Karr Messages: 802 Registered: July 2009 |
Senior Member |
|
|
I've been using Eclipse 2019-12 since the day it was released. I have a bunch of different related projects that are all SpringBoot Java Maven projects, which were imported from my local git repositories.
In general, all of these work perfectly fine.
Yesterday, I discovered that I couldn't run unit tests in Eclipse for one particular project. This project had been in my workspace for quite a while, and I do things with it almost every day, including running unit tests. What I saw yesterday is that all my attempts failed because it couldn't find the test class file. Other similar projects had no problem with this. I viewed the settings for the project, and there was nothing unexpected. The src/test/java directory was a source directory, and I could use "Open Type" to open the test class. I tried doing "Maven Update". No change. Running "mvn package" from the shell works fine, and I can clearly see that it executes all the unit tests.
I tried deleting the project and reimporting from git. No change.
I then tried deleting the project again, and then manually deleted the .project, .classpath, and .settings files and folder, and then reimporting from git. This made it worse. Initially, it didn't appear to know it was even a Java project.
I then deleted the project again and edited the .project file from another editor. I compared it to to one of the other .project files. It only had the "maven2Builder", and didn't have the "javabuilder" or "springbootbuilder". It also only had the "maven2nature", and didn't have the "javanature" or "groovyNature". I manually copied those elements from the other .project file and reimported the project.
At this point, it knew it was a Java project, but it only added the root "src" directory as the only source folder, instead of src/main/java, src/test/java, and others. I also noted that it still didn't have a .classpath file. So, I deleted the project again and created the .classpath file with an external editor. I copied in the .classpath file from a related project. The structure of the two projects were identical, so this barely required any changes (the other project had one additional source folder that this project didn't have, so I deleted that entry). I then reimported the project again.
The project now "looks" normal in the package explorer. However, I STILL cannot execute unit tests in this class. I have come full circle. I can open the test class with "Open Type", but executing it fails with a ClassNotFoundException in the console.
If I search for the particular test class file in the shell, I find it in the expected locations in both "bin" and "target/test-classes", in the correct package directory.
I looked in the Eclipse error log, and there was nothing significant there.
Curiously, I'm seeing no issue with "Run/Debug As ... Spring Boot App". This finds all of the required class files and starts up fine. I just can't run unit tests.
As unit tests in other projects are working fine, I tried comparing aspects of one working unit test with one in the bad project. I first looked at the run configurations, and I stepped through each tab, going back and forth between the two run configurations, and the only difference I saw was the name of the project, so I found nothing of interest there.
I then looked for the working class file in the shell in the working project, and what was curious is that I did NOT find it in the "bin" tree. In fact, the working project didn't even have a "bin" directory. I then verified that the project properties didn't even refer to a "bin" directory, including any of the "output folders", in both projects. I'm not sure why the problematic project even had a "bin" directory, as it clearly doesn't refer to it anywhere.
So, I then deleted the project again, and then deleted the "bin" directory from the shell, and reimported the project. Unfortunately, still no change in the overall symptom. It still gets the ClassNotFoundException trying to run the test class.
I also noted that there were some differences between the ".settings" files in the two projects.
The bad project had these two files:
* org.eclipse.jdt.groovy.core.prefs
* org.eclipse.core.resources.prefs
The good project had those two files, and also had these files:
* org.eclipse.jdt.core.prefs
* org.springframework.ide.eclipse.prefs
The following file was different between the two:
*** .settings/org.eclipse.core.resources.prefs 2018-10-31 16:31:10.644650300 -0700
--- ../badproject/.settings/org.eclipse.core.resources.prefs 2020-03-05 08:09:53.274173300 -0800
***************
*** 1,7 ****
eclipse.preferences.version=1
- encoding//opt/ajsc/etc/config=UTF-8
- encoding//src/main/java=UTF-8
- encoding//src/main/resources=UTF-8
- encoding//src/test/java=UTF-8
- encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
--- 1,2 ----
I have no idea whether these are significant differences.
Note that I posted the same question, with slightly different analysis details, at https://stackoverflow.com/questions/60550130/one-existing-java-maven-project-suddenly-not-generating-classpath-file-in-eclip .
[Updated on: Thu, 05 March 2020 17:50] Report message to a moderator
|
|
| |
Re: Eclipse can't find the test class files for one particular project [message #1822414 is a reply to message #1822412] |
Thu, 05 March 2020 19:06 |
David M. Karr Messages: 802 Registered: July 2009 |
Senior Member |
|
|
Thanks for replying. I'm starting to tear my hair out.
I'm using a single Eclipse installation of 2019-12, and one workspace.
I would paste a snapshot of the project settings showing the configuration of src/test/java, but I'm not sure how to paste images in this forum, but for "src/test/java", the "Contains test sources" flag is "Yes", and the output folder is the "target/test-classes" folder, which is exactly where the class file resides (in the correct package folder mapping).
The "Show Command Line" thing does provide a clue, but it's only consistent with everything else I've seen so far. When I do this for the project that is working, I get a very long command line, mostly consisting of the classpath. When I do this for the project that is NOT working, the command line doesn't even HAVE a "-classpath" parameter, and is very short. Otherwise, all the other contents of the two strings are identical. So, somehow, it thinks this project doesn't have anything to put into a classpath. Perplexing.
|
|
|
Re: Eclipse can't find the test class files for one particular project [message #1822416 is a reply to message #1822414] |
Thu, 05 March 2020 19:19 |
David M. Karr Messages: 802 Registered: July 2009 |
Senior Member |
|
|
I just found another difference, but I don't understand it, or even whether it would make a difference.
I tried editing both run configurations, the working one and the not working one, and adding "-Xdiag -XshowSettings".
When I compared the results, I found that both showed a "java.class.path" value that included all the expected directories, being "target\test-classes" and "target\classes", even the one that is NOT working. However, note the very subtle difference:
Working:
java.class.path = C:\Users\<myuid>\git\futurebillestimatorms\target\test-classes
C:\Users\<myuid>\git\futurebillestimatorms\target\classes
NOT working:
java.class.path = "C:\Users\<myuid>\git\checkoutms\target\test-classes
C:\Users\<myuid>\git\checkoutms\target\classes
Note the one character difference, the double quote at the beginning of the value in the NOT working sample. There is a matching double quote at the end of the long list of classpath entries. The one that is working does not have those double quotes.
|
|
| | | |
Goto Forum:
Current Time: Fri Apr 26 23:25:16 GMT 2024
Powered by FUDForum. Page generated in 0.03834 seconds
|