Maven dependency not found for org.bukkit:bukkit - java

The groudID, artifactId and version dependencies are not being found in Maven?
I followed this tutorial to set up a Minecraft plugin which uses Maven.
But I get the error
org.bukkit:bukkit:1.7.2-RO3 not found
and the text font is red where everything else in the pom file is white.
Here is the code in the pom file:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.chrismepham</groupId>
<artifactId>TestPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.3</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Why is the dependency not being found?
EDIT:
I changed the repository and dependency version as suggested but still have the error as shown in the picture:

The reason the text is red is because that dependency you've specified can't be found in either maven central, or the additional repository you've added.
Paste the repo link into a browser, and you'll find that the dependency is actually 1.8-R0.1-SNAPSHOT not 1.7.2-RO3 as the tutorial mentioned (maybe the tutorial is out of date, or that dependency has since been removed for some reason)
Change the dep to
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
If you haven't already set auto-import on intelliJ, you'll get a popup in the top right hand corner asking if you want to re-import. IntelliJ then reads your pom.xml file, works out what dependencies you need and then downloads them.
You should see org.bukkit.bukkit under external dependencies in the left hand "projects" window, along with some other libraries it depends on, such as guava and commons lang.

Bukkit as a Maven dependency suggests a different repository:
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
On inspection, it includes 1.7.2-R0.3.
(It also works over SSL, as https://repo.bukkit.org/content/groups/public/, which you should prefer.)

The dependency doesn't exist in the repo. If you follow the repository link, you see that the only version inside is 1.8-R0.1-SNAPSHOT. So you must change that version inside your pom.

Related

Is there a way to use multiple maven dependencies for one maven project in Eclipse?

I am developing a Bukkit plugin with the M2E plugin in Eclipse. I have a problem where the maven dependency (Bukkit 1.5.2 R1.0) is in two different locations depending on whether I am at school or not. At home the file tree is in my dropbox with the maven repo at C:/users/canon/.m2/repository/org/bukkit/bukkit-1.5.2-R1.0 but at school it is located at C:/users/nmeyer/.m2/repository/org/bukkit/bukkit-1.5.2-R1.0. I have been able to recreate the project with maven such that the maven repository is in the correct place on only one computer at a time, but not both at once. Is there a way that I can tell Maven to look in both these file locations for the maven repository so I do not have to keep identical versions of the same project configured for one or the other locations only?
Additional Note: whichever file path I create the maven project with will work and display correctly with the bukkit-1.5.2-R1.0 jar file tree correctly displayed under maven dependencies, but it will not work on a computer in the other location (home vs school).
Clarification: The Maven repository is defined in my pom.xml but i don't see where to find the maven repo path. I've attached my pom.xml because the format of it seems to be a little different than the posted possible answers took into account:
<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>
<groupId>com.nathanMeyer</groupId>
<artifactId>headInfo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bukkit-repo</id>
<url> http://repo.bukkit.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.5.2-R1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
For Maven, you don't need to hard-code paths. You can use:
${user.home}
For example,
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
...
</settings>
Review the maven settings reference for more info: https://maven.apache.org/settings.html
Your import, then, would look something like this:
<plugin>
<groupId>org.bukkit</groupId>
<artifactId>bukkit-1.5.2-R1.0</artifactId>
</plugin>
I figured out what the problem is, and it's so stupid that i didn't even think of it originally. Turns out that my school blocks bukkit.org as "games" and since school computer Eclipse hasn't had a chance to connect to that repository from the school computer since the repo http://repo.bukkit.org/content/groups/public/ was inaccessable.

Maven *.xml resorces not updated after build

I recently found that some changes that I make in files are not reflected in target war - it happens only when I don't make any changes to java code, so the compilation phase is omitted. Is there a better way to force compilation than meaningless code changes like renaming variables or is there a way to update *.xml content?
EDIT:Here is my 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>
<groupId>com.example</groupId>
<artifactId>hiring</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine</artifactId>
<version>7.0.0-Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>camunda-bpm-nexus</id>
<name>camunda-bpm-nexus</name>
<url>https://app.camunda.com/nexus/content/groups/public</url>
</repository>
</repositories>
</project>
All xml files are at src/main/resources
I'm using Eclipse Keppler Service Release 1 with Maven 3.2.1, Java 1.7.0_17
Make sure you have m2e/m2e-wtp installed
Make sure Eclipse applies the Maven project nature to the project - Right click project > Configure > Convert to Maven Project.
If you edit a file outside Eclipse, make sure Eclipse knows about the change -- you need to enable native hooks -- Preferences > General > Workspace > Refresh using native hooks or polling. Alternatively, you can select the file and hit F5 (refresh) to make sure Eclipse is aware of the change.
Hit publish if you're using WST/JST (server tools) and deploying to a server via Eclipse.
In my experience if you've done all this, it should publish the changes to your target war as expected. Though, you may need to restart the container if the XML files are used as part of the startup configuration.

Maven error when pom.xml is packaged an ejb, but goes away when packaged as jar

When I package my pom.xml as an EJB I get an error that I do not understand. This error shows up if I touch the package in any way, to include Ctrl+S and Maven update. The error goes away if I change the packaging back to jar.
Code:
<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>com.myorg.buildparent</groupId>
<artifactId>BuildParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.myorg.myEjbPackage</groupId>
<artifactId>MyEjbPackage</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ejb</packaging>
</project>
By changing
<packaging>ejb</packaging>
to
<packaging>jar</packaging>
The error will go away.
Error string for reference:
'Building workspace' has encountered a problem.
Errors occurred during the build.
Errors running builder 'Maven Project Builder' on project 'MyEjbPackage'.
org.codehaus.plexus.archiver.ArchiverException
Even though I can remove the error, I still feel like it should be packaged as an ejb. Does this make sense to anyone? Does my EJB package need to be packaged as a EJB in the pom? I should admit that my skills with Maven are around that of a novice/low intermediate.
Try adding this configuration in your POM. The EJB plugin (which is bound to the lifecycle by default when you select ejb packaging type) doesn't use the same version of the archiver that the jar/war/ear plugins do.
There is a JIRA issue for updating the dependency versions, however it has not been worked yet.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>${maven.ejb.plugin.version}</version>
<dependencies>
<!-- Use the same archiver as the other [j/w/e]-ar plugins -->
<!-- See http://jira.codehaus.org/browse/MEJB-52 -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
Update
MEJB-52 is fixed in maven-ejb-plugin version 2.4 and later. Consider updating the plugin version to the latest before adding this configuration.

Maven: javax.servlet specification deployed

I've a web application configured with Maven which uses a library, also configured with Maven and when I package geronimo-servlet_3.0_spec-1.0.jar is included in WEB-INF/lib and I don't understand why.
I check the library with mvn dependency:tree
$ mvn dependency:tree | grep geronimo
[INFO] +- org.apache.geronimo.specs:geronimo-servlet_3.0_spec:jar:1.0:provided
I check my web app:
$ mvn dependency:tree | grep geronimo
$
However when I run mvn:package the file gets included in WEB-INF/lib.
When I run mvn tomcat:run I can see:
INFO: validateJarFile(/home/stivlo/workspace/private/src/main/webapp/WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Why and how to avoid? Thank you.
UPDATE 1: as requested I add the 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.obliquid</groupId>
<artifactId>test-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>private webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<!-- For Jakarta ORO -->
<repository>
<id>mvnsearch</id>
<name>Maven Search</name>
<url>http://www.mvnsearch.org/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>private</finalName>
</build>
</project>
UPDATE 2: I followed the advice of Stephen C and modified the build section as follows:
<build>
<finalName>private</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war</artifactId>
<version>2.1</version>
<configuration>
<overlays>
<overlay>
<groupId>org.obliquid</groupId>
<artifactId>test-webapp</artifactId>
<excludes>
<exclude>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
However geronimo*.jar still gets included. I guess I've made a mistake in this configuration.
UPDATE 3: Stephen C. says that I should use
the groupId the artifactId of the WAR
file that contains the JAR file(s)
that you are trying to exclude.
I didn't know that WAR files could have a groupId and artifactId, in fact in my pom.xml I don't see any. My project builds a WAR file and has a groupId and an artifactId and those were the ones I tested above without success.
The dependency causing the problem is the following (is a JAR, not a WAR):
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
If I try to use the groupId and artifactId listed in this dependency I've the following error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-war-plugin:2.1.1:war
(default-war) on project test-webapp:
overlay [ id
org.obliquid.helpers:obliquid-helpers]
is not a dependency of the project. ->
[Help 1]
If I try to use the groupId and artifactId of the JAR included by org.obliquid.helpers:
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>)
I have the same error.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-war-plugin:2.1.1:war
(default-war) on project test-webapp:
overlay [ id
org.apache.geronimo.specs:geronimo-servlet_3.0_spec]
is not a dependency of the project. ->
[Help 1]
Reading the War plugin documentation, I found a section about creating skinny WARs. So I tried the following:
<build>
<finalName>private</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
Still without any success, geronimo-servlet_3.0_spec-1.0.jar is still there!
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project test-webapp: overlay [ id org.obliquid.helpers:obliquid-helpers] is not a dependency of the project. -> [Help 1]
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project test-webapp: overlay [ id org.apache.geronimo.specs:geronimo-servlet_3.0_spec] is not a dependency of the project. -> [Help 1]
UPDATE 4: I discovered that the target/private.war file is not a zip of target/private/ directory, but the exclusions are done at packaging time and not by deleting files in target/private/ -- This means, I've to re-test all the things I did before.
Suggestion of gouki: doesn't work, the JAR is still there also in the WAR file.
Suggestion of Stephen C., maybe mis-understood: actually I just noticed that the pom.xml is always invalid whatever groupId/artifactId I put of the three possibilities explained above. So they didn't work for me.
What I found in the documentation (packagingExcludes), works.
Now, if I had to choose one of he answers I would choose Stephen C., because he helped me pointing at the documentation of the WAR plugin (I was reading in the wrong places). However I'd accept an answer that doesn't work, at least in the way I tried (probably wrong). So I'm not going to accept any answer, and add a new answer myself with the final working configuration.
UPDATE 5: I post the relevant part of the pom.xml of obliquid-helpers, that mentions geronimo-servlet_3.0_spec. I've marked it optional and with scope provided, still it gets included by a web-app, unless I mark it as "packagingExclude" in the maven-war-plugin configuration.
<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>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<packaging>jar</packaging>
<name>obliquid-helpers</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
[...]
</repositories>
<dependencies>
[...]
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Clearly, something has a dependency on that JAR file. If it is not showing up in the dependency tree, perhaps it is due to a dependency of your webapp WAR file on another WAR file that has this dependency.
If that is the case, then you could get add an <excludes> to the <overlay> element of the build descriptor for the WAR file plugin; e.g.
...
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<overlays>
<overlay>
<groupId>xxx</groupId>
<artifactId>yyy</artifactId>
<excludes>
<exclude>WEB-INF/lib/whatever.jar</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
...
If you are using WAR file overlays, you should always include the clean target in the build. Otherwise you can get old dependencies hanging around in the WAR file. (IIRC, there is a Warning in the Maven output each time you build an overlaid WAR without cleaning!)
In fact, this could be the root cause of your problems. For instance, if previously you had the "geronimo" as an ordinary dependency and you haven't run mvn clean since then, the JAR file could still be hanging around.
Based from your pom.xml, the only dependency that might have dependency on geronimo servlet is
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
Can you try excluding the geronimo in this dependency?
<dependency>
<groupId>org.obliquid.helpers</groupId>
<artifactId>obliquid-helpers</artifactId>
<version>0.9-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
First I want to thank gouki and Stephen C. for helping me. However their proposed solution didn't work for me. I'm grateful to them, but I can't accept their answer, because it would be misleading since it didn't work for this problem. I've upvoted Stephen C. answer, because he pointed me to the right documentation, which was essential to solve the problem.
Reading the WAR plugin documentation, especially the war:war mojo section, I've found an example on how to create Skinny WARs, which did the trick. So here is below the working configuration, to be added to the build section:
<build>
<finalName>private</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/lib/geronimo-servlet_3.0_spec-1.0.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
The archive part is probably not really needed, but I will find out when I deploy the WAR. The part that does the trick is the packagingExcludes tag, that can contain a comma separated list of tokens to exclude from the WAR before packaging.

Question about maven

I read some useful posts here on SO about previous maven questions, I'm currently very interested in learning maven(cause I like it and because my boss requires me to). I'm currently reading [this][1] book and I'm working my way trough examples. Its a straightforward book but its has some errors inside(trivial ones), yet for a newbie like me can be hard to spot, once spotted it can be easily fixed. Is there any other book better to understand maven from top to bottom?
Second part of the question is relating an example in this book, maybe a simple explanations would resolve my doubts.
Here is the thing, I made a simple-weather project in java which retrieves the weather conditions from yahoo weather server, given the particular zip code it returns weather information.
Then I made an 'simple-webapp'(with maven as well as the one above I forgot to mention that), which is basicaly a web project which has some default servlet already there with maven and it does nothing.
And I have some parent-project I wanna merge those two projects into one, so I made a pom.xml which has 2 modules , 1 to retrieve info(java project) and other to display it on the web (web app).
I made everything work at the end, but here is the odd thing .. if I make webapp display any string "name" lets say then build it independently, it does exactly print that string. But when I put the webapp in the "parent-project" and change this string to "name1" and build it as sa partent-project sub module.. nothing changes ..
So I go back to the point, because simple-webapp is dependent on simple-weather I can't build it anymore on its own, so now if I wanna make some changes to the webapp.. modify the webapp outside the "parent-project" build it there then paste it back to the parent-project and then the changes will apply, why is that, why can't I directly change the servlet content/or add another one in the webapp as the part of the "parent-project"?
Thank you.. I know its a long and boring question, but I'm just trying to learn things and there is no better place to ask than here :D
EDIT - HERE ARE POM FILES FOR EACH PROJECT :
1. simple-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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2. simple-weather 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-weather</artifactId>
<packaging>jar</packaging>
<name>Multi Chapter Simple Weather API</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3. simple-webapp 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-webapp</artifactId>
<packaging>war</packaging>
<name>simple-webapp Maven Webapp</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-weather</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<finalName>simple-webapp</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I am not sure to completely understand your question. However, let's explain some principles in Maven.
So you have such a structure:
parent
+ simple-weather
+ simple-webapp
On a Maven point of view, we have 3 projects here:
parent, which is a pom project (i.e. its packaging attribute is set to pom)
simple-weather, which is a jar project and has parent as parent.
simple-webapp, which is a war project, has parent as parent and simple-weather as dependency.
The parent projects uses two concepts in Maven:
The inheritance, which say that all of his children (simple-weather and simple-webapp) will inherit all of his properties (this concept is almost the same thing as the extends in Java).
The aggregation, which is defined by the definition of <modules>. Aggregation means that every command that will be run on the project will also be run on each module.
What happen if I build (using mvn clean install) on the parent directory?
Maven will "compile" the parent project and then install the pom.xml in the local repository.
Maven will compile the simple-weather project, but as it has a parent, Maven will look the parent pom.xml file into the local repository. Once the JAR is created, it is installed in the local repository.
Maven will finally compile the simple-webapp project. Maven will do the same thing for the parent pom.xml, but also for the simple-weather project.
The situtation explained in the 3rd point is important: If you want to build the simple-webapp project, Maven will always try to find all of his dependencies - including simple-weather - from the local (or distant) repository.
That's why if you build only the simple-webapp without building and installing simple-weather, Maven will not find the latter project, or will find an older version.
So to summarize, when you work on multi-modules project with Maven, try to always run the build and install commands from the root (or parent) directory.
I hope that this explanation is clear enough and help you to understand what happen in your case. Do not hesitate to ask more information...

Categories