Deadlock Eclipse(R) has a great set of tools such as the debugger. A debugger allows a user to control a program while it is executing. Using a debugger to understand how a program works is a good way to find potential bugs. The debugger can be remotely attached to a JVM running in the Wrapper and you can see step by step what is happening. In the following example, you will see how the debugger is easy to setup.

Solution

Download the Java Service Wrapper

In this example, we will use the latest available version of the Wrapper: 3.5.26. Please download the Wrapper for your platform and save it somewhere on your disk. For example: /home/tanuki/wrapper-3.5.26/

Download the Java source code

The source code of the Java Service Wrapper is accessible via SourceForge. Please download the source code here download for the version you just downloaded in the previous step. In this example, we will use the source code for version 3.5.26.

Extract the files somewhere on your machine, for example: /home/tanuki/wrapper_3.5.26_src

NOTE

The Java source code is the same for all the editions (Community, Standard and Professional) of the Wrapper.

Eclipse files

Create the following two files (used by Eclipse) in the folder: /home/tanuki/wrapper_3.5.26_src/src/java

.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="."/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
.project
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>wrapper-code</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
</projectDescription>

Eclipse

Import the Java source code in Eclipse:

  • Start Eclipse
  • Click on file
  • Continue on import
  • Select General > Existing Projects into Workspace
  • Go to Next
  • Select the folder /home/tanuki/wrapper_3.5.26_src/src/java
  • Click on Finish

As soon as the folder is imported, you will see an error in Eclipse. To fix this, do the following steps:

  • Remove the extension .in from the file org.tanukisoftware.wrapper.WrapperInfo.java.in
Open the file and apply the following changes:
  • Change @version.root@ to 3.5.26
  • Change @build.date@ to 20131212
  • Change @build.time@ to 1200

My application

In Eclipse, we will create an application "MyApplication" that will be launched by the Java Service Wrapper. The folder for this project is /home/tanuki/workspace/MyApplication.

Create a class my.app.test.HelloWorld.

HelloWorld.java
package my.app.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.tanukisoftware.wrapper.WrapperManager;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Enter your name: ");

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String name = "";

        try {
            name = br.readLine();
        } catch (IOException ioe) {
            System.out.println("Could not read your name!");
            System.exit(1);
        }

        System.out.println("Hello, " + name + "!");
		
        String version = WrapperManager.getVersion();
        System.out.println("Wrapper Version: " + version);
    }
}

Eclipse will display some errors about the WrapperManager. To solve it open MyApplication's Properties and add the wrapper-code in the build path.

Link the Java Service Wrapper to MyApplication

Open the file /home/tanuki/wrapper-3.5.26/conf/wrapper.conf and set the following properties:

wrapper.conf
# information to run MyApplication
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

# set the path to your application
wrapper.java.classpath.3=/home/tanuki/workspace/MyApplication/bin
wrapper.app.parameter.1=my.app.test.HelloWorld

# set the Wrapper in debug mode
wrapper.java.additional.1=-Xdebug
wrapper.java.additional.2=-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y

NOTE

Port 8001 will be used later by Eclipse.

In this example, we are using the Integration Method 1 to integrate MyApplication with the Java Service Wrapper.

Run the Java Service Wrapper

Run the Java Service Wrapper using the following command:

TestWrapper Example Application
bin/testwrapper console console

You will see that the process looks frozen.

waiting for a debugger
Listening for transport dt_socket at address: 8001
In fact, the Wrapper is waiting for a debugger to be attached.

Run the debugger

In Eclipse, follow the steps to create a remote debugger:

  • Select in the menu Debug->Debug Configuration...->Remote Java Application.
  • Create a New Launch Configuration.
  • Set a name (for example "RemoteWrapper")
  • Select the project wrapper-code.
  • Set Host to localhost.
  • Set Port to 8001 (same value we set in wrapper.conf)
  • Click on tab Source
  • Click on Add, select Java project and choose both MyApplication and wrapper-code.
  • Finally click on Debug

From this point, the Eclipse debugger is linked to MyApplication and the Wrapper! If you look at the terminal, you will see that MyApplication is running. Back in the source code, you can add a breakpoint and debug the application. You will be able to see which line is executed.