I'm using maven-war-plugin to generate a WAR file.
In the dependency hierarchy, I can see many transitive dependencies, which are extract in the lib folder.
After many research, I saw that the easiest way to exclude them from the war lib folder is to declare them as 'provided' in my dependencies.
However, I have a lot of dependencies to exclude, and I have to do this in many WAR pom file.
My question is :
Is there a way to group all these dependencies in a 'pom' packaging, and use this new artifact in my WAR pom file ?
If I understand your needs...
try this--> http://maven.apache.org/plugins/maven-war-plugin/examples/including-excluding-files-from-war.html
when you build the war you can exclude all dependencies you want in this way:
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!--
Exclude JCL and LOG4J since all logging should go through SLF4J.
Note that we're excluding log4j-<version>.jar but keeping
log4j-over-slf4j-<version>.jar
-->
<packagingExcludes>
WEB-INF/lib/commons-logging-*.jar,
%regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]
</packagingExcludes>
</configuration>
</plugin>
</plugins>
Related
I have a multi-module maven project. I use maven build helper plugin to automatically add generated sources to the classpath.
I am able to use the generated sources of module-X in module-X, however, when I add module-X as a dependency to module-Y, the generated sources of module-X are not visible because they are not included in the X.jar file.
Is there a way to include the generated sources in the jar file or force maven to generate sources of dependencies?
You can explicitly specify that the generated classes should be part of the output jar file:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<includes>
<include>generatedClassesFolderPath</include>
</includes>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
Replace the generatedClassesFolderPath with the relative path of the folder where the generated classes are.
More info:
How to include/exclude content from jar artifact
I had the same question and I solve it as follows:
Add an application class under package such as src/main/java/com..... in your module-X and add a #SpringBootApplication annotation. In addition to this, the application class can be no content.
Make sure module-X in module-Y dependencies and restart `module-Y.
I am writing a project for acceptance testing and for various reasons this is dependent on another project which is packaged as a WAR. I have managed to unpack the WAR using the maven-dependency-plugin, but I cannot get my project to include the unpacked WEB-INF/lib/*.jar and WEB-INF/classes/* to be included on the classpath so the build fails. Is there a way to include these files into the classpath, or is there a better way of depending on a WAR?
Many thanks.
There's another option since maven-war-plugin 2.1-alpha-2. In your WAR project:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
This creates a classes artifact which you can use in the acceptance tests project with:
<dependency>
<groupId>your-group-id</groupId>
<artifactId>your-artifact-id</artifactId>
<version>your-version</version>
<classifier>classes</classifier>
</dependency>
Indeed, by design, Maven doesn't resolve transitive dependencies of a war declared as dependency of a project. There is actually an issue about that, MNG-1991, but it won't be solved in Maven 2.x and I'm not sure that I don't know if overlays allow to workaround this issue. My understanding of the suggested solution is to duplicate the dependencies, for example in a project of type pom.
(EDIT: After some more digging, I found something interesting in this thread that I'm quoting below:
I have been helping out with the development of the AppFuse project over
the last month where we make heavy use of the war overlay feature in the
Maven war plugin. It is a really nifty feature!
To get max power with war overlays I have developed the Warpath plugin
that allows projects to use war artifacts as fully fledged dependencies.
In brief:
1) The contents of the /WEB-INF/classes directory in the war dependency
artifacts can be included in the project's classpath for normal compile,
etc tasks.
2) Transitive dependencies from the war dependency artifacts become
available for use by other plugins, e.g. compile and ear - so no more
having to include all the dependencies when creating skinny wars!
The plugin has now been actively used in the AppFuse project for the
last few months, and I feel it is at a point where it is both usable and
stable.
Would the war plugin team be interested in including the warpath
functionality inside the war plugin? It would seem to be the most
natural place to host it.
So, I don't have any experience with it, but the maven warpath plugin actually looks nice and simple and is available in the central repo. To use it,include the following plugin configuration element in your pom.xml file:
[...]
<build>
<plugins>
<plugin>
<groupId>org.appfuse</groupId>
<artifactId>maven-warpath-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>add-classes</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
And add the war dependencies you want included in the classpath as warpath type dependencies:
[...]
<dependencies>
<dependency>
<groupId>org.appfuse</groupId>
<artifactId>appfuse-web</artifactId>
<version>2.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.appfuse</groupId>
<artifactId>appfuse-web</artifactId>
<version>2.0</version>
<type>warpath</type>
</dependency>
</dependencies>
[...]
Both the war and warpath dependency types are needed: the war type is used by the Maven war plugin to do the war overlay, the warpath type is used by the Warpath plugin to determine the correct list of artifacts for inclusion in the project classpath.
I'd give it a try.)
Use overlays. First, your test project need to have also packaging war.
Declare dependency of war project you want to test:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>your-project-arftifactId</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>test</scope>
</dependency>
then configure maven-war-plugin overlay:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webresources</directory>
<filtering>true</filtering>
</resource>
</webResources>
<overlays>
<overlay/>
<overlay>
<groupId>your.group</groupId>
<artifactId>your-project-artifactId</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
In the above example in test project I overwrite webresources configuration files (like conxtext etc.).
EDIT: This solution wasn't tested with Maven 3.
Good point, Justin. That got me actually solving my problem, namely: including a war into an assembly AND including all its transitive dependencies.
I could not duplicate the war-dependency as 'jar' as you suggested since the assembly plugin would not find a jar referenced by that groupId/artefactId, but
duplicating the war-dependency as type pom
works!
The war and its transitive dependencies are not included in the assembly.
To exclude the (now also appearing) pom file I had to add an exclude element like this:
<excludes>
<exclude>*:pom</exclude>
</excludes>
into my assembly.xml file.
I think this could also be a workaround for the original question of this thread.
If you list the dependency on the war project as a jar dependency it seems to pickup the required jars/resources. I'm using Maven 2.2 + m2eclipse.
I am using maven-rar-plugin and following is my configuration in POM file. includeDependencies is set to false. But all the dependent and dependent project's sub dependencies are all packaged into rar.
<plugin>
<artifactId>maven-rar-plugin</artifactId>
<version>2.4</version>
<configuration>
<raXmlFile>src/main/resources/META-INF/ra.xml</raXmlFile>
<includeDependencies>false</includeDependencies>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
</configuration>
</plugin>
I cannot use exclusion in dependencies as it would lead to compilatin errors.
<dependencies>
<dependency>
<groupId>com.fi.ps</groupId>
<artifactId>frm-fl</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
Is this a bug in the Maven plugin or is there a different way of configuring for rar packaging?
There is no includeDependencies parameter for the maven-rar-plugin and, from reading the source code, it isn't currently possible to exclude dependencies of the project. A possible work-around would be to declare the dependencies to exclude with the provided scope: they will be present during compilation but excluded when building the RAR file.
But why do you want to exclude dependencies in the first place? The maven-rar-plugin is used to build a Resource Adapter Archive file for the Java 2 Connector Architecture. Dependencies are supposed to be included, otherwise it won't work. Beware that, as stated in the FAQ, this plugin does not create compressed file like WinRar.
I'd like to use maven to include jar/war's libraries in my EAR project's lib folder.
Currently my ear looks like this :
lib
lib/<entities>.jar
lib/<ejb-client>.jar
<ejb-impl>.jar
<web-app-project>.war
Each jar/war have maven dependencies which are declared with scope provided.
Why scope provided? I'm using Glassfish 3.1.2 and having issue when I put libraries in /WEB-INF/lib. I fixed the issue by copying libs in ear/lib instead (see Spring / Glassfish 3.1.2 stale files).
What I want to do is to tell to maven he has to put thoses librairies in the ear's lib folder.
I tried to put all projects in the ear's maven dependencies but it's not working actually.
Could someone help me ?
Thanks,
Smoky
This is similar to Including A Third Party Library In application.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9</version>
<configuration>
[...]
<modules>
<jarModule>
<groupId>artifactGroupId</groupId>
<artifactId>artifactId</artifactId>
<bundleFileName>entities.jar</bundleFileName>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
I have some problems with some of my dependencies, declared in pom file dependencyManagement section: dependency is not included to MANIFEST.MF file. This dependency is used in web project in section. However, there is no related declaration about this dependency in MANIFEST and deployed app fails with exception. How to guarantee adding this dependency to MANIFEST file?
Thanks.
Maven does not put dependencies in the MANIFEST.MF file. If you have web project which means having a war file all dependencies will be packaged into the war file. Furthermore it's not needed to put the dependencies into the MANIFEST.MF file.
If you really like having the dependencies into your MANIFEST.MF file you have to configure the maven-war-plugin like this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
If you define a dependency only in dependencyManagement it will not be a real dependency. This is only a definition of the version to be used.
To make a dependency really be used to your project you must define the dependency in dependencies.