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>
Related
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
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.
I need to include custom file (/com/app/log4.properties) in a final JAR.
How can I add one file to my JAR when using jar-with-dependencies?
Now there are only class files in that JAR. I'm using:
mvn assembly:assembly
My pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.app.Start</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Thank you.
Put non-Java files that need to be in the final artifact in src/main/resources, in this case:
src/main/resources/com/app/log4j.properties
My maven project has several dependent jars, but when I create a jar of my project I would like to include a subset of those dependencies. Is there a way to do this? Currently, I am using the pom.xml below (from question How can I create an executable JAR with dependencies using Maven?), but it is packaging every dependency with my project.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Try:
<dependencySets>
<dependencySet>
....
<excludes>
<exclude>commons-lang:commons-lang</exclude>
<exclude>log4j:log4j</exclude>
</excludes>
</dependencySet>
....
</dependencySets>
See Including and Excluding Artifacts for more details
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>