Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 680
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 #1822412 is a reply to message #1822404] Thu, 05 March 2020 18:44 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
As you mention groovy: is all this using the same Eclipse installation? Or do you have one installation with groovy support, and another without?

Next, when the problem affects only tests: please verify that all test source folders are properly marked as containing tests. Also, this source folder should have target/test-classes as its output.

Generally, when you have issues with any launches, open the run configuration and click "Show Command Line" to see, what exactly will be launched.
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 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 680
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 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 680
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.
Re: Eclipse can't find the test class files for one particular project [message #1822418 is a reply to message #1822416] Thu, 05 March 2020 19:43 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
The latest find very much sounds like https://bugs.eclipse.org/bugs/show_bug.cgi?id=558495

Please try a 2020-03 release candidate: go to https://www.eclipse.org/downloads/packages/ and select "Developer Builds". Today you'll find 2020-03 M3, tomorrow it'll be 2020-03 RC1.

Note that you may have to test without groovy support, as I don't know whether they have picked up the fix already (groovy ships a patched jdt.core plug-in).
Re: Eclipse can't find the test class files for one particular project [message #1822428 is a reply to message #1822418] Thu, 05 March 2020 21:32 Go to previous messageGo to next message
David M. Karr is currently offline David M. KarrFriend
Messages: 680
Registered: July 2009
Senior Member
Is the theory that we must have added one or more additional artifacts to the classpath, causing the length to go over a threshold which resulted in the quotes being added? I'm trying to understand why this would have just started happening.
Re: Eclipse can't find the test class files for one particular project [message #1822429 is a reply to message #1822428] Thu, 05 March 2020 21:44 Go to previous message
David M. Karr is currently offline David M. KarrFriend
Messages: 680
Registered: July 2009
Senior Member
Ok, going through all of that, the least impact hack at this point is clicking the "Use temporary jar" checkbox. I can live with that until 2020-13.
Previous Topic:Executing TesTNG issues. Need help
Next Topic:Photon and JD-Eclipse
Goto Forum:
  


Current Time: Sun Oct 25 03:25:10 GMT 2020

Powered by FUDForum. Page generated in 0.07645 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top