How to create a release package with maven?

I am building a desktop application using Maven2.

I would like to release from time to time (just copy all the projects and third-party banks into one directory and create a run.bat file).

How to do it?

+4
source share
4 answers

You need to create run.bat yourself and put it in src / main / assembly / scripts, for example. Then you need to create the assembly.xml file in src / main / assembly.

Here is an example assembly.xml file that you might want to use. It creates tar.gz with all your jars of dependency and your run.bat.

<assembly> <id>1.0</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>/lib</outputDirectory> </dependencySet> </dependencySets> <fileSets> <fileSet> <directory>target</directory> <outputDirectory>/lib</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> <fileSet> <directory>src/main/assembly/scripts</directory> <outputDirectory>/scripts</outputDirectory> <includes> <include>*.bat</include> </includes> </fileSet> </fileSets> </assembly> 

Finally, in the pom.xml file add the assembly plugin:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>attached</goal> </goals> </execution> </executions> </plugin> 

Now when you run "mvn install", you should see that your tar.gz is created.

To start a launch:

mvn release: prepare mvn release: execute

+8
source

OK, I got a little help from the dossier.

I used my own assemlby src / main / assemlby.assembly.xml file

 <assembly> <id>teleinf</id> <formats> <format>dir</format> </formats> <moduleSets> <moduleSet> <includes> <include>pl..........:core</include> <include>pl..........:gui</include> </includes> <binaries> <outputDirectory>../../release</outputDirectory> <unpack>false</unpack> </binaries> </moduleSet> </moduleSets> <fileSets> <fileSet> <directory>src/main/assembly/</directory> <outputDirectory>../../release</outputDirectory> <includes> <include>*.bat</include> </includes> </fileSet> </fileSets> </assembly> 

and added the following to pom

  <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> </plugin> 

I had to write run.bat myself so that it would not completely satisfy, but would do.

+1
source

I would go with the maven release plugin, see

0
source

Just add the answer received by dogbane

In your .bat file, a packed jar file will be launched with a file name that reflects the current version of the application, for example.

 java -Xms256m -Xmx350m -jar bin\yourApp-1.10.1-SNAPSHOT.jar 

In each release, this file must be updated with a new application name. It can also be automated.

In your pom.xml file add this section:

 <build> <resources> <resource> <filtering>true</filtering> <directory>${project.build.sourceDirectory}/../assembly/scripts</directory> <includes> <include>yourApp.bat</include> </includes> </resource> ... </resources> ... </build> 

This means that you placed yourApp.bat in the folder:

 src/main/assembly/scripts 

The contents of yourApp.bat should look like this:

 java -Xms256m -Xmx350m -jar bin\${project.build.finalName}.jar 

Just run the Maven commands and enjoy.

0
source

All Articles