I have a maven 3 project in eclipse who's structure is as follows. The app project serves as the parent project to all the other apps. I have included the pom.xml from the app project (first pom), and the pom.xml from the app-web project. (second pom)
app
app-ear
app-ejg
app-web
The problem I'm having is that I can see the dependencies from the parent in the effective pom of the app-web/pom.xml but my java classes in the app-web project cannot import from these dependencies. I get "The import com.fasterxml cannot be resolved". I have this problem for the app-ejb project as well. I don't think this is just an "eclipse error" either. If I try to mvn clean install from the app project I get compilation errors complaining about the same thing.
By the way the only change I've made is moving the dependencies up out of the pom.xml of the children and into the parent. I wanted to centralize things as much as possible and keep my project config as DRY as possible. Before moving the dependencies up the hierarchy things worked fine. I am using Eclipse Juno for Java EE developers with m2e, m2e-wtp, and WTP patches installed.
app/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>
app-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>
Right-click on the project and choose Properties, and then Maven. Uncheck the box labeled "Resolve dependencies from Workspace projects" Hit Apply, and then OK. Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies)
Just go to Project Tab on Eclipse and Select Clean. Then Eclipse will automatically remove the Maven Dependencies and re-build your project. By then, the error may be gone.
Now child POM need to refer the parent POM using parent tag and specifying groupId/artifactId/version attributes. This pom file will inherit all properties and dependencies from parent POM and additionally can include extra sub-project specific dependencies as well.
After moving the jackson-annotations
and jackson-core
dependencies to the parent POM you still need to reference it in the app-web
module by specifying (minimally) the groupId
and artifactId
. Maven documentation explains this usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With