Home > Blockchain >  How to modify the default bundle name made by JavaPackager
How to modify the default bundle name made by JavaPackager

Time:10-31

In the JavaPackager documentation the default bundle names are described.

For example, for a zip file:

  • "${name}-${version}-${platform}.zip"

I'd like to change those.

For example having :

  • "${name}-${version}-${platform}-Full.zip" for the bundle with the Jre, and
  • "${name}-${version}-${platform}-Light.zip" for the bundle without Jre.

Setting the ${name} property to e.g. "MyApp-Full" will affect the whole chain. From the bundle name to the exe name. I'd like to avoid this.

Edit: So my goal is to to build to zip files, one with one without the jre, with a different label, but with the same executable name inisde.

E.g. myapp-1.0.0-windows-Full.zip and myapp-1.0.0-windows-Light.zip with both a myapp.exe executable inside.

Anyone knows the solution ?

CodePudding user response:

There is no direct option in JavaPackager to change the name of the build. But you can achieve that by executing maven-antrun-plugin after javapackager plugin assuming you are using maven.

Need to create 2 builds. With JRE (Full) and without JRE (Light).

<plugin>
  <groupId>io.github.fvarrui</groupId>
  <artifactId>javapackager</artifactId>
  <version>1.6.6</version>
  <executions>
    <execution>
      <id>light</id>
      <phase>package</phase>
      <goals>
        <goal>package</goal>
      </goals>
      <configuration>
        <mainClass>com.example.demo.DemoApplication</mainClass>
        <generateInstaller>false</generateInstaller>
        <createZipball>true</createZipball>
        <outputDirectory>${project.build.directory}/light</outputDirectory>
      </configuration>
    </execution>
    <execution>
      <id>full</id>
      <phase>package</phase>
      <goals>
        <goal>package</goal>
      </goals>
      <configuration>
        <mainClass>com.example.demo.DemoApplication</mainClass>
        <generateInstaller>false</generateInstaller>
        <createZipball>true</createZipball>
        <bundleJre>true</bundleJre>
        <jrePath>${env.JAVA_HOME}</jrePath>
        <outputDirectory>${project.build.directory}/full</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

You can add maven-antrun-plugin to copy generated zip file to the target folder with the name you want.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>3.1.0</version>
  <executions>
    <execution>
      <id>light</id>
      <phase>package</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <target>
          <taskdef resource="net/sf/antcontrib/antcontrib.properties"
            classpathref="maven.plugin.classpath" />
          <property name="sub_dir" value="light" />
          <property name="file_suffix" value="-Light" />
          <ant antfile="${basedir}/build.xml">
            <target name="default" />
          </ant>
        </target>
      </configuration>
    </execution>
    <execution>
      <id>full</id>
      <phase>package</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <target>
          <taskdef resource="net/sf/antcontrib/antcontrib.properties"
            classpathref="maven.plugin.classpath" />
          <property name="sub_dir" value="full" />
          <property name="file_suffix" value="-Full" />
          <ant antfile="${basedir}/build.xml">
            <target name="default" />
          </ant>
        </target>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>ant-contrib</groupId>
      <artifactId>ant-contrib</artifactId>
      <version>1.0b3</version>
      <exclusions>
        <exclusion>
          <groupId>ant</groupId>
          <artifactId>ant</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</plugin>

You need to place build.xml at the root of the project so maven-antrun-plugin can execute that.

<?xml version="1.0"?>
<project name="javapackager">

  <target name="default">
    <fileset id="zip-files" dir="${project.build.directory}/${sub_dir}">
        <include name="*.zip" />
      </fileset>
    <foreach param="path" target="zip-copy" inheritall="true" inheritrefs="true">
      <path>
        <fileset refid="zip-files" />
      </path>
    </foreach>
  </target>
  <target name="zip-copy">
    <propertyregex property="filename" input="${path}" regexp="(. ?)(\.[^.]*$|$)" select="\1" />
    <propertyregex property="filename" input="${filename}" regexp="([^\\|\/]*)$" select="\1" casesensitive="false" override="true" />
    <copy file="${path}" tofile="${project.build.directory}/${filename}${file_suffix}.zip" />
  </target>

</project>

Now once you run mvn clean package command you will have myapp-1.0.0-windows-Full.zip and myapp-1.0.0-windows-Light.zip in the target directory.

  • Related