Solution Advices

Typical solutions for reference


Overview

Java language is a simple and convenient language, so it is good for tool softwares or game softwares, you can write a useful tool software easily and quickly. Java language is also powerful and stable, so it is also good for server softwares, which will run as a server for a long time stably.

Jar2Exe has many powerful functions to use in different kinds of java redistribute solutions. Here are some advices for typical solutions. The demos here are not only demos, they are also useful tools in practice.


About application types

There are 3 types of applications can be generated by Jar2Exe:

 Console type: When this type of application runs, the console window will be attached or created. User can interact with program through console. This type of applications are usually started at command line, with arguments if required.

 Windows GUI type: This type of applications are usually started from shortcuts by mouse clicking. When this type of application runs, there is no console window to be created. The outputs of System.out and System.err will not be visible, but the outputs can be redirected to a file or a pipe.

 Service type: This type of applications run in background. They can automatically start up when System starts up, without user login. This type of applications usually do a service on the network or do some background tasks.


About Java Runtime Library (JRE)

When generated exe runs, JRE is required. You can select to tell your customers to install JRE by themselves, or you can copy a 'jre' directory along with your program, and pack your program and 'jre' into install file together.

If your software is a small software, which is put online for download, it is preferred to tell your users how to install JRE.

If you want your software can run on a pc without JRE "installed", you can select to copy a 'jre' along with your program and pack them into install file together.


About encryption

Your java program can be encrypted and hidden into generated exe files, so user cannot extract it from exe file.

In most cases, your program will continue to run normally after encrypted. In certain cases, when your main program or a third-party library uses ClassLoader explicitly, you may need to make a little change to your code, to use another ClassLoader, in order to be compatible with encryption.


About 32 bits and 64 bits

32bits of generate exe files, with 32bits JRE only, can run on both 32bits and 64bits of OS.

Usually, you can redistribute your product as 32bits of exe file with 32bits JRE in order to run on both 32bits and 64bits of OS. If your program uses a memory larger than 1.4G, you must run your program as 64bits of exe file with 64bits of JRE.


Advices with live demos

These are some typical solutions of java program with Jar2Exe.

Advice Description Links

 Console tool

This advice shows you: How to write a console tool software to run at command line? How to print usage messages? How to prompt user to download java runtime environment?

The demo software is a tool to process svn dump file. It may be useful for someone in special situation. :)

 Details

 Live demo

 Desktop window

This advice shows you: How to write a window tool software using JSwing? How to show a splash window?

The demo software is a test tool for Regular Expressions in Java.

 Details

 Live demo

 Background service

Background service is running in background. It will continue to run when user logout. It can automatically start up when Sysem starts up without user login. This advice shows you: How to write a service program? How to redirect System.out as daily log files?

The demo software is a ftp server to run as a service. 

 Details

 Live demo

 Webapp

If you have a webapp (".war") file, and you want to encrypt it and wrap it into an exe file, Jar2Exe can help you do that. This advice shows you: How to compile, encrypt and wrap a webapp step by step? How to run a webapp as a standalone server or run a webapp as a background service?

The demo webapp is copied from Tomcat/webapps/examples.

 Details

 Live demo

 JavaFX

To encrypt a JavaFX program need some special steps. This advice shows you: How to encrypt a JavaFX program step by step.

The demo software is a calculator using JavaFX.

 Details

 Live demo

 More safety

This advice introduces the differences between Jar2Exe and some other third-party softwares, and how to use Jar2Exe and some third-party softwares together in your solution to let your java program more safe.

 Details

Mac ".app" folder

This advice introduces how to put generated binary file into an ".app" folder to be a Mac app.

 Details


Download

Comments

remove stderr.log

Hi

     jartoexe tool using automatically created stderr.log empty textfile in service application.i dont need this file.how to remove this file.

 

redirect to NUL or /dev/null

Yes, You can redirect stdout or stderr or both to a NUL device, on Windows:

stderr NUL

On Linux:

stderr /dev/null

Kotlin exe runtime error

Hi, When I run an executable program obtained through jar2exe packaged kotlin project, These errors were encountered.

I tried two versions of jar2exe,

version 2.5.1263

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at com.regexlab.j2e.Jar2ExeLauncher.main(Jar2ExeLauncher.java:48)
Caused by: java.lang.IllegalStateException: Unable to find extension point configuration extensions/compiler.xml (cp:
  null)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerApplicationExtensionPointsAndExtensionsFrom(KotlinCoreEnvironment.kt:545)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createApplicationEnvironment(KotlinCoreEnvironment.kt:516)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironmentForProduction(KotlinCoreEnvironment.kt:470)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:424)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.createForProduction(KotlinCoreEnvironment.kt)
        at com.test.env.KotlinEnvironment.createKotlinCompilerEnv(KotlinEnvironment.java:145)

version 2.1.4.979

Exception in thread "main" java.lang.IllegalStateException: Resource not found: /org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment$Companion.class
        at org.jetbrains.kotlin.utils.PathUtil.getResourcePathForClass(PathUtil.kt:172)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.registerApplicationExtensionPointsAndExtensionsFrom(KotlinCoreEnvironment.kt:542)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createApplicationEnvironment(KotlinCoreEnvironment.kt:516)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.getOrCreateApplicationEnvironmentForProduction(KotlinCoreEnvironment.kt:470)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:424)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.createForProduction(KotlinCoreEnvironment.kt)
        at cn.com.env.KotlinEnvironment.createKotlinCompilerEnv(KotlinEnvironment.java:145)

How can I solve this?

Same error

I get same errors, can't figure out why.

When i run exe file then it

When i run exe file then it gives Java Runtime Environment not found

JRE is required

1. When generated exe file runs, JRE is required.

2. Please make sure the 32bits or 64bits of exe and JRE match, 32bits of exe runs with 32bits of JRE, 64bits of exe runs with 64bits of JRE.

Working directory on Mac

Hi,

my Java Application has to read and write files located in sub folders from the current directory of the executable itself. This are NO resource files but own document files.

When I create an executable for MAC and start it from the terminal with ./prgrammname everything works fine. But if I start it by double click from the mouse the subfolders are not found. Looks like there is a problem with the working directory.

How can I solve this?

 

Use forcecwd

Use 'forcecwd .' in configuration file to set the "current working directory" to be the same folder as the binary file.

need solution...without installing JRE

After converting Jar file to exe, without installing JRE. I just want to place extracted JRE in the path of Program files.
# path : C:\Program Files\Java\jre1.8.0 ,But exe file is not working by this method.

Is there any other way to use Converted exe file without installing JRE( copy extracted JRE files in the path : C:\Program Files\Java\jre1.8.0) ??.

Classloader and resources

Hello I am having problems extracting a zip file out of a jar I have as a resource.  I can extract it but the names of the files and directories are obfuscated.  On this page you mention "program or a third-party library uses ClassLoader explicitly, you may need to make a little change to your code, to use another ClassLoader, in order to be compatible with encryption.", can you explain how to do this?  I am attempting to extract the jar like this currently:

   File dstFile = new File(outputPath, newFileName);
   InputStream resource = Myclass.class.getResourceAsStream("/MyJarToExtract.jar");
   FileOutputStream outStream = new FileOutputStream(dstFile);

   byte[] buffer = new byte[1024];
   int bytes;
   while ((bytes = resource.read(buffer)) != -1) {
    outStream.write(buffer, 0, bytes);
   }
   outStream.close();
   resource.close();
   dstFilePath = dstFile.getAbsolutePath();
   return dstFile;

I'm going to deploy a new release for this point

Right now Jar2Exe is not compatible with codesign on Mac. I have already resolved this problem and the new release is going to be finished soon, maybe within days or weeks.

Java Exe with Derby DB

hi,

I just purchased your product and need to have an exe for my java program which also uses Derby DB.  I used netbeans, so the Dberby DB has it's Folder for the DB.  Will jar2exe include the Dberby??  How should the jars and dependent Derby DB be included?

 

Thanks - Tony

Yes, Derby db can be included into exe file

Hi Tony,

I have just replied your another comment here: http://www.jar2exe.com/comment/571#comment-571

Yes, the Derby database can be put into exe file, but the database becomes readonly. If you need your Derby to be Readable and Writable, you need to put the Derby database outside in a directory.

Please take a look at this demo : http://www.jar2exe.com/support/demos/helloderby

Thank you very much for your purchasing.

Bundled JRE

Hello,

I downloaded the trial version yesterday and am trying to create a single Windows XP 32 bit executable. I need to include a main jar file, 3 dependent library jars, and a bundled JRE. Can you clarify what the settings should be to include the bundled JRE? From the "Config Internal" button and the "JRE" tab, I selected "Bundled JRE './jre'" and "Relative Path". It creates the exectuable without error, and will run correctly as long as the executable is in the same folder as the JRE. However, when I copy my executable to a different location, I receive the error "Java Runtime Environment not found". What do you recommend?

My directory structure looks like this:

- bin

   |- myExecutable.exe

   |- myExecutable.jar

   |- jre

   |- lib

       |- 3 library jars

 

Thank you,

Meg

 

You can specify the 'jre' through relative path from executable

1. The 'jre' is not wrapped into exe file, there need to be a 'jre' when exe file runs.

2. The 'jre' directory should be copied from installed jre or jdk without modification.

3. If there is a 'jre' directory along with the executable file, the executable will use this 'jre'.

4. If the 'jre' is not in the same folder of the exe file, you can specify it using relative or absolute path.

Your directory structure is correct, I could not tell exactly what's wrong, so I list some possible points. You can also contact me through email.

32bit versus 64bit

Hi,

On this page is stated that a 32bit can work on both 64bit and 32bit environments. This is not 100% correct. If you have a 64bit JRE installed the generated 32bit exe file will detect the JRE correctly and the progra will fail to start. You should change the decsription on this page accordingly.

Also, a nice new feature would be to not incorporate the JAR file(s) but also allow the EXE file to simply link to the JAR file. This would create a very small EXE file just calling the selected JAR file (and it's dependencies). My project is quite large and having to incorporate all the JAR files in the EXE file would be a pain. It does seem that I only have to select the main JAR and does actually seem to pick up on the dependencies correctly after that. Anyway, linking would be really good to have..

Best regards,

Robert Jan van der Waals

Thank you very much for your comment

Dear Robert,

Thank you very much for your comment. About the first point, I have modified the description. Yes, 32bits exe can only run with 32bits JRE.

About your second point, thank you for your suggestion. In future releases, I will let Jar2Exe be able to create a pure starter without a jar in it. Right now, there is an alternative method:

You can use an empty zip file as the "main JAR". Then at the "step 3: main class" step, you can ignore the warning message which tells you the "main class" may be not right. Then add all of your program as classpath.

Thanks.

Sswater Shi

Add new comment