Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a release package with maven?

Tags:

java

maven-2

I build a desktop application using Maven2.

I'd like to make a release from time to time (just copy all the project's and third party jars into a single dir and generate a run.bat file).

How to do it ?

like image 839
Łukasz Bownik Avatar asked Jan 23 '23 16:01

Łukasz Bownik


2 Answers

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

Here is an example of an assembly.xml file that you might want to use. It creates a tar.gz with all your dependency jars 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 your 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 your tar.gz created.

To release run:

mvn release:prepare
mvn release:perform

like image 101
dogbane Avatar answered Jan 26 '23 05:01

dogbane


OK I got it with a little help of dogbane's answer

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

<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 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 a run.bat myself - so it's not fully satisfying but will do.

like image 31
Łukasz Bownik Avatar answered Jan 26 '23 04:01

Łukasz Bownik