【发布时间】:2015-04-05 23:07:30
【问题描述】:
我有一个 Eclipse Maven 项目(父级),它托管三个 Maven 模块(它是子级)。只有子 MODULES 在“src/main/java/...”下有代码(即 PARENT 只是孩子的存根占位符)。 每个 MODULE 都是相互独立的......我只是这样设置它以减少混乱。 =:)
现在项目结构并不是这样开始的。最初它只是一个大 PARENT 而没有子 MODULES;一切正常。但后来我使用各种移动/重构在 Eclipse 中重新组织了一些东西(再次减少混乱),但一切都停止了。
问题:我的源代码现在找不到导入的类,所以我的依赖解析在某个地方出现了问题。这个问题不仅出现在 Eclipse 中,而且当我从 CLI 运行“mvn clean install”时也出现了问题。所以我怀疑我的移动/重构导致的一组 POM 文件有问题。
他们在这里(父母和一个孩子)。我错过了什么,还是有什么不正确的?也许我也应该检查一下Eclipse? 请注意,我在下面的 POM 文件中嵌入了几个小问题。 :)
PARENT pom.xml 文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>someName</name>
<packaging>pom</packaging>
<groupId>someParentGroupId</groupId>
<artifactId>someParentArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<jdk.version>1.7</jdk.version>
<example-core.version>0.9.3</example-core.version>
<!-- Intended to be used by some Child/Module.
I hope PARENT/CHILD POM inheritance works that way? -->
</properties>
<dependencies>
<!-- Dependencies are all in the Children/Modules -->
</dependencies>
<!-- ################### BUILD SETTINGS BEGIN ##################### -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin> <!-- Used to create an UBER/FAT-JAR. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>uber-${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>
</plugins>
</build>
<!-- ################### BUILD SETTINGS END ####################### -->
<modules>
<module>childModule1</module>
<module>childModule2</module>
<module>chileModule3</module>
</modules>
</project>
示例 CHILD pom.xml 文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>someParentGroupId</groupId>
<artifactId>someParentArtifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>someChildArtifactId</artifactId>
<!-- I noticed this missing in the Children/Module POM. Is that okay?
<name>
</name>
-->
<dependencies>
<dependency>
<groupId>org.example.somgGroupId</groupId>
<artifactId>example-core</artifactId>
<version>${example-core.version}</version>
</dependency>
</dependencies>
</project>
同样,问题似乎很简单。我无法解决导入问题(因此,我的类自然会出现与导入相关的错误)。
提前谢谢你!
【问题讨论】:
-
有人解决了这个问题吗?我现在也遇到了同样的问题
标签: java eclipse maven dependencies pom.xml