JNC (JavaNativeCompiler) v1.1 Manual

Version from 2007, February 07.

The latest versions of the manuals can be viewed here.
Please also read the FAQ on the homepage if you have any further questions...

Table of contents


Create/Open a project

Here you can open a saved project or create a new one. Nothing fancy...

Step 1 of 4: Source

Here you can specify the source of your application.
You can add: Each jar has an additional checkbox. It specifies if the whole jar or only needed (referenced) classes should be included into the final binary. Including only the needed classes will - who would have guessed that - result in smaller binaries. But there is a price tag attached to that: If a class is never referenced and only loaded by reflection, it will not be in the executable and thus a ClassNotFoundException will be thrown at runtime. To force the inclusion of such classes, you have to add a reference to them into your code.

An example to illustrate the problem and to show how to solve it:
SWT does not reference the handlers for the various image types. Looking at the source shows that the classes PNGFileFormat, JPEGFileFormat, WinICOFileFormat, ... from the package org.eclipse.swt.internal.image are loaded by Class.forName() when a user creates an image. Thus, references to the needed image handlers have to be added in the own application:
static
{
	org.eclipse.swt.internal.image.PNGFileFormat.class.getName();
	org.eclipse.swt.internal.image.JPEGFileFormat.class.getName();
	org.eclipse.swt.internal.image.WinICOFileFormat.class.getName();
}
In the case of SWT, this is not yet enough. These classes are protected, not public. So just create a dummy class in the org.eclipse.swt.internal.image package and add the initializer to that class...

Step 2 of 4: Basic settings (required)

Setting Description
Main class* You have to specify the class of your application that contains the main() method. This the same as when calling "java foo.bar.MyMainClass".
java.library.path You might want to specify the java.library.path.
Use CNI instead of JNI Check this box if you use native code by CNI instead of JNI.
Windows* Specify if a binary for Windows has to be created. If yes, you have to provide a location for it.
Icon On Windows, you can set an icon for you executables. It will be visible in the Windows Explorer.
Hide console On Windows, a console will be opened when executing the compiled application. While this is needed for console applications, it is mostly unnecessary for GUI applications. It can be hidden with this option.
Linux* Specify if a binary for Linux has to be created. If yes, you have to provide a location for it.
Mac Not yet supported...
Omit stripping Symbols of the binary will be stripped by default. This won't need additional time and the binary will be much smaller. You can turn it of with this option.
Omit packing The binaries will be packed by default. This needs a lot of additional time but will result in much smaller binaries. You can turn it off with this option.
Disable optimization The code to compile will be optimized by default. This needs - depending on how large your program is - a lot of additional time and a lot of RAM. In return, the compiled binary will be smaller and faster. You can turn it off with this option.
* Required

Step 3 of 4: Advanced settings (optional)

Setting Description
Custom GCJ flags Here you can specify additional flags for GCJ. Multiple flags are separated by spaces or newlines.
Show used commands If checked, the used commands for compiling the application will be shown during compilation.
Exclude GUI You can exclude the GUI part of the class library. It gets pulled into the binary by default. This will result in much smaller binaries but you have to ensure that you do not use any of these classes. Else you end up with compilation errors.
Exclude JCE You can exclude the "Java Cryptography Extension" of the class library. It gets pulled into the binary by default. This will result in smaller binaries but you have to ensure that you do not use any of these classes. Else you end up with compilation errors.
Add GNU regex This is needed if there are invalid regular expressions in the compiled code.
Without it, you will get this runtime error:
java.util.MissingResourceException: Bundle gnu/java/util/regexp/MessagesBundle not found
Don't cache compiled jars By default, compiled jars will be saved in the same directory as the jar. By doing so, it can be reused in later compilations (what is a real time saver). You can turn it off with this option.

Step 4 of 4: Compilation

Here you can finally hit the "compile" button :-)
If you check "Beep when done", it will beep once if the compilation succeeds and twice if it fails.