I'm trying to build a jar with a valid Classpath in its MANIFEST.MF within Eclipse-IDE(Version Kepler Service Release 2; Maven 3.0.4) . The relevant configuration for the maven-jar-plugin in my pom.xml is
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>$${artifact.artifactId}-$${artifact.version}.$${artifact.extension}</customClasspathLayout>
</manifest>
</archive>
</configuration>
</plugin>
However this does not work as expected. For example I'm using the findbugs-maven-plugin and this plugin creates some Maven-Dependencies, namely the findbugs-maven-plugin-2.5.4.jar in my local repository. Heres the configuration for the findbugs-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<findbugsXmlOutput>true</findbugsXmlOutput>
<xmlOutput>true</xmlOutput>
<!-- Optional directory to put findbugs xdoc xml report -->
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
</configuration>
</plugin>
This is ok, but this dependency also makes it in the classpath-entry of my MANIFEST.MF which looks like this (excerpt):
lib/findbugs-maven-plugin-2.5.4.jar
The problem is, I have no clue how to disable this behaviour.
What I have tried so far:
Use the maven-dependency-plugin and define excludeGroupId and excludeArtifactId entries, which solved another problem, where the dependencies where all copied to lib-Folder in target-Directory.
Clearly I am missing something here.
Ok I managed to solve this problem.
The dependency came from an module base I was working on and which. It defined the dependency to the findbugs-maven-plugin-2.5.4.jar. This dependency was recognized by maven and placed in the classpath of my jar I wanted to build.
The solution to this problem can be found here http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html. It is possible to define excludes to transitive libraries. The dependency to base ind my module must therefore be written as:
<dependency>
<groupId>base</groupId>
<artifactId>base</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
</exclusion>
</exclusions>
</dependency>
Thanks to Tome who finally pointed me in the right direction!
Related
I am trying to build jar file of my app based on Maven. So I need to not include external jar library's to my build. I need that my app gives this external dependency in runtime from local maven repository or from local folder, those will contain these external libraries.
I configure my pom file for this dependency like this:
<profiles>
<profile>
<id>compile</id>
<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>some.artifact</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</profile>
and trying to run this jar with this prefix -Pcompile. I am using this answer.
But in the runtime, when I am trying to execute a method, that using this external library, I've got java.lang.NoClassDefFoundError with the name of my class from my external library.
So how I can make a build that will use external jar libraries from local storage?
So i found the solution to store jars outside the final maven build.
I was just need to add this jar to classpath with correct path. For this i add this to pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
<mainClass>your.mainClass</mainClass>
</manifest>
<manifestEntries>
<Class-Path>project-0.0.1-SNAPSHOT.lib/some.lib-1.1.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
Is there anyway to get at runtime the full artifact version / build number generated by the maven deploy plugin of my war at runtime?
It'd be ok if the maven process generated and packaged up a properties file with the value.
Keep in mind that my project generates unique (timestamped) artifact versions for every deploy.
Try this:
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries/>
<addDefaultSpecificationEntries/>
</manifest>
</archive>
</configuration>
That will add the maven details from the pom that build the war into the MANIFEST.MF file, which you can read at runtime.
Another way that I occasionally use is to use filtering of properties files, and drop the pom values into there - useful if you already have a property file/config loading mechanism in place.
Then, when it's deployed, which uses the same values from the pom, you're fine.
-Chris
You could package it up in your Manifest file using maven-jar-plugin which can be read through you application wherever you need.
Here is the basic configuration which would write the properties in pom.xml to your Manifest file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Vendor>Vendor Name</Implementation-Vendor>
<Implementation-Version>${revision}</Implementation-Version>
<Build-Timestamp>${timestamp}</Build-Timestamp>
<Build-Number>${release}_${revision}</Build-Number>
</manifestEntries>
</archive>
</configuration>
<executions>
<!-- your jar executions here -->
</executions>
</plugin>
where your property values would be defined in pom.xml as :
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<release>DevelopmentBuild</release>
<revision>Some Value</revision>
<properties>
EDIT:
This can be done using maven-war-plugin also.
You can get more information on WAR Manifest Customization Here.
I am new to maven.
I have created a maven project , in this i have twosession beans and i have added all dependencies in pom.xml. I want to conver this project to EARso that I can deploy it on jboss EAP 6.0 .
I have used
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
but it doen't provide the runtime dependencies.
How do i convert maven project to EAR file. How do get all dependencies including project dependencies at runtime.
I would suggest using maven-ear-plugin. The pom.xml would have the following item inside <build><plugins>..</plugins>..</build> listing:
(taken from the documentation)
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<!-- configuration elements go here -->
</configuration>
</plugin>
</plugins>
</build>
Please also refer to the documentation here: http://maven.apache.org/plugins/maven-ear-plugin/usage.html.
Maven handles all the dependencies that you list in the <dependencies>...</dependencies> section that follows the above block. For example:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
You can get the dependency details, like the above for log4j, from various maven repositories online. (http://search.maven.org/, http://mvnrepository.com/ etc.)
I've got the maven-enunciate-plugin integrated so that it generates documentation during the build and outputs it to the docs directory under the target directory. As I'm new to Maven I would like to know what would be the ideal way to configure my build so that it packages the docs directory into the WAR artifact of my build. Currently it is left outside of the WAR.
Thanks,
Mike
Please take a look at this and this
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</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>
<packagingIncludes>
**/docs
</packagingIncludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Is there a way to pack the dependencies of a maven ejb project in with the final jar?
I typically use a separate ear project and include the ejb as a dependency - it will fill out the lib folder automatically this way. However, this seems a bit wasteful - to have a project just to build the ear.
Right now I have:
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- without this, the datetime stamp unique id's will be appended to classpath items -->
<!-- see: http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Snapshot -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
Do I need to set the packaging type to ear? Can I include transitive dependencies in a standalone ejb jar? If I set it to ear, how do I config the ear plugin?
Thanks in advance!
The Maven Shade Plugin can package dependencies in with the JAR. It will extract the classes/resources from all the project's dependencies on package them in with the final JAR.
This should be enough to package all your dependencies:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
There are disadvantages to doing this, however.
Multiple resources with the same name in different JARs can cause problems (e.g. /META-INF/services/...). You can use Shade's resource transformers, but it can get messy.
Not as easy to track what JARs are dependencies in your project once deployed (you'd have to refer back to the POM instead of just looking at the EAR).
Unless you have good reason not to, I'd recommend you stick with building an EAR.
I don't think there is a direct way to do this. Instead, what can be done is to create it as a module project with an ear and an ejb module. It isn't exactly what I wanted, but it works and is better than separate projects.