Maven uses old version of pom.xml - java

I've just started using Maven for one of my Java projects. It took me a few edits to get Maven to accept the pom.xml but I finally got it working. However, to my surprise it still uses an older version of the pom.xml!
The thing is that I can't even find it in the project's directory. I used Notepad++ for all my edits. When I open pom.xml it's the correct (latest) version. When I look into the JAR with jd-gui, it's the previous version that Maven was complaining about. This makes no sense. I tried deleting everything in the target directory and running 'maven clean' to no avail.
Here's the current 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>solint</artifactId>
<version>1.0</version>
<name>SolInt</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<!-- Prepares Agent JAR before test execution -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifestEntries>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
<Premain-Class>my.project.Agent</Premain-Class>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
</dependencies>
</project>
The only way I've been able to force Maven to use the latest version of pom.xml is to copy the whole project to a different directory. I want to understand this mystery. Any ideas?
EDIT 1:
Here's how the JAR looks after mvn package. Note that this one has the correct pom.xml because I changed the root directory.

If you deleted everything, then the next copy of the jar file built should contain the at-that-time current pom.xml file.
However, if you are actually loading the JAR file out of the ~/.m2/repo cache, then you need to do a maven install to update the cache, and then the projects that use that JAR will get the last installed version.

I suggest you to take a look here to find out where your pom.xml should be located inside your folder structure.
Another important thing is to understand how your folders structure should be; for this, please take a look here.
Basically, you should have something like this:
+ Project Folder
|
+ src
|
+ main
|
+ java
|
+ {here goes your package, classes, etc.}
|
i.e.
|
+ com
|
+ sample
|
+ HelloWorld.java
|
+ pom.xml
Also it's important, that you can have poms inheriting from other Poms and you also could have aggregation to group several poms on a project, check this to get more info.
Also, I will suggest you to use a IDE instead just Notepad++, such IntelliJ or Eclipse; both have Maven Integration.

Related

azure-functions-maven-plugin:1.12.0 MalformedJsonException

I have a java azure function that was running package azure-functions-maven-plugin version 1.3, trying to upgrade the package to anything 1.4 or greater when I try to package the function I get the following error:
Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.12.0:package (package-functions) on project azure-functions-archetype: com.google.gson.stream.MalformedJsonException: Expected name at line 9 column 4 path $.extensions.http
My 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-archetype</artifactId>
<version>1.38</version>
<packaging>jar</packaging>
<dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
</dependency>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>1.12.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<configuration>
<resourceGroup>java-functions-group</resourceGroup>
<appName>${functionAppName}</appName>
<region>${functionAppRegion}</region>
<appSettings>
<property>
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>~3</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
```
I m unable to find a solution online on what is causing this error, hoping someone out there has an idea
Failed to execute goal com.microsoft.azure:azure-functions-maven-plugin:1.12.0:package (package-functions) on project azure-functions-archetype: com.google.gson.stream.MalformedJsonException:
It seems to be the issue in pom.xml code like either the tags are misspelled or the azure functions maven plugin code is missing or written wrong.
There is a similar issue here resolved by specifying the runtime and correcting the misspelt tags/code.
Also, Please make changes in your pom.xml file by comparing with my pom.xml as I see in the given pom.xml is missing the azure.functions.maven.plugin.version, runtime OS property etc. (https://i.imgur.com/uVkrUfU.png, https://i.imgur.com/ccu4BrW.png).
Reference: pom.xml code
I tried to run the Azure Functions Project (Java Stack) in VS Code and it come up with many issues regarding to loading the dependencies, Java Compiler Packages etc. and finally running the function successfully by following the below steps:
Maven version 3.8.4
Azure Functions Maven Plugin 1.15
Process 1:
Created the Azure Java Functions Project through VS Code and run the function successfully:
Process 2:
Created azure functions project using maven-archetype-quickstart template and is working good.
Run this command in your VS Code terminal:
mvn archetype:generate -DgroupId=com.microsoft.azure -DartifactId=azure-functions-archetype -DinteractiveMode=false
Since archetypes are templates and they intend to reflect current best practices, they can evolve in time, thus they have their own versions. Maven will ask you which version of the archetype you want to use. By default, maven chooses latest version for you. so if you agree to use the latest version of an archetype, just press Enter at this step;
Every maven project (and module) has its groupId, artifactId and version. Maven will then ask these to you in three steps. groupId: This is generally unique amongst an organization or a project. artifactId: The artifactId is generally the name that the project is known by. version: This is the last piece of the naming puzzle.(read more)
Finally, maven will ask you the package structure for your code. A best practice is to create your folder structure that reflects the groupId, thus Maven sets this as default but you are free to change this.
After entering these information, Maven will show you all the information you entered and ask you to verify project creation. If you press Y and then enter, voila your project is created with the artifact and settings you chose.
You can also read maven-archetype-plugin's usage site.
To Update the pom.xml versions, please run the commands (in your VS Code Project terminal) available in this Maven official site.

Maven: Sharing resources between projects

I am currently switching from ant to maven for a larger library consisting of a couple of projects. I am pretty new to Maven.
Due to the fact, that multiple libraries require the same external files as input for testing, I decided to create an individual project containing the resources (Project1), as explained here. Project1 only contains the test resources, nothing else, except an class project1.java with an empty main method. The resource files are ASCII text and binary files with arbitrary file extensions. Now, I want to use these files in testing of other projects, e.g. Project2. I tried to illustrate my structure:
Root
|-Project1: Resources
| |-src
| | |-main
| |-test
| |-resources
| |-file1.txt
| |-file2.dat
| |-...
|-Project2: Consumer
| |-src
| | |-main
| |-test
| |...
| |-test1.java (requires file1.txt)
| |-test2.java (requires file2.dat)
| |-...
I added Project1 as a dependency in the POM of Project2. Both projects are built with Clean and Build from Netbeans 11, so I guess mvn clean, build & install.
I do test for the existance of the relevant file in Project1 with Project1.class.getClassLoader().getResource([FILE]) and all files seem to be at the correct location. However, if I use Project1.class.getClassLoader().getResource([FILE]) from within Project2, e.g. test1.java the respective FILE is not found.
System.out.println("1:" + Project1.class.getClassLoader().getResource(""));
System.out.println("2:" + Project1.class.getClassLoader().getResource("file1.txt"));
from within test1.java in Project2 gives:
1: file:[PATHTOPROJECT]/Project2/target/test-classes/
2: null
So I tried following the apporach in this description. My problem with the explanation is, that I do not have a plugin to perform the executions for maven-shared-archive-resources as described in the consumer-part. Thus, I do not know where to put them. In the example the executions are carried out inside <groupId>org.codehaus.mojo</groupId> with <artifactId>sql-maven-plugin</artifactId>.
I also had a look at this thread, but I get an Ant BuildException.
Could somebody be so kind and explain a maven novice, how I can share resources between different projects? Is there even another, simpler way?
POM.xml of Project2
I tried to strip the POM.xml down to a MWE.
<?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>
<!-- TOOL INFO -->
<groupId>org.test</groupId>
<artifactId>project2</artifactId>
<version>0.0.0.1</version>
<packaging>jar</packaging>
<!-- PROPERTIES -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- System -->
<java.version>1.8</java.version>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<junit.platform.version>1.0.0</junit.platform.version>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<maven.plugin.compiler.version>3.8.1</maven.plugin.compiler.version>
<maven.plugin.enforcer.version>3.0.0-M2</maven.plugin.enforcer.version>
<maven.plugin.release.version>2.5.3</maven.plugin.release.version>
<maven.plugin.resources.remote.version>1.6.0</maven.plugin.resources.remote.version>
<maven.plugin.surefire.version>3.0.0-M3</maven.plugin.surefire.version>
<!-- Own -->
<project1.version>0.0.0.1</project1.version>
</properties>
<!-- DEPENDENCIES -->
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>project1</artifactId>
<version>${project1.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- BUILD -->
<build>
<!-- PLUGINS -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.plugin.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.plugin.enforcer.version}</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<requireJavaVersion>
<version>${java.version}</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.plugin.release.version}</version>
<configuration>
<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version>
</plugin>
</plugins>
</build>
</project>
Change the location of the resources in project 1. Note, moved from test dir to main.
|-Project1: Resources
| |-src
| | |-main
| |-resources
| |-file1.txt
| |-file2.dat
| |-...
Then, in project 2's POM, add project 1 as a test dependency:
<dependency>
<groupId>org.test</groupId>
<artifactId>project1</artifactId>
<version>${project1.version}</version>
<scope>test</scope>
</dependency>
Instead of sharing resources, create another project called "onlyresources" or something like this and inside the project keep only those *.txt, *.dat files. Other projects will have the dependency on the above defined project called "onlyresources". In case of multi module maven project, ensure to add the dependency to other projects. This project I mean "onlyresources" should be the first project which should be built first.

maven war plugin does not forget about old files and dependencies and creates a war that contains removed files and dependencies

Hello I'm having a weird problem about war creation.
I use maven-war-plugin (tried with 3.1.0, 3.2.0, and 2.6). When I run war:war (or mvn clean package, or similars) the war is created but I noticed that it is like it always packages all the files and dependencies it encountered in the history of the project. I noticed this because the war file is always getting bigger and by opening it I see there are a lot of dependencies that I declared on the pom but now they are removed, and most importantly there are classes I deleted from the project! I even tried to start a new project and the result does not change.
I guess I'm using this badly... Is there something I should do to let him "forget" about the history and force it to consider the project "as it is" when creating a war?
Thanks for the help!
PS:
I always clean and compile before running war:war;
I work with IntelliJ IDEA Community 2017.3
using jdk 1.7 because of technical constraints.
Just for completeness, there is my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sduca-consumer-listener</groupId>
<artifactId>sduca-consumer-listener</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<webappDirectory>/sduca</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Using Spring 4 because of jdk 1.7 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.18.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</project>
EDIT1: I tried to change versions of maven-war-plugin, maven-compiler-plugin, and Maven itself, but nothing changes.
EDIT2: I tried changing the output directory, no changes. I tried to change version of the dependencies and as "expected" now the war includes both versions, becoming bigger and bigger...
EDIT3: I reinstalled IntelliJ IDEA, upgrading to the latest version. Nothing changes, it has only reset the content of the package, but it still "keep track" of the content and dependencies and still includes removed stuff on the package when creating a new one.
EDIT4: I've started using mvn clean compile war:war instead of mvn clean package and at first things started working, but then the problem of the existing old files returned. However, I find out that if I manually remove the exceding resources and *.class from the war it looks it works (at least it's deployed).
It's just a trick worked for me many times,
Backup your dependencies from pom.xml and delete it.
Do a clean build, it will show errors in all Java classes. Also delete the previous war.
Now, replace those backed up dependencies and clean build the webapp again. All errors will be disappeared and war file will be as expected.

How to place folder/jar in Maven META-INF root

I am working on a implementation that requires UnlimitedJCEPolicyJDK8 for SAP hana cloud platform. The documentation tells me that i need to place it under the following structure:
WAR file:
META-inf
- ext_security
- jre8
The problem is when i include the jars it goes to WEB-INF/classes and thats not where the server is looking. As seen in the picture.
Technical details:
tomcat 8: v3.2 runtime
JRE 1.8
Maven build: using webapp archatype
With facades to support servlets.
IDE: eclipse
Tried the following:
add files using eclipse web deployment assembly (for what ever the reason it does not seems to work with maven and yes i use .m2 and WTP plugin)
Adding files trough maven dependency and tried copy to output folder.
i open WAR file moved files manually to correct folder and re-zipped and verified that if its in correct folder the update to server is working fine.
i really hope you can help me.
kind regards,
UPDATE: as requested by khmarbaise the pom file. And i created web-inf folder by myself in the hope it would be placed in root.
<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>hcp</groupId>
<artifactId>edi.web</artifactId>
<packaging>war</packaging>
<version>0.0.2-SNAPSHOT</version>
<name>edi.web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- tried classpath but it did not seem to do annything
Below dependency is from local .m2 repository-->
<dependency>
<groupId>hcp</groupId>
<artifactId>jre8security</artifactId>
<version>1.0.0</version>
<optional>true</optional>
<!-- goes in manifest classpath, but not included in WEB-INF/lib -->
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Solution provided by pace:
create a source folder under the following name: src/main/webapp/META-INF
The maven-war-plugin's war goal has a configuration option webappDirectory. It defaults to src/main/webapp. Anything in there will be placed in the root of the war. So you could create a directory:
src/main/webapp/META-INF
and drop in whatever files you want there. I don't much about the web tools plugin so not sure what approach would work there.

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.

Categories