简体   繁体   中英

Eclipse Mars not finding classes

I've a maven's multimodule project in Eclipse and I'm having a compilation problem when importing some classes. I first thought it was some problem with the Maven configuration because the not found classes are from the test package but then I found that other classes importing the same test class from the same module also fails. In code, my project looks like this:

library
|-model
|-resource
|-int-test
|-... some other modules that doesn't matter

The first classes I found with problems were this:

// this class belongs to the test package (src/test/java) from the model module
// In my Eclipse project it's red underlined with the error message:
// The import com.library.app.commontests.author.AuthorForTestsRepository cannot be resolved
import static com.library.app.commontests.author.AuthorForTestsRepository.*;
...

// This class belongs to the int-test module (test package also)
public class AuthorResourceIntTest {...}

Same case for this class

import static com.library.app.commontests.author.AuthorForTestsRepository.*;
...

// This class belongs to the resource module (test package)
public class AuthorResourceUTest {...}

Maven is configured to package the test classes so I can set it as a dependency in the other modules, this is the configuration:

model/pom.xml

<parent>
    <groupId>com.library</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>model</artifactId>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <!-- versionId setted in app/pom.xml in the pluginManagement section -->
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

resource/pom.xml

<parent>
    <groupId>com.library</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>resource</artifactId>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>com.library</groupId>
        <artifactId>model</artifactId>
        <!-- versionId setted in dependencyManagement section -->
    </dependency>
    <dependency>
        <groupId>com.library</groupId>
        <artifactId>model</artifactId>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>
</dependencies>

As I said, my first thought was to think in a bad configuration in my pom, but then I found the same error in a class from the same model package, this is the class:

import static com.library.app.commontests.author.AuthorForTestsRepository.*;
...

// This class belongs to the same model module (also from test package) 
// as AuthorForTestsRepository
public class AuthorRepositoryUTest {...}

In every case I have the same error in Eclipse. The AuthorForTestsRepository class exists (I swear) and I have the same error for other classes of my system (there are other *ForTestRepository with the corresponding *RepositoryUTest , *ResourceUTest and *ResourceIntTest ).

It's a bug in Eclipse? Where should I look for the solution. Thanks in advance for your answers.

Update #1

I tried 2 things from the command line to test if it's something with Eclipse or with Maven:

First

I ran mvn test -PintegrationTests-wildfly from the int-test module. integrationTests-wildfly is a profile to run the integration test in a Wildfly container (by default I skip the integration test because they take too long). The container starts without errors and when trying to run the test I have the following error message:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 32.114 sec <<< FAILURE! - in com.library.app.author.resource.AuthorResourceIntTest
com.library.app.author.resource.AuthorResourceIntTest  Time elapsed: 32.112 sec  <<< ERROR!
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive com.library.app.author.resource.AuthorResourceIntTest.createDeployment()
     at com.library.app.author.resource.AuthorResourceIntTest.createDeployment(AuthorResourceIntTest.java:43)

But I don't know what does it have to do with the class not found from the test package.

Second

Then I ran mvn clean install -PintegrationTests-wildfly from the main project ( app ). The model and resource modules test and compile correctly. In the int-test module the container starts correctly but I have a problem creating a table in the test database.

What I don't understand is that some tests where already working and I didn't change anything from the code they're supposed to test!

Conclusion

There're some code completions that aren't working in Eclipse, and that's the main problem I'm facing in this post, so I don't want to go into details of my projects that doesn't have anything to do with this problems.

Thanks again in advance for your answers.

Finally, I moved my code to another workspace and that solved my problem. Not completely but creating the project from scratch and moving just the files ( .java , .xml and so on). In 2 or 3 moments I had to update some modules with right click -> Maven -> Update Project . I realized of that option thanks to the Markers View ( Window -> Show View ).

Don't know if it has something to do but my previous project was in my Dropbox folder, maybe it has some conflict with Maven, but I'm not sure about this.

Thanks for all the comments and views to my question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM