Definition
Explain how to perform debugging when something doesn't work in Cargo. Indeed it can happen that the container does not start or stop as expected. Or that some deployable does not deploy fine. Or whatever else! Here is a short list of things you can do to try debugging the problem.
Enabling the Java debugger
Most Java Virtual Machine implementations support remote debugging. Once started in debug mode, you can then remotely connect to your container using any IDE and debug your container and/or application.
In order to do so, add the following arguments to the JVM arguments configuration:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=<suspend>,address=<port> -Xnoagent -Djava.compiler=NONE
where:
- suspend is whether the launch of the container should first wait for a remote debugger to connect. If
y
, the container will wait for you to connect with your remote debugger before starting; ifn
the container will start immediately and at the same time listen on the remote debugging port. - port is the port number to use for remote debugging.
Here is an example for starting a JOnAS 5.x container in Remote Debug on port 8000 without suspend mode using the Maven2 plugin:
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>${cargo.version}</version> <configuration> <container> <containerId>jonas5x</containerId> <type>installed</type> <home>${jonas.root}</home> </container> <configuration> <type>existing</type> <home>${jonas.base}</home> <properties> <cargo.servlet.port>${http.port}</cargo.servlet.port> <cargo.jvmargs> -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xnoagent -Djava.compiler=NONE </cargo.jvmargs> </properties> </configuration> </configuration> </plugin>
Once the server is started, follow these steps to remotely debug your server and/or application:
- Click Debug - Attach Debugger...
- In the window that appears, type in the remote host name and the port number then click OK
Steps for achieving the same in Eclipse IDE are similar.
Redirecting container output to a file
The Container.setOutput(File)
API allows you to redirect the container console (stdout) to a file. This is the first file you should check in case of problem.
Example using the Java API
Starting Tomcat 4.x specifying an output console log file:
LocalContainer container = new Tomcat4xLocalContainer( new CatalinaStandaloneLocalConfiguration("target/tomcat4x")); container.setHome("c:/apps/jakarta-tomcat-4.1.30"); container.setOutput("target/output.log"); container.start();
Use the container.setAppend(true|false)
method to decide whether the log file is recreated or whether it is appended to, keeping the previous execution logs (by default, the file is recreated at every container start or stop).
Example using the Ant API
Starting Tomcat 4.x specifying an output console log file:
<cargo containerId="tomcat4x" home="c:/apps/jakarta-tomcat-4.1.30" action="start" output="target/output.log"/>
Use the append="true|false"
attribute for controlling the log file creation behavior.
Generating Cargo logs
Some Cargo classes support generation of logs. This is implemented through the notion of Logger
.
For example to turn on logging monitoring on a Container
class, you can use:
Logger fileLogger = new FileLogger(new File("c:/tmp/cargo.log"), true); container.setLogger(fileLogger);
There are several Loggers that are readily available in the Cargo distribution:
- FileLogger: logs messages to a file
- SimpleLogger: logs messages to the console (stdout)
- AntLogger: logs messages using Ant's logging mechanism
Turning on container logs
Cargo is able to configure containers to generate various levels logs. There are 3 levels defined in o.c.c.container.property.LoggingLevel
: LoggingLevel.LOW
, LoggingLevel.MEDIUM
and LoggingLevel.HIGH
(LoggingLevel.MEDIUM
is the default value). They represent the quantity of information you wish to have in the generated log file. You can tune container logging by using the following API:
configuration.setProperty(GeneralPropertySet.LOGGING, LoggingLevel.HIGH.getLevel());
![]() |
The |
The generated log files will then be found in the working directory you have specified on the container (through the container.setWorkingDir()
call).
When using the Ant tasks, you can specify the log file by using the log
attribute. For example:
<cargo containerId="resin3x" [...] log="target/cargo.log"/>