简体   繁体   English

Eclipse火星找不到类

[英]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. 我在Eclipse中有一个Maven的多模块项目,并且在导入某些类时遇到编译问题。 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. 我首先认为Maven配置存在问题,因为未找到的类来自测试包,但是后来我发现从同一模块导入同一测试类的其他类也失败了。 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: Maven配置为打包测试类,因此我可以将其设置为其他模块中的依赖项,这是配置:

model/pom.xml 模型/ 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 资源/ 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: 就像我说的那样,我首先想到的是在pom中配置错误,但是随后我在同一model包的类中发现了相同的错误,这是该类:

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. 在每种情况下,我在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 ). AuthorForTestsRepository类存在(我发誓),并且我的系统的其他类也有相同的错误(还有其他*ForTestRepository和相应的*RepositoryUTest*ResourceUTest*ResourceIntTest )。

It's a bug in Eclipse? 这是Eclipse中的错误吗? Where should I look for the solution. 我应该在哪里寻找解决方案。 Thanks in advance for your answers. 预先感谢您的回答。

Update #1 更新#1

I tried 2 things from the command line to test if it's something with Eclipse or with Maven: 我从命令行尝试了两件事来测试它是否与Eclipse或Maven有关:

First 第一

I ran mvn test -PintegrationTests-wildfly from the int-test module. 我从int-test模块运行了mvn test -PintegrationTests-wildfly 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). integrationTests-wildfly是用于在Wildfly容器中运行集成测试的配置文件(默认情况下,我跳过了集成测试,因为它们花费的时间太长)。 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 ). 然后,我从主项目( app )运行了mvn clean install -PintegrationTests-wildfly The model and resource modules test and compile correctly. modelresource模块可以正确测试和编译。 In the int-test module the container starts correctly but I have a problem creating a table in the test database. int-test模块中,容器正确启动,但是在测试数据库中创建表时遇到问题。

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. 有一些代码补全在Eclipse中不起作用,这是我在这篇文章中面临的主要问题,所以我不想进入与该内容无关的项目细节。问题。

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). 并非完全如此,而是从头开始创建项目并仅移动文件( .java.xml等)。 In 2 or 3 moments I had to update some modules with right click -> Maven -> Update Project . 在2到3分钟内,我必须right click -> Maven -> Update Project来更新一些模块。 I realized of that option thanks to the Markers View ( Window -> Show View ). 感谢Markers View( 窗口-> 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. 不知道它是否有事可做,但是我以前的项目在我的Dropbox文件夹中,也许它与Maven有冲突,但是我不确定。

Thanks for all the comments and views to my question. 感谢您对我的问题的所有评论和看法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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