Many developers encounter this issue when trying to modify Tomcat's startup parameters through /etc/init.d/tomcat6
. The key misunderstanding is that Ubuntu's init scripts often override environment variables. Here's why your changes aren't taking effect:
# Common pitfall - environment variables get overwritten
# In /etc/default/tomcat6 you'll find:
JAVA_OPTS="-Djava.awt.headless=true -Xmx128m"
Instead of modifying the init script directly, you should:
- Edit
/etc/default/tomcat6
(the proper location for environment variables) - Add your debug parameters to the existing JAVA_OPTS
- Make sure to preserve existing settings
# Correct way to modify JAVA_OPTS
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
After making changes, restart Tomcat and verify:
sudo service tomcat6 restart
ps aux | grep tomcat
netstat -tulpn | grep 8000
In Eclipse, create a new debug configuration:
1. Go to Run → Debug Configurations
2. Create new Remote Java Application
3. Set Host to your server IP
4. Port 8000 (must match address in JAVA_OPTS)
5. Connection Type: Standard (Socket Attach)
- Check firewall settings:
sudo ufw allow 8000
- Verify Tomcat is running with your user:
ps -ef | grep tomcat
- Examine catalina.out for errors:
tail -f /var/log/tomcat6/catalina.out
For production systems, consider using:
CATALINA_OPTS="$CATALINA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
This keeps debug settings separate from other Java options.
When setting up remote debugging for Tomcat 6 on Ubuntu 10.04, the common approach of modifying JAVA_OPTS in /etc/init.d/tomcat6
often fails because Ubuntu's init scripts use a different mechanism. Here's what actually works:
On Ubuntu systems, Tomcat 6 settings should be configured in:
/etc/default/tomcat6
Add these debug parameters at the end of the file:
JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
JAVA_OPTS="${JAVA_OPTS} -Djava.awt.headless=true -Xmx256M"
After saving the file, restart Tomcat:
sudo service tomcat6 restart
Check if the debug port is listening:
sudo netstat -tulpn | grep 8000
You should see output similar to:
tcp6 0 0 :::8000 :::* LISTEN 1234/java
In Eclipse, create a new debug configuration:
1. Go to Run → Debug Configurations
2. Create new 'Remote Java Application' configuration
3. Set host to your server IP
4. Port: 8000
5. Connection Type: Standard (Socket Attach)
For more control, you can modify the startup script directly:
sudo nano /usr/share/tomcat6/bin/catalina.sh
Find the JPDA_ADDRESS
variable and set it to:
JPDA_ADDRESS="8000"
JPDA_TRANSPORT="dt_socket"
Then start Tomcat in debug mode:
sudo /etc/init.d/tomcat6 stop
sudo /usr/share/tomcat6/bin/catalina.sh jpda start
If you still can't connect:
- Check Ubuntu's firewall:
sudo ufw status
- Verify SELinux isn't blocking:
sudo setsebool -P tomcat_can_network_connect_db 1
- Ensure your debug parameters appear in the process list:
ps aux | grep tomcat