我在eclipse中有一个maven 3项目,其结构如下。该应用程序项目用作所有其他应用程序的父项目。我已经包含了来自 app 项目(第一个 pom)的 pom.xml,以及来自 app-web 项目的 pom.xml。(第二个pom)
app
app-ear
app-ejg
app-web
我遇到的问题是我可以在 app-web/pom.xml 的有效 pom 中看到来自父级的依赖项,但我在 app-web 项目中的 java 类无法从这些依赖项中导入。我得到“无法解析导入 com.fasterxml”。我的 app-ejb 项目也有这个问题。我也不认为这只是一个“日食错误”。如果我尝试从应用程序项目 mvn clean install 我得到编译错误抱怨同样的事情。
顺便说一句,我所做的唯一更改是将依赖项从子项的 pom.xml 中移到父项中。我想尽可能地集中事物并保持我的项目配置尽可能 DRY。在将依赖项向上移动之前,一切正常。我正在为安装了 m2e、m2e-wtp 和 WTP 补丁的 Java EE 开发人员使用 Eclipse Juno。
应用程序/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boardgamebuilder</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>app application</name>
<modules>
<module>app-ejb</module>
<module>app-web</module>
<module>app-ear</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java-version>1.6</java-version>
<org.slf4j-version>1.7.2</org.slf4j-version>
<com.fasterxml.jackson-version>2.1.1</com.fasterxml.jackson-version>
</properties>
<dependencyManagement>
<dependencies>
<!-- JSON handler -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${com.fasterxml.jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${com.fasterxml.jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${com.fasterxml.jackson-version}</version>
</dependency>
<!-- RESTful servlet -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.16</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.7</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<!-- Misc -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Define the version of the EJB jar so that we don't need to repeat
ourselves in every module -->
<dependency>
<groupId>com.boardgamebuilder</groupId>
<artifactId>app-ejb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<!-- Define the version of the WAR so that we don't need to repeat ourselves
in every module -->
<dependency>
<groupId>com.boardgamebuilder</groupId>
<artifactId>app-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation
processors -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
应用程序-web/pom.xml
http://maven.apache.org/maven-v4_0_0.xsd">4.0.0
<parent>
<artifactId>app</artifactId>
<groupId>com.boardgamebuilder</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>app-web</artifactId>
<packaging>war</packaging>
<name>app Web module</name>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>