Top || Section Contents || Permuted Index
SavaJe OS 1.1.0

run_java(doc)


This document discusses packaging and running applications on SavaJe OS , including the following topics:

Packaging applications

The best way to package applications is to use JAR files.

For example, consider the application demo.MyDemo , where main() is contained in the file demo/MyDemo.class . MyDemo also uses demo.stuff.AnotherClass and demo.util.Tool . The following tree shows the package hierarchy for demo.MyDemo :

    demo
    |-- MyDemo.class
    |-- stuff
    |   `-- AnotherClass.class
    `-- util
            `-- Tool.class

To package this application in a JAR file, create a manifest file (MyDemo.mf in this example) containing the line:

Main-Class: demo.MyDemo

Then, from the parent directory of demo, run the jar command

jar cvmf MyDemo.mf MyDemo.jar demo

Now, you should be able to execute the resulting JAR file using the java command (on non- SavaJe OS platforms):

java -jar MyDemo.jar

On a SavaJe OS platform (after you've copied MyDemo.jar to the compact flash and inserted the compact flash into the computer), you should be able to run the application with the following commands (assuming that MyDemo.jar is located in the directory /cf0/users/me :

lsh% cd /cf0/users/me
lsh% run MyDemo.jar

or (from anywhere)

lsh% run /cf0/users/me/MyDemo.jar

You can also copy JAR files to the /ramfs file system (e.g., /ramfs/users/me/MyDemo.jar ) and run them from there.

Repackaging large applications

If you need to repackage an application that consists of multiple JAR files, you do not need to disturb the current JAR files. Simply create a new JAR file that contains only a MANIFEST file with the Main-Class attribute specifying the class that contains the main() method and the Class-Path: attribute listing the JAR files that should be searched. For example, if an application is split into two JARs, you could create a file EmptyJar.mf that contains the lines

Main-Class: AppMain
Class-Path: AppMain.jar another.jar

Create a new JAR file that contains only the manifest information:

host% JAR -cvmf EmptyJar.mf EmptyJar.jar

Place EmptyJar.jar and the other JAR files in the same place and Run the application with

% cd somewhere
% run [-nosm] EmptyJar.jar

You may need to use the -nosm option of the run command if the security policy is not appropriate.

Network JARs

Copy JAR files to a directory being served by httpd. The requirements on the JAR file are the same as for local JAR files.

Security for applications

By default, SavaJe OS installs a security manager with fairly restrictive permissions. (To see the default permissions, enter the command policy dump .) See policy(shell) . Some applications may try to read or write files on the compact flash or make socket connections. If you get a security exception while running an application, try using the -nosm option of the run(shell) command.

When class files are loaded, they are run through a bytecode verifier. Some applications compiled with older versions of Java compilers may fail the current bytecode verification. If this is the case, try using the -noverify option of the run(shell) command.

File names

The SavaJe OS operating system supports FAT12 and FAT16 file systems on compact flash with VFAT long filename extensions. Short filenames with capital letters will cause problems if created on a PC. There are two solutions:

Running local applications

You can run classes or executable JAR files that reside in local storage.

The following example demonstrates running a class from the compact flash:

lsh% cd /cf0/apps
lsh% ls Hello.class
Hello.class
lsh% Hello
Hello, world!

The following example demonstrates running an executable JAR from /ramfs/tmp :

lsh% cd /ramfs/tmp
lsh% ls Hello.jar
Hello.jar
lsh% Hello.jar
Hello, world!

Using base to set the class search path

Use set(shell) to specify a list (via the shell variable base ) of URLs to search for classes. The shell variable base is analagous to CLASSPATH in other Java environments. The URLs included in base can be either directories (denoted by a trailing slash) or JAR or zip files (no trailing slash). For example,

lsh% set base=file:///ramfs/users/albc/,http://192.168.0.237/MyApp.jar,http://chopin/classes/
lsh% run MyApp

sets the search path to the directory (note the trailing slash) /ramfs/users/albc/ , the JAR file MyApp.jar served by host 192.168.0.237 , and the directory classes served by the host chopin .

Running remote applications

Use set(shell) to set base to the URL where a remote application resides (JAR files or class directory). Once base is set, you should be able to run the application normally.

Troubleshooting large remote applications

If you are trying to run a remote application that consists of a large JAR file and you are having trouble getting it to run on a SavaJe OS platform, try running the application locally first to make sure the problem is not a result of a networking problem. There are several alternatives:

Bootstrapping applications

If you need to load an application as if it were part of the platform (a bootstrap or extension), you can place the application JAR file in the jre/lib/ext directory of either the /cf0 or /apps partition. See romfs(doc) for information about adding files to the /apps partition.

Putting applications on the GUI

For information about creating JNLP files and adding icons to the desktop, see jnlp(shell) .

SEE ALSO

app_env(doc)
jnlp(shell)
policy(shell)
romfs(doc)
run(shell)
set(shell)


July 11, 2002
Copyright © 2002 , SavaJe Technologies, Inc. All rights reserved.
Corrections, suggestions to: docs@savaje.com