Solution Advice: JavaFX

Encrypt and protect JavaFX programs built from e(fx)clipse.


Introduction

When a JavaFX program starts, it uses a Special ClassLoader to load JavaFX libraries and program. So, in order to let the starter program of JavaFX program compatible with encryption of Jar2Exe, we need some special steps during exe file generation.

The JavaFX programs here are of JavaFX 2.0, not JavaFX scripts.


Solution

To let the JavaFX starter program be compatible with encryption of Jar2Exe, we need to do little modification on the starter program, that is to add 4 or 5 lines to deal with the special ClassLoader. Then we use our modified starter program instead to start JavaFX program.

The JavaFX starter program will read META-INF/* to know which is the real entrypoint of your program. So we need to "keep META-INF/* not hidden" when we encrypt the jar file.


Features used

We discuss how to encrypt JavaFX program here, for other features such as "Program Icon", "Application type" etc, please refer to other solution advices.

Feature Advice Introduction How to enable

e(fx)clipse

Required

We discuss how to encrypt JavaFX program built from e(fx)clipse.

http://www.efxclipse.org/

Encryption

Required

Encrypt JavaFX program from being extracted. There are some special steps during generation, please see the steps.

At Step 4, check the encrypt option

JDK 1.7 or above

Required

The demo program requires 1.7 or above.

Download from oracle javase.


Steps

There are some special steps to encrypt JavaFX programs:

  1. The demo program is from https://github.com/lestard/SnakeFX
  2. Build with e(fx)clipse and we get SnakeFX/build/dist/SnakeFX.jar ( SnakeFX.jar)
  3. Doanload modified JavaFX starter program: fx.jar, and save to disk, such as "C:\fx.jar". If you are interested in which 4 or 5 lines are added, please see the introduction of modification below.
  4. Start Jar2Exe, at step 1, click Browse Jar and select: SnakeFX.jar
  5. At step 3, if you select a picture as Splash window, please close it through integrate API when main window opens.
  6. At step 4, check the Encrypt and hide class files option
  7. At step 4, at the 'These files keep not hidden' box, input C:\fx.jar|META-INF\*|com\javafx\** , which contains path to downloaded fx.jar and META-INF\*|com\javafx\** . The path to fx.jar must be in front to overwrite the original starter program.
  8. Please refer to other solutions for other options of Jar2Exe according to your program.
  9. Click Next until finish.

Modification on JavaFX starter

If you are interested in the modification on the starter program, you can see the modification here:

  1. Download JavaFX starter Source code
  2. Insert following lines at line 221: ( Modified source code)
                ClassLoader urlClassLoader = new URLClassLoader(urls, null);
                
                // INSERT by Sswater Shi for Jar2Exe compatible 2013.3.12
                try {
                    Class j2eldr = Class.forName("com.regexlab.j2e.Jar2ExeClassLoader");
                    if(j2eldr != null) {
                        ClassLoader sysldr = ClassLoader.getSystemClassLoader();
                        java.lang.reflect.Constructor c = j2eldr.getConstructor(ClassLoader.class);
                        urlClassLoader = (ClassLoader)c.newInstance(new URLClassLoader(urls, j2eldr.isInstance(sysldr)?sysldr.getParent():sysldr));
                    }
                } catch(Throwable t) { }
                // END of INSERT
                
                Class launchClass = Class.forName(fxLaunchClassName, true,
                        urlClassLoader);
    
  3. Compile and pack into fx.jar

 

Comments

Spelling

Spelling error on this page with "download", but seems good :)

Add new comment