Orangevolt ANT Tasks » Tasks » jstub
jstubjnlp

2.2.1.  Example

Suppose you have a working self executable jar file which is named myapp.jar.

build.xml
<?xml version="1.0"?>  
 
<project basedir="." name="myapp" default="main">
  <taskdef classpath="orangevolt-ant-tasks-1.3.2.jar" resource="com/orangevolt/tools/ant/taskdefs.properties"/>
    
  <target name="main">
    <jstub
      archive="myapp.jar"
      mode="win32"
      execute="java -jar myapp.exe"
      output="myapp.exe"
    />
</target>
</project>

In case of a jar file which contains all resources required by your application named myapp.zip and is not a self executable jar file with main class com.mycompany.myapp you can use the following example.

build.xml
<?xml version="1.0"?>  
 
<project basedir="." name="myapp" default="main">
  <taskdef classpath="orangevolt-ant-tasks-1.3.2.jar" resource="com/orangevolt/tools/ant/taskdefs.properties"/>
    
  <target name="main">
    <jstub
      archive="myapp.jar"
      mode="win32"
      execute="java -cp myapp.exe com.mycompany.myapp"
      output="myapp.exe"
    />
</target>
</project>

The example below uses the commandline placeholder XYZjstubLocationXYZ:

build.xml
<?xml version="1.0"?>  
 
<project basedir="." name="myapp" default="main">
  <taskdef classpath="orangevolt-ant-tasks-1.3.2.jar" resource="com/orangevolt/tools/ant/taskdefs.properties"/>
    
  <target name="main">
    <jstub
      archive="myapp.jar"
      mode="win32"
      execute="java -cp XYZjstubLocationXYZ com.mycompany.myapp"
      output="myapp.exe"
    />
</target>
</project>

The key difference to the example before is that you can rename the application or put it somewhere in the path. The placeholder XYZjstubLocationXYZ will be replaced before execution by the real name and path of the executable.

An scenario: You rename the executable (configured with commandline javaw -cp XYZjstubLocationXYZ com.mycompany.myapp) to test.exe and store it under c:\winnt (which is registered in the PATH enviroment). When opening a console in c:\temp and execute test.exe the executable substitutes the placeolder and executes java -cp c:\winnt\test.exe com.mycompany.myapp.

Only the first placeholder will be replaced. Multiple placeholders will be ignored.

This example shows how to create a unix executable using dynamic commandline substitution.

build.xml
<?xml version="1.0"?>  
 
<project basedir="." name="myapp" default="main">
  <taskdef classpath="orangevolt-ant-tasks-1.3.2.jar" resource="com/orangevolt/tools/ant/taskdefs.properties"/>
    
  <jstub output="test.sh" mode="unix" archive="../layxx.jar">
    <execute>
      java -cp "${env:PATH}" -jar "${app:absolutepath}"
    </execute>
  </jstub>
</project>

The executable will execute java with the contents of the PATH environment variable as classpath and the executable itself as jar file.