Solution Advice: Webapp manually

Encrypt and wrap a webapp (war) into a single exe file


Webapp is a group of files (jsp, htm, java, xml etc) to perform a web site under a web server such as Tomcat etc.

If you want to encrypt and protect your webapp, and wrap it into a single exe file, and run it as a background service, this advice will show you how to do that, wrap and encrypt a webapp into a single exe file step by step.

 There is another easier way for reference :


We select 'tomcat-embed' as the web server. In our starter program, we create a Tomcat instance and call its start() to start the web server.

We will let the programs, such as jsp, jspx, jar and java files etc be 'encrypted' by Jar2Exe. The jsp files cannot be compiled at runtime because required classes are encrypted, so we must pre-compile the webapp before we can wrap into exe.

Because we want to get only ONE single exe file as result, we need to do little modification on tomcat that we need to let tomcat regard ".exe" file as a ".war" file. Of course, we do not really "modify" source code of tomcat, but inherit and overwrite one or two methods, by just modifying one or two lines.

Features used

Following features or third-party libraries are selected in this solution:

Feature Advice Introduction How to enable

Tomcat embed


We select tomcat embed as the web server.

Download from local site, or pom.xml



We will let the programs be encrypted, while we let other plain resources such as htm, gif, xml etc keep accessible.

At Step 4, check the encrypt option

Service application


We discuss how to protect and wrap webapp into one exe in this chapter. You can select to run as either a console program or a service program.

At Step 2, select Service application

Depend jar files


We wrap all tomcat jar files and jars of webapp into a single exe file.

At Step 5, add jar files

Stdout redirect


Tomcat will write logs to System.out, so it is recommended to redirect output to disk file as a log file.

At Step 6 > Config Internal > Custom tab, use a 'stdout' item

Stdout redirect
to cronolog


You can redirect stdout to a pipe, "| cronolog.exe %Y%m%d.log", to split output to daily log files.

Use a "stdout | cronolog.exe" in config

Force CWD


Disk IO, such as write log files with 'relative path' are based from the "working directory".

At Step 6 > Config Internal > Custom tab, use a 'forcecwd' item

Program icon


You can decide whether to select an icon, not necessary.

At Step 6 > Version & messages

Steps with example

We select the 'Tomcat/webapps/examples' as our demo webapp. The steps are a bit more complex than a common java program, so please prepare a working directory, for example "C:\tempspace\" or any directory else. Now let's begin:

  1. We need JDK and ANT installed before we can go on with this demo.
  2. Download from local site and extract to C:\tempspace\ , then we get:
    │  build.xml
  3. Copy the 'examples' webapp from Tomcat/webapps/examples to C:\tempspace\. If you have a war file, please extract it. Then we get:
    │  build.xml
    │  └─WEB-INF\
    │      ├─classes\
    │      └─lib\
  4. Pre-compile the webapp at command line by ant tool:
    C:\tempspace> ant -Dtomcat.home=. -Dwebapp.path=examples
  5. By the instructions of pre-compile webapp, we insert the contents of C:\tempspace\examples\WEB-INF\generated_web.xml into beginning of C:\tempspace\examples\WEB-INF\web.xml:
    <web-app xmlns=""
        <!-- INSERT contents of generated_web.xml HERE -->
          Servlet and JSP Examples.
        <display-name>Servlet and JSP Examples</display-name>
  6. Move all jar files out of webapp, that is to move from C:\tempspace\examples\WEB-INF\lib to C:\tempspace\lib
  7. Delete all programs in webapp, that is to delete all *.jsp, *.jspx, *.java(excluding static java that just for download), *.class(excluding Applet for browser client use) files in 'examples', and delete directory C:\tempspace\examples\WEB-INF\classes and C:\tempspace\examples\WEB-INF\lib .
  8. Wrap left contents of webapp into a zip file, that is to compress all files in C:\tempspace\examples\* into C:\tempspace\
    C:\tempspace>jar cvf -C examples/ .
  9. Write the starter program, using the modified Tomcat: ( Source code and modified tomcat)
    package hello;
    import org.apache.catalina.Context;
    import org.apache.catalina.core.StandardContext;
    import org.apache.catalina.startup.Tomcat;
    import com.regexlab.j2e.tomcat_modified.Jar2ExeTomcat;
     * demo starter for Jar2Exe
     * @author sswater
    public class HelloWebapp {
        public static void main(String[] args) throws Exception {
            // Tomcat instance
            Tomcat tomcat = new Jar2ExeTomcat();
            tomcat.setBaseDir(System.getProperty("", "."));
            // deploy exe file self as a war file
            Context context = tomcat.addWebapp("/", System.getProperty(""));
            // do not extract war file
            // Start server
  10. Compile the starter program and wrap into a jar file, C:\tempspace\hellowebap.jar . ( Download the starter) Now we should get following files:
    │  build.xml
    │  hellowebapp.jar
  11. Start Jar2Exe, at step 1, click Browse Jar and select 'C:\tempspace\hellowebapp.jar'
  12. At step 2, select Console application, or one of other type if you like.
  13. At step 3, select the main class hello.HelloWebapp
  14. At step 4, check the Encrypt and hide class files option.
  15. At step 4, at the 'These files keep not hidden' box, input C:\tempspace\
  16. At step 5, click Add, browse to C:\tempspace\lib and add all jar files in the directory.
  17. At step 5, select one or more or all jar files in the list box, and click Protect to encrypt selected jar files.
  18. At step 6, click "Version & Message", then
    1. At "Product Info" tab, click Add to add a program icon.
    2. Click OK to close this popup dialog.
  19. At step 6, click "Config Internal", or at step 7(Finished), click "Config External", then
    1. At Custom tab, append "forcecwd ." to set the "working directory".
    2. At Custom tab, append "stdout out.log" to redirect System.out to a disk file.
    3. Click OK to close this popup dialog.
  20. Click Next until finish.



Error: convert WebApp to exe


I follow your guide to build webapp to exe, but after building successful, i run "hellowebapp.exe" error.

Please support me, if ok i wil buy your tool



hello,i want to put one spring tomcat webap to a exe,so i try to use jar2exe,
i have do it sucessfully when do on examples,
but faile when i try to do on my project,which is a simple spring web project,just a hello project.
bellow is the message:
warning:cannot search for matching files underneath url [j2e:libs/web-inf-classes.jar!com/demo/web/controllers/] brease
it does not correspond to a directory in the file system

my directoy is c:tempspace/lib, not libs

Getting error while running

Getting error while running exe as belowINFO: No global web.xml found
Exception in thread "main" org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
        at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(
        at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(
        at org.apache.catalina.startup.ContextConfig.processAnnotations(
        at org.apache.catalina.startup.ContextConfig.webConfig(
        at org.apache.catalina.startup.ContextConfig.configureStart(
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
        at org.apache.catalina.core.StandardContext.startInternal(
        at org.apache.catalina.util.LifecycleBase.start(
        at org.apache.catalina.core.ContainerBase.startInternal(
        at org.apache.catalina.core.StandardHost.startInternal(
        at org.apache.catalina.util.LifecycleBase.start(
        at org.apache.catalina.core.ContainerBase.startInternal(
        at org.apache.catalina.core.StandardEngine.startInternal(
        at org.apache.catalina.util.LifecycleBase.start(
        at org.apache.catalina.core.StandardService.startInternal(
        at org.apache.catalina.util.LifecycleBase.start(
        at org.apache.catalina.core.StandardServer.startInternal(
        at org.apache.catalina.util.LifecycleBase.start(
        at org.apache.catalina.startup.Tomcat.start(
        at hello.HelloWebapp.main(



Add new comment