tags:

views:

805

answers:

4

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 ?

A: 

i would go with the maven release plugin, see:

Michael Lange
+3  A: 

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

dogbane
A: 

Just an addition to the answer given by fahdshariff

Your .bat file will running packaged jar file with a filename reflecting the current version of the application, e.g.

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

On every release this file will need to get updated with a new version name of the application. This can be automatized, too.

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 asumes that you have put the yourApp.bat file in the folder:

src/main/assembly/scripts

Content of the yourApp.bat file should look like this:

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

Just run the Maven commands and enjoy.

Boris Pavlović
Good idea, but I couldn't get it to work. I needed to add the filtering flag to the fileset element in the assembly xml instead.
disown
A: 

OK I got it with a little help of fahdshariff'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.

lbownik