Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure maven:assembly root path in the jar

Here is 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/xsd/maven-4.0.0.xsd">     <modelVersion>4.0.0</modelVersion>     <groupId>org.springframework.webflow</groupId>     <artifactId>spring-js-resources-thin</artifactId>     <version>2.2.1.RELEASE</version>     <name>Spring js lib</name>     <description>Spring javascript library without dojo</description>     <build>         <plugins>             <plugin>                 <artifactId>maven-assembly-plugin</artifactId>                 <version>2.2.1</version>                 <configuration>                     <descriptors>                         <descriptor>src/main/assembly/assembly.xml</descriptor>                     </descriptors>                 </configuration>             </plugin>         </plugins>     </build> </project> 

and here is the assembly.xml

<assembly>     <id>js-jar</id>     <formats>         <format>jar</format>     </formats>     <fileSets>         <fileSet>             <directory>src/main/resources/</directory>               <outputDirectory>/</outputDirectory>             <includes>                 <include>META-INF/**/*</include>             </includes>         </fileSet>     </fileSets> </assembly> 

The problem is, everytime I open the generated jar file(spring-js-resources-thin-2.2.1.RELEASE-js-jar.jar), the root folder is always named as artifactid-version(spring-js-resources-thin-2.2.1.RELEASE), then the META-INF.

I wonder there is anyway that I can build the jar file with the file name artifactid-version.jar, but WITHOUT the artifactid-version in the class path, just like every jar in the maven repository. I think there should be an option or a way to name the <outputDirectory>.

like image 730
Dreamer Avatar asked Jul 31 '12 20:07

Dreamer


People also ask

What is assembly descriptor in Maven?

This descriptor specifies the type of assembly archive to create, the contents of the assembly, and the ways in which dependencies or its modules are bundled with an assembly. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

What is fileset in Maven?

Defines the rules for matching and working with files in a given base directory. Element.

What is Assembly XML in Maven?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.

What is goal single in Maven?

This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).


1 Answers

You have to tell maven-assembly-plugin not to include the base directory within the archive which can be achieved by using the following:

<assembly>     <id>js-jar</id>     <formats>         <format>jar</format>     </formats>     <includeBaseDirectory>false</includeBaseDirectory>     <fileSets>         <fileSet>             <directory>src/main/resources/</directory>               <outputDirectory>.</outputDirectory>             <includes>                 <include>META-INF/**/*</include>             </includes>         </fileSet>     </fileSets> </assembly> 

And the suggestion about using maven-jar-plugin is very good, cause it looks a little bit that you are misusing the maven-assembly-plugin.

In the most recent versions of maven-assembly-plugin you should . as the root folder. If you use / you will get a warning.

like image 70
khmarbaise Avatar answered Sep 25 '22 18:09

khmarbaise