Maven seems to put its pom.xml and pom.properties into the JAR at META-INF/maven/example.com/example.com.foo/pom.properties.
How can I get it to leave those files out?
The first thing is to take a look into the documentation for Maven archiver
This shows the possibilies which are usable:
<archive>
<addMavenDescriptor/>
<compress/>
<forced/>
<index/>
<manifest>
<addClasspath/>
<addDefaultImplementationEntries/>
<addDefaultSpecificationEntries/>
<addExtensions/>
<classpathLayoutType/>
<classpathMavenRepositoryLayout/>
<classpathPrefix/>
<customClasspathLayout/>
<mainClass/>
<packageName/>
<useUniqueVersions/>
</manifest>
<manifestEntries>
<key>value</key>
</manifestEntries>
<manifestFile/>
<manifestSections>
<manifestSection>
<name/>
<manifestEntries>
<key>value</key>
</manifestEntries>
<manifestSection/>
</manifestSections>
<pomPropertiesFile/>
</archive>
If you change the configuration to prevent using the default by this:
<project>
<url>http://some.url.org/</url>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
By using the above the defaults will not being part of your artifacts anymore. So from here you can start to customize the configuration based on your wishes.
Related
I've been trying to build javaagent (containing premain()) to .jar file using maven mvn package, and keep getting java.lang.NoClassDefFoundError exception related to external dependencies. For details, I added kafka-client dependecies and maven-jar-plugin to pom.xml like below
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
<Premain-Class>com.my.java.monitoring.Agent</Premain-Class>
<Can-Redefine-Classes>true</Can-Redefine-Classes>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
</manifestEntries>
</archive>
</configuration>
</plugin>
After reading How can I create an executable JAR with dependencies using Maven?, I tried using maven-assembly-plugin instead, like below
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Premain-Class>com.my.java.monitoring.Agent</Premain-Class>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- append to the packaging phase. -->
<goals>
<goal>single</goal>
<!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
but I get this error =>
Failed to find Premain-Class manifest attribute in target/my-java-agent.jar Error occurred during initialization of VM agent library failed to init: instrument
Can anyone who has experience building javaagent .jar file with dependencies, please help.
I need your help. I have to write a script adding versions of sub-projects to MANIFEST.MF file during build application by Maven.
I write some Mojo class that gets information I need (I named it GenerateVersionPropertyFile.class). Now I need know how to put this information to manifest file.
Here is my pom.xml:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.1</ejbVersion>
<generateClient>true</generateClient>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
<!--
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
</manifest>
-->
<manifestEntries>
<Built-By />
</manifestEntries>
<manifestSections>
<manifestSection>
<Name>appName</Name>
<manifestEntries>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
</manifestEntries>
</manifestSection>
<manifestSection>
<Name>exampleApp</Name>
<manifestEntries>
<Implementation-Title>exampleEntry</Implementation-Title>
<Implementation-Version>dupa2</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>maven.GenerateVersionPropertyFile</mainClass>
<arguments>
<argument>${project.basedir}\src</argument>
<argument>${project.build.directory}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>server-ejb-build-devel</id>
<activation>
<property>
<name>build-devel</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<archive>
<manifestSections>
<manifestSection>
<Name>app1</Name>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
<Implementation-Timestamp>${timestamp}</Implementation-Timestamp>
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Make sure, if you are adding custom properties in MANIFAST.MF file which build package is JAR/WAR.
if packaging JAR in your pom.xml file then use
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<mode>development</mode>
<url>http://testing/</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
OR if packaging WAR in your pom.xml file then use
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<mode>development</mode>
<url>http://testing/</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
Have to use the maven-jar-plugin on your pom.
Example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>${maven-ejb-plugin.version}</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
I have pom.xml like this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>package.mainClass</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
and I compile and package my project successful. but when I java -jar myProject.jar I get Error: Could not find or load main class package.mainClass!!
I think it happened because I wrote both mainClass and classpathPrefix in manifest! what is the way to set them with each other in pom.xml?
"Main-Class: first.PathGetter" instead of "Main-Class: package.mainClass" in pom.xml file, according to your MANIFEST.MF
This sounds so simple, so why an I struggling?
Is there a POM entry I can use to seal all the packages?
Or do I provide a manifest with value 'Sealed: true'?
Thanks
Jeff Porter
> Or do I provide a manifest with value 'Sealed: true'?
As explained in "Manifest Customization":
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifestEntries>
<Sealed>true</Sealed>
</manifestEntries>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
I'm using Maven to generate a war file. I'm trying to get it to generate a manifest file in the war. Right now it's not happening. I've included the following in my pom.xml, but I can't get it to output a manifest file with that information. Anyone have any ideas or pointers? There is no MANIFEST.mf being put into the war.
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
...
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
You should add this to your plugin config:
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>