java Maven 构建失败:包不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38596946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:33:55  来源:igfitidea点击:

Maven build failure: package does not exist

javamaven

提问by SVN600

I have two maven modules, AppManager and myApp. These are in the same directory locally and are not available in the company's online repo as they are for testing purposes. In IntelliJ I have no problem using the fields and methods of AppManager and there are no error messages. I am exporting com.mycompany.appManager in my impl pom file for myApp. However, when I build outside of the IDE, i.e. mvn clean install, there is an error for the package com.mycompany.appManagerdoes not exist and then associated errors for unresolved symbols for usage of public fields defined in appManager. How can I resolve this problem? I've tried the exporting and adding a dependency, but these two solutions do not work.

我有两个 Maven 模块,AppManager 和 myApp。它们在本地位于同一目录中,并且在公司的在线存储库中不可用,因为它们用于测试目的。在 IntelliJ 中,我使用 AppManager 的字段和方法没有问题,并且没有错误消息。我在 myApp 的 impl pom 文件中导出 com.mycompany.appManager。但是,当我在 IDE 之外构建时,即mvn clean install,存在包com.mycompany.appManager不存在的错误,然后与未解析符号相关联的错误用于使用 appManager 中定义的公共字段。我该如何解决这个问题?我已经尝试导出并添加依赖项,但这两种解决方案都不起作用。

pom.xml:

pom.xml:

<moduleVersion>4.0.0</moduleVersion>
<parent>
    <groupId>com.myCompany</groupId>
    <artifactId>myApp</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<groupId>com.myCompany.myApp</groupId>
<artifactId>com.myCompany.myApp.impl</artifactId>
<packaging>bundle</packaging>
<name>My App Implementation</name>

<build>
    <plugins>
        <plugin>
             <groupId>org.apache.felix</groupId>
             <artifactId>maven-bundle-plugin</artifactId>
             <extensions>true</extensions>
             <configuration>
                 <instructions>
                     <Export-Package>
                          com.myCompany.appmanager
                     </Export-Package>
                     <Bundle-Activator>com.mycompany.myapp.impl.component</Bundle-Activator>
                 </instructions>
             </configuration>
         </plugin>
     </plugin>
 </build>

Compilation Error:

编译错误:

[ERROR] /root/Desktop/apps/myapp/impl/src/main/java/com/mycompany/myApp/impl/component.java:[11,49] package com.mycompany.appmanager does not exist
[ERROR] /root/Desktop/apps/myapp/impl/src/main/java/com/mycompany/myApp/impl/component.java:[64,49] cannot find symbol
    symbol: variable AppManagerModule
    location: class com/mycompany/myApp/impl/component

回答by JF Meier

I try to answer the question as far as I understand it:

我尝试就我的理解回答这个问题:

If you have two projects A and B and A depends on B, then you have to have to build B first. If you e.g. use mvn clean install, then B.jar will be put into your local repository. After that, you can build A against it (if you choose the correct version in the pom).

如果您有两个项目 A 和 B,并且 A 依赖于 B,那么您必须先构建 B。例如mvn clean install,如果您使用,那么 B.jar 将被放入您的本地存储库。之后,您可以针对它构建 A (如果您在 pom 中选择了正确的版本)。

回答by Blondysinger

For the sake of completeness, if you have two projects A and B and A depends on B, you also have to be sure that your code in B project exists in compiled jar. Obviously you have to write your packages in src/main/java (and not in src/test/java) if you want them visible.

为了完整起见,如果您有两个项目 A 和 B 并且 A 依赖于 B,您还必须确保您在 B 项目中的代码存在于已编译的 jar 中。显然,如果您希望它们可见,您必须在 src/main/java(而不是 src/test/java)中编写您的包。