If you are seeing a 404 response on your HTTP request for an application running on a tomcat server, it may be because we need to have at least one ROOT.war in your /webapps folder.
If you want to change the port number on which tomcat is running, you need to edit properties in server.xml file in /conf folder : Update the connector port = “8080” to whatever port you want the tomcat to run on.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Some of the configuration for local tomcat installation are also present in catalina.sh file in /apache-tomcat-8.0.32/bin directory.
If you are seeing any weird errors in your tomcat logs upon starting tomcat server, make sure you did not update any tomcat config files(Try to get that standard property file content from apache website).
Debugging java application in tomcat using Eclipse and Intellij :
Add this to your Tomcat catalina.sh file:
JAVA_OPTS=”$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y”
Run Tomcat from command line in tomcat bin directory, run:
./catalina.sh start ; tail -f ../logs/catalina.out
If using Eclipse, create a Debug configuration:
- Under the “Run” menu, select “Debug”
- Single-click the heading “Remote Java Application”, then press the new button (looks like a page with a plus on it).
- On the dialog that appears, enter a meaningful name (like “Debug Tomcat” for this configuration).
- From the same dialog, change to the “Source” tab, then click “Add”
- On the dialog that appears, single-click “Java Project”, then click “OK”.
- On the dialog that appears, click “Select All” (or check the projects you wish to import), then click “OK”.
- Now click the “Connect” tab and check the box marked “Allow termination of remote JVM”.
- Set the Connection Properties to “localhost” and port 8787. Note this is the same port as in the line you added to the catalina.sh file above.
- Click “Apply” to save your changes.
- Click “Debug” to start testing your configuration.
To deploy new changes in your webapp code to Tomcat using a Gradle task:
Eclipse:
- Under the “Run” menu, choose “External Tools”> “External Tools Configurations”
- Click the + add icon in the upper left corner
- Add the following Gradle tasks:
clean compileJava compileTestJava assemble deployToTomcat
Make sure those tasks are defined in the build.gradle file for your project.
4.Click “Run”
in IntelliJ, create aDebug configuration:
- Under the “Run” menu, select “Edit Configurations”
- Click the + icon in the upper left corner
- Choose “Remote”
- Give the Configuration a name, such as “Debug Tomcat”
- Change the Port # to whatever your Tomcat service is listening on which would be 8787 in example above (dt_socket,address=8787 in the JAVA_OPTS )
- Click “OK”
- Click Run > Debug and choose this configuration.
- Add breakpoints to the code you wish to invoke/debug.
To deploy new changes in your webapp code to Tomcat using a Gradle task:
IntelliJ:
- Install the Gradle plugin for IntelliJ if you don’t already have it.
- Open the Gradle Projects window on the right side of the window
- Click the + icon at the top right and navigate to your project’s build.gradle file and select it.
- Expand the “Tasks” > “build” and “other” items in the tree, and run the tasks you wish to run and deploy the code to tomcat. (You can also run gradle tasks from terminal)