ArcGIS Engine Java applications can be deployed using standard Java deployment technologies like executable Java Archive Files (JARs), Java WebStart, and launch scripts.
Prerequisites
The ArcGIS Engine Runtime, in combination with the Java Runtime Environment (JRE), is a complete runtime environment for ArcGIS Engine Java applications.
Once an ArcGIS Engine Runtime and a supported JRE are installed on a system, any ArcGIS Engine Java application can execute on that system. An ArcGIS Desktop installation also acts as an ArcGIS Engine Runtime. This means that any ArcGIS Engine Java application can run on a computer with ArcGIS Desktop and a supported JRE installed.
There are two recommended methods for deploying ArcGIS Engine Runtime.
Java desktop applications are typically deployed using the following technologies:
These deployment technologies will require access to arcobjects.jar. See Bootstrapping arcobjects.jar for more information.
An executable JAR is a type of Java Archive that packages together the application code (class files) and resources (images, sound, etc.) in a single executable file that can be used to launch the application by double-clicking its icon or using the java –jar <filename.jar> command. Executable JARs make it easy to package, distribute, install, and launch Java applications. They can also reference classes in other JAR files specified in the Class-Path header of the JAR’s manifest. This can be used to specify the location of arcobjects.jar if it is relative to the location of the application JAR. For example, if you are placing your executable JAR relative to ARCGISHOME, you can use the Class-Path header to refer to the location of arcobjects.jar. For more information on using the Class-Path header field in the manifest, refer to the Java tutorial at http://java.sun.com/docs/books/tutorial/jar/manifest/downman.html.
To create an executable JAR,
1. Compile your Java code, generating class files.
2. Create a manifest file containing the following lines:
Manifest-Version: 1.0
Main-Class: com.vendor.application.Main
Class-Path: ../../<relative path to>/arcobjects.jar
The name of the file should end with the .mf suffix. It is important that the file ends with a blank line. If the relative path to arcobjects.jar is not known at the time of creating the executable JAR, you can bootstrap arcobjects.jar as described in the Bootstrapping arcobjects.jar section.
3. To create the JAR, type the following command:
jar -cmf manifest-file app.jar input-files
The input files must include any class files, images, or sounds that your program uses.
4. To view the contents of the JAR, type the following:
jar -tvf jar-file5. The application can be executed using the following command or by double clicking the JAR file:
java -jar app.jar
1. Create a JAR file of the application using the above mentioned instructions and use the bootstrapping mechanism explained above to locate arcobjects.jar. An important thing to note is that arcobjects.jar is treated as a run time component and should not be bundled with your application or downloaded as a resource.jar from the WebStart application.
Assume you created app.jar.
2. Sign this JAR file:
a. Using the Java keytool utility, create an RSA KeyStore file:
keytool -genkey -keyalg RSA -keystore keystore.ks -alias myalias
b. Sign the JAR file using the jarsigner utility and the keystore file generated previously:
jarsigner -keystore keystore.ks -storepass abc123 -keypass mypass app.jar myalias
myalias is the alias and mypass is the password for the keystore.
3. Create a .jnlp file
.jnlp file is a XML document which specifies the behavior and requirements to run the application using Java WebStart.
The important tags to remember for the .jnlp files are as follows:
<application-desc/> — Can specify the main class for the application and pass arguments
<resources/> — To specify JRE requirements and resources for the application
This is how a sample .jnlp file looks:
**********************************************************************************************************************
<jnlp spec="1.0" codebase="http://EDN:8080/examples/demos/" href="enginedemo.jnlp">
<information>
<title>ArcGISEngine Java</title>
<vendor>Environmental Systems Research Institute</vendor>
<icon href="images/arcgis_globe.gif"/>
<icon kind="splash" href="images/arcgis_globe.gif"/>
<offline-allowed/>
<description>Demo</description>
</information>
<security>
<all-permissions/>
</security>
<application-desc main-class="com.example.Demo"/>
<resources>
<j2se version="1.4+"/>
<jar href="jar/jintegra.jar"/>
<jar href="jar/arcobjects.jar"/>
</resources>
<component-desc/>
</jnlp>
**********************************************************************************************************************
4. Serve this .jnlp file using a server:
Simply create a link on your webpage and point to this jnlp file for your users to connect and launch ArcGIS Engine applications using Java WebStart
You can find more information about Java WebStart at http://java.sun.com/products/javawebstart/developers.html.
Java applications are commonly started using shortcuts to launch scripts. On Windows, batch files can be used to launch ArcGIS Engine Java applications.
Create a batch file with the following line, and save it with the .bat extension.
java –classpath "%ARCGISHOME%/java/lib/arcobjects.jar;app.jar" com.vendor.application.Main
On running the batch file, the java application will be launched. For GUI applications, use javaw.exe instead of java.exe. This prevents an additional command window from opening up when the batch script is run.
Shell scripts can similarly be used on UNIX.
The ArcGIS Engine Java library is installed with ArcGIS Engine at <ARCGISHOME>/java/lib/arcobjects.jar.
It is recommended that ArcGIS Engine Java applications use this JAR file and do not redistribute arcobjects.jar with their own applications. Using the pre-installed arcobjects.jar ensures version compatibility and helpsto keep the size of application JARs as small as possible.
Since all ArcGIS Engine Java applications reference class files from the arcobjects.jar library, arcobjects.jar should be present in the Java classpath when the applications are run. In some cases, the location of arcobjects.jar is not known relative to the application JAR. This is the case with WebStart applications and executable JARs. In such cases, the following helper utility can dynamically load arcobjects.jar from its location on disk.
To use this utility, you will need to add the following Java class to your application and make it the entry point in your application. You will need to invoke your application's main method from the Bootstrapper's main method:
//Replace the following line with the name of your main
Application App.main(args);
No change is required in your main application.
You will still need to make sure that the first call in the other Java class is still the EngineInitializer call.
//Bootstrapper.java
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
public class Bootstrapper {
public static void main(String[] args) throws Exception {
bootstrapArcobjectsJar();
//Replace the following line with the name of your main Application
// App.main(args);
Globe3DEventBug.main(args);
System.out.println("done.");
}
public static void bootstrapArcobjectsJar() {
String arcEngineHome = System.getenv("ARCGISHOME");
String jarPath = arcEngineHome + "java" + File.separator + "lib" + File.separator + "arcobjects.jar";
File f = new File(jarPath);
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL", new Class[] { URL.class });
method.setAccessible(true);
method.invoke(sysloader, new Object[] { f.toURL() });
} catch (Throwable t) {
t.printStackTrace();
System.err.println("Could not add arcobjects.jar to system classloader");
}
}
}