I am trying to create a tar.gz with the name my-project-2.0.tar.gz and inside that file there is a zip file with all my java classes called my-project.zip. The reason for this is due to some script files that look for this type of format.
I have set up the maven assembly plug in my pom file and the descriptor files.
This issue is that when I run my build the plug in and descriptors are ignored.
The goal in eclipse is clean package.
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<phase>package</phase>
<id>assemble</id>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/prep.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<phase>package</phase>
<id>bundle</id>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>my-project-2.0</finalName>
<descriptors>
<descriptor>src/assembly/bundle.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
This is the bundle descriptor:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bundle-id</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>target</directory>
<includes>
<include>my-project.zip</include>
</includes>
<outputDirectory></outputDirectory>
</fileSet>
<fileSet>
<directory>src/assembly</directory>
<includes>
<include>place.sh</include>
</includes>
<lineEnding>unix</lineEnding>
<fileMode>0755</fileMode>
<outputDirectory></outputDirectory>
</fileSet>
</fileSets>
</assembly>
This is the prep descriptor
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>prep-id</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>target/classes</directory>
<outputDirectory></outputDirectory>
</fileSet>
</fileSets>
</assembly>
Ive tried running clean assembly:assembly but I get a `No assembly descriptors found' error
Ive tried rewritting my plug in as:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>my-project-2.0</finalName>
<descriptors>
<descriptor>src/assembly/bundle.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<id>assemble</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
But I dont know how to name the inside zip as my-project.zip
When the zip file is created with prep.xml the name of the zip file should be ${project.artifactId}-${project.version}.zip.
So in your case my-project-${project.version}.zip.
Try to edit the bundle.xml the following way:
<fileSet>
<directory>target</directory>
<includes>
<include>my-project-${project.version}.zip</include>
</includes>
<outputDirectory></outputDirectory>
</fileSet>
The main reason why my build was ignoring my descriptors is because I had all my plugins wrapped around a <pluginManagement> </pluginManagement>.
This solved my issue
Related
I have a project which is using a maven assembly plugin to include a bunch of files into a tar. Now I want to include a few more files in that tar, but first I want to zip them up and actually include that zip file.
I tried doing something like this: maven-assembly plugin - how to create nested assemblies
So basically created 2 executions inside the maven assempbly plugin and have the first execution create the required zip file that the second execution can package into a tar.
But I get the error saying the zip file 'is not a file'.
What is wrong with what I am doing?
Is there a more efficient way to do this?
This is what I tried:
My POM:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>create-tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>tar.xml</descriptor>d
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
zip.xml
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip-id</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources/vertica_schema/schema_migrations</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
tar.xml
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly- plugin/assembly/1.1.2"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>tar-id</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>/*.zip</source>
<outputDirectory>/lib</outputDirectory>
<destName>schema_migrations.zip</destName>
</file>
</files>
The <source> tag does not support *: it is only possible to select a single file with it. Additionally, the zip file build by the first execution will be generated inside the target folder by default, so you should point to that directory.
By default, the zip file will be named ${project.build.finalName}-zip-id.zip. You can change this name by setting the finalName attribute in the plugin configuration. Note that, by default, the assembly id will be concatenated to the finalName. You can turn this off by switching the appendAssemblyId flag to false.
This is a working configuration:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
<finalName>myzip</finalName> <!-- Name of zip file -->
<appendAssemblyId>false</appendAssemblyId> <!-- Do not concatenate "zip-id" to the finalName" -->
</configuration>
</execution>
<execution>
<id>create-tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>tar.xml</descriptor>d
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
with the following tar.xml:
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly- plugin/assembly/1.1.2"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>tar-id</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>${project.basedir}/target/myzip.zip</source>
<outputDirectory>/lib</outputDirectory>
<destName>schema_migrations.zip</destName>
</file>
</files>
It is a good practice to keep everything that is generated by Maven under the target directory. This is the working folder of Maven and you should not worry about keeping intermediate files in there.
I have a project which has following structure.
Parnet
|
Module 1(create a jar)
|
Module 2(create a war)
After built this project I want to have
Parent
|
target
|
settings-include a property file which required to initialize
|
lib- include all dependency for module 1 and 2
|
run.sh-use to run
I have try with maven-assembly-plugin. But each time it is copying settings folder and run.sh only.
What is the correct way to archive my goal?
Edit:
My main pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>assembly-descriptor.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
and assembly-descriptor.xml
<formats>
<format>dir</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>settings</directory>
</fileSet>
<fileSet>
<includes>
<include>run*</include>
<include>start*</include>
<include>log4j.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/lib</outputDirectory>
</fileSet>
</fileSets>
I have next directory structure:
src/main/resources/export/v1/android/
src/main/resources/export/v1/ios/
src/main/resources/export/v2/android/
src/main/resources/export/v2/ios/
...
src/main/resources/export/vn/android/
src/main/resources/export/vn/ios/
And I need to obtain next result:
WEB-INF/export/v1/android.zip
WEB-INF/export/v1/ios.zip
WEB-INF/export/v2/android.zip
WEB-INF/export/v2/ios.zip
...
WEB-INF/export/vn/android.zip
WEB-INF/export/vn/ios.zip
Can I solve the problem with maven-assembly-plugin? If not, is there an another plugin that can cope with it or is it better to write custom class and call it with exec-maven-plugin?
Here's what I've figured out by tinkering with the plugin. I've been able to create one zip with some arbitrary files in it. Here's the plugin I've defined:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/resources/my-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>assembly-id</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
And heres my-assembly.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip-example</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/java/com/sandbox</directory>
</fileSet>
</fileSets>
</assembly>
I'm hoping there's an easier way to do this for your needs, but from this point you can create an assembly file for each zip you need to build and this will work for you.
I've ended up with writing java class and runnign it with exec-maven-plugin as below:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>Running custom java class</id>
<phase>compile</phase>
<goals><goal>java</goal></goals>
<inherited>false</inherited>
<configuration>
<mainClass>mycompany.CustomJavaClass</mainClass>
<classpathScope>compile</classpathScope>
<arguments>
<argument>
${project.basedir}/src/main/resources/export
</argument>
<argument>
${project.basedir}/target/art-1.0/WEB-INF/export
</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
I have a maven question.
I have a GWT project which generates a temporary directory gwt-unitCache folder. I'd like to remove it at the end of the build process.
I have got this plugin configuration:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
This does its job by deleting the automatically generated gwt-unitCache folder under src/main. However, it also removed the target folder which contains the classes and war file.
I don't want the target file to be removed thus I modified the configuration by removing the section:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
But this time it does not work anymore. The gwt-unitCache is not removed. It looks like the plugin is run at the beginning of the build process rather than at the end.
I am not good at Maven. Can someone help with this? How can I configure it so that:
The gwt-unitCache is removed at the end of the build process.
The target folder is not removed.
I use the command:
maven clean install
to build it.
Many thanks.
Not tested but maven-clean-plugin exposes an excludeDefaultDirectories that could help do the job. Something like:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
</configuration>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
On a side note, I don't see why you need to clear this directory, can't you just ignore it in your SCM?
RC I use this variation to still working as usual on clean phase.
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>gwt-unitCache</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.directory}/${project.build.finalName}/c</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
</configuration>
</execution>
</executions>
</plugin>
Since it came up in a comment: You can change the location of the cache directory like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<configuration>
<persistentunitcachedir>${project.build.directory}</persistentunitcachedir>
</configuration>
</plugin>
I have a project (of type 'jar') that (obviously) builds a jar. But that project has many dependencies. I'd like Maven to build a "package" or "assembly" that contains my jar, all the dependent jars, and some scripts (to launch the application, etc.)
What's the best way to go about this? Specifically, what's the best way to get the dependents into the assembly?
For a single module, I'd use an assembly looking like the following one (src/assembly/bin.xml):
<assembly>
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/command</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
<include>*.bat</include>
</includes>
</fileSet>
</fileSets>
</assembly>
To use this assembly, add the following configuration to your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
In this sample, start/stop scripts located under src/main/command and are bundled into bin, dependencies are bundled into lib. Customize it to suit your needs.
Here is my solution to create a distributable .zip (or .tar.gz / .tar.bz2) including all dependencies in a lib folder. It will:
Create a jar with a Manifest including the dependencies of the lib directory as the classpath and the main class to run when executing the jar.
Copy all dependent jars to the target/lib directory.
Create the distributable `zip with the main jar and all dependent jars of the lib directory.
Excerpt from pom.xml:
<!-- create distributable -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>full.path.to.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/resources/dist.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
dist.xml:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
</assembly>
The dist.xml was derived from the bin descriptor format here: http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#bin
I have used the maven assembly plugin to packages everything in one single jar. you can find info here
http://maven.apache.org/plugins/maven-assembly-plugin/
http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
HTH.