我有一個承載三個Maven模塊(它是子項)的Eclipse Maven項目(父項)。只有子模塊具有「src/main/java/...」下的代碼(即,PARENT只是兒童的存根位置持有者)。 每個MODULE都是相互獨立的...我只是設置它來減少混亂。 = :)無法解決具有子/模塊的MAVEN項目中的類依賴關係(在Eclipse和mnv CLI中可見)
現在項目結構並沒有以這種方式開始。最初它只是一個大的父母,沒有孩子的模塊;一切正常。但後來我重組了Eclipse中的東西(再次減少混亂),使用各種移動/重構,並且事物停止工作。
問題:我的源代碼現在找不到導入的類,所以我的依賴關係解析在某處變得有問題。而且這個問題不僅僅出現在Eclipse中,而且當我從CLI運行時,比如'mvn clean install'。所以我懷疑由移動/重構導致的POM文件集有些問題。
這裏他們是(父母和一個孩子)。我錯過了什麼,或者是不正確的?也許我應該檢查一下Eclipse的東西呢? 請注意,我在下面的POM文件中嵌入了一些小的在線問題。 :)
的家長 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>
例兒童的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>
同樣,這個問題似乎很簡單。我無法解析導入(所以,我的類自然會導入相關的錯誤)。
預先感謝您!
有沒有人解決過這個問題?我現在有同樣的問題 – viper 2016-09-18 09:40:20