Remote Debug Tomcat 7 With IntelliJ - java

I have a web application running on 10.0.1.62:8080/xxx. I want to debug remotely via IntelliJ IDEA. I have set JAVA_OPTS = -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
on 10.0.1.62 machine(Tomcat7 on Ubuntu) and when I hit the remote debug button IDE is giving an info message :
Connected to the target VM, address: '10.0.1.62:8000', transport: 'socket'
Than I am hitting the 10.0.1.62:8080/xxx.
Although I get this success message brekpoints are not hit. What am I missing ?

Firstly, double check your settings by referencing this question and answer: Remote Debugging in IntelliJ Tomcat
From you question it sounds like you have already followed these steps. There are a few other config problems that have caused me issues with remote tomcat debugging in the past that I'll share and hope it helps.
Be sure you started the proper remote debugging process on IntelliJ.
Make sure you are connecting to the correct Tomcat instance, if there are multiple Tomcat servers running on your host. The debug port 8000 may already be in use. I'm use an arbitrary port of 15019 or some other port number not already in use. Make sure the ports used match between Tomcat and IntelliJ.
Depending on how you setup remote debugging on Tomcat, it may not shutdown properly leaving an old instance running. Adding the debug hooks at the top of catalina.sh will cause the shutdown.sh script to fail because your debug port is already bound to the Tomcat server. Instead place it within the start if statement:
elif [ "$1" = "start" ] ; then
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=15019,suspend=n,server=y"
After fixing this issue, you can shutdown Tomcat successfully with ./shutdown.sh and still start debugging with ./startup.sh
Make sure you have a clean deployment of your application on Tomcat. Your cleanup process may require variations, but here is the general idea:
Shutdown Tomcat, then verify it is no longer running.
Remove the deployed war file and corresponding exploded version from your tomcat webapps directory.
Remove the contents of the work and temp directories.
Deploy and verify your recently build war file.
Start Tomcat.
Creating a script to do this will save time.
If all else fails, add a debug log to double check the code with the breakpoint is being invoked in the first place.
I'm sure there are twenty other things that could go wrong. Feel free to add ideas.

Related

Unable to start Tomcat server in IntelliJ IDEA

I found following issue whenever i try to run tomcat server with intellijidea. I have tried adding hostname to localhost but didn't work. Any suggestions?
Take a closer look at the server's output, to see the reason, why was Tomcat not started:
java.net.UnknownHostException: nitesh-pc: nitesh-pc
That could mean, that you have a problem with your hosts file (in OS Windows it could be found at {WindowsFolder}\System32\drivers\etc\hosts). You just need to add your hostname to localhost ip-address (don't forget to uncomment it, if needed), like:
127.0.0.1 localhost nitesh-pc
And then try to restart your server again.
I had an issue where Tomcat appeared to have started inside IntelliJ, but when I tried to open the Tomcat homepage I was getting "HTTP 404 Not Found" in the browser.
Starting Tomcat standalone (running startup.bat from the command prompt) started Tomcat and I could see the homepage fine.
I compared the output of running both standalone and within IntelliJ and noticed that CATALINA_BASE was different.
So I created a setenv.bat file in Tomcat bin directory (it was initially not there) and set CATALINA_BASE there like:
set CATALINA_BASE=C:\apache-tomcat-8.5.14
After that, Tomcat starts from IntelliJ and I can access the homepage.
Just putting this out there because I was at a loss why the page was not available when Tomcat seemed to have started OK.
Hope this will help someone.
This may happen if the machine has multiple or changing IP adresses (e.g. when using VPN or Hyper-V, Docker or other virtualization).
The solution is to define the IP address Tomcat should use for RMI:
-Djava.rmi.server.hostname=127.0.0.1
(This is a sane default for a Tomcat running locally, but you’re setup might require a different one.)
This has to be set so it’s applied as a command-line argument for the JVM. This might be in IntelliJ or Tomcat itself (for Linux systems bin/setenv.sh in the Tomcat directory, for a Windows service it’s usually in HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\Tomcat9\Parameters\Java\Options.

Start Tomcat on Console from Jenkins

I have a batch file which start Tomcat as follows (when running it on Windows it works fine)
...
start C:\Users\root\tomcat\tomcat2\bin\startup.bat
The batch file is called from Jenkins as follows
I have this error in the Jenkins Consol at the end of the build
D:\jenkins\workspace\Start 3T2>start C:\Users\root\tomcat\tomcat2\bin\startup.bat
Process leaked file descriptors. See http://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build for more information
Finished: SUCCESS
When I check the task manager I see that the server is started but in background. I need actually to start Tomcat it in the Console.
This is what I did :
I added -Dhudson.util.ProcessTree.disable=true in jenkins-slave.xml
used to start jenkins slave service.
I added set BUILD_ID=dontkillme in startup.bat to stop Jenkins from
stopping the process in the end.
I think Tomcat start correctly in the end but not in Console. I'm running Windows 2012 server/Tomcat7/Jenkins 1.578.
Any idea on how to start Tomcat in a Console ?
AFAIK, if you're trying to start Tomcat console on a given machine which has Jenkins configured as service, it will not work. To make it work, you will have to connect to the given machine using JNLP. In case it's a standalone system and you want to open a Tomcat console using Jenkins, you will have to set up a Slave on the same machine and that too using JNLP (Launch slave agents via Java Web Start) in the Launch method section in Jenkins > Manage Jenkins > Manage Nodes > Slave Node's Configure page.
You can connect to the slave using any of the methods shown below. You will see the below option as soon as you configure the slave node and click Save. I ran the highlighted command from the Win command prompt. In my set up, i had configured Master and Slave on the same machine. I have Win 7 Professional, 64-bit laptop.
Once you run the command, you will see a small window that will pop-up and will display 'Connected' message as shown below:
At least for me, i checked that hudson.util.ProcessTree.disable=true & BUILD_ID parameters were not required. The only thing that i needed was to make sure that the following property is unset: HUDSON_SERVER_COOKIE
P.S.: You might have to make sure to start JNLP on reboot. A start-up script will do that. Also, ensure that your project/job is tied to the given slave which is running using JNLP mechanism.
i was going crazy with this , as shutdown.sh worked from Window-Master-Jenkin-->Linux-Slave-Jenkins, but startup.sh was not happening on my linux-slave-jenkins though startup.sh execution showed success message, as there were no logs anywhere, it was difficult to troubleshoot, not sure how and why setting up "export HUDSON_SERVER_COOKIE= " just before running startup.sh worked. Anyway Thanks a lot.

Tomcat starts but home page cannot open with url http://localhost:8080

I am a newbie in Java, and I am trying to develop a web application.
I have Windows 7 32 bit. I have installed Java 7 and set the path and classpath as well. After that I installed Tomcat 7.
When I try to open tomcat home page using URL localhost:8080, it does not open and Tomcat stops automatically.
Please help me.
Make sure no other application using port 8080 before starting tomcat. If that's not the problem please paste tomcat log.
If you want to change tomcat's default port, go to tomcat folder and open conf folder, in which you can see server.xml. In that file you can see something like <Connector port= . Change the port value and start tomcat.
If you started tomcat through eclipse, It can be solved in different ways too.
Method 1:
Right click on server --> Properties
click on Switch location and apply.
Method2:
Double click in the server in eclipse.
Change Server location to Use tomcat installation(takes control of tomcat installation).
Your issue is not with port 8080, but with port 8005. Port 8005 is the shutdown port for Tomcat.
Rather than trying to figure out what is using port 8005, it may just be easier to edit TOMCAT_DIR/conf/server.xml and change the shutdown port to 8006
<Server port="8006" shutdown="SHUTDOWN">
For *Unix based systems, you can check the ports used by a particular application by issueing the following command in the terminal
[~/.]$ netstat -tuplen
You will get the list of all the ports that are being currently held and used by their respective process ID's
For windows user, type netstat -anin command prompt to see ports that are listening, this may come handy.
1) Using Terminal (On Linux), go to the apache-tomcat-directory/bin folder.
2) Type ./catalina.sh start
3) To stop Tomcat, type ./catalina.sh stop from the bin folder. For some reason ./startup.sh doesn't work sometimes.
For mac users
First Try : go to activity monitor -> search for java and kill the instance then restart the server and try.
Second Try:
Check log file for any errors under tomcat logs folder.
Use below command to check tomcat logs in terminal
tail -f {tomcatpath}/logs/catalina.out
Third Try:
Check if node or other apps using the same port. Use below command to check which app listening to a specific port. You will see list of apps with pid in second column.
lsof -i :8080 | grep LISTEN
Kill the process using below command
sudo kill -9 pid
If you are using eclipse to start the server then check for the server location being used and the deployment path:
In my case changing this to Tomcat installation instead of workspace metadata worked for me.
My issue has solved.I was getting log as below.
SEVERE: StandardServer.await: create[localhost:8005]:
java.net.BindException: Cannot assign requested address: JVM_Bind
My tomcat server was automatically stopping when I tried to open tomcat homepage with
URL.
So I just made some changes in windows->System32->drivers->etc->host file.
keep only 127.0.0.1 localhost and remove all other. your problem will be solved.
Thank you guys for your help :D
If you have your tomcat started (in linux check with ps -ef | grep java) and you see it opened the port 8080 or the one you configured in server.xml (check with netstat --tcp -na | grep <port number>) but you still cannot access it in your browser check the following:
It may start but with a delay of 3-5 minutes. Check the logs/catalina.out. You should see something like this when the server started completely.
INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 38442 msIf you don't have this INFO line your server startup is not complete yet. The problem may occur due to the SecureRandom class responsible to provide random Session IDs and which can cause big delays during startup.
Check more details and the solution here.
Check your firewall (on linux iptables -L -n): You can try to reset your firewall completely iptables -F if you are not into an exposed environment. However, pay attention, that leaves you without protection therefore it can be dangerous.
Check your selinux (if you are on linux).
These are some of the most forgotten and not obvious issues in having your Apache Tomcat up and running.
I am using Eclipse Java EE IDE for Web Developers. Version: Oxygen.1a Release (4.7.1a) in Windows 8.1 x64 with Apache Tomcat 8.5.24 (for testing purpose).
Port Name & Numbers for my Tomcat Server are :
Tomcat admin port : 8005
HTTP/1.1 : 8081 (my Tomcat Listening Port Number)
AJP/1.3 : 8009
Peoples, for those the Tomcat were running good earlier, and sometimes sudden after stopping tomcat server explicitly by pressing the below shown image button or may be other reasons.
Either they continuously failed to start/restart the tomcat with below said error:
Server Tomcat vX.Y Server at localhost failed to start.
or sometimes the Tomcat Server is started but instead of showing Tomcat Homepage in web browser, it is throwing client exception HTTP Status 404 – Not Found. in preferred web browser.
possibly, there are many reasons i.e. wrong Host name defined, Wrong Tomcat Server Locations defined in eclipse, project JDK/JRE version mismatch with Tomcat JRE dependent version, maven project version mismatch due to maven.compiler.source and maven.compiler.target version not defined under properties tag, mismatch version of project facet Dynamic Web Module to 2.5/3.0, Sometimes Tomcat Server is running on Windows Services level, previous stopped Tomcat port number were still listening and the processing pid were not killed in Tomcat defined timespan Timeouts Stop (in seconds): 15(by default) in eclipse and pid still running, failed to start in defined Start (in seconds): XX, etc.
Here I will give the resolution on, how to check and kill the running existing Tomcat port number's processing pid(beware, you must be aware with after effects).
In Windows, open you command prompt, and follow steps(my tomcat HTTP port is 8081):
netstat -ano | findstr :8081
TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING 2284
TCP [::]:8081 [::]:0 LISTENING 2284
if any listening is being there, above command will list details of port listening along with processing pid at last of the line(here pid is 2284).
now kill the running pid like:
taskkill /PID 2284 /F
SUCCESS: The process with PID 2284 has been terminated.
also illustrated the above two steps like following:
Now, after resolving above illustrated reason, start the Tomcat Server.
I had the same issue. My tomcat was started but I was getting HTTP 404 page not found.However, in my situation, I installed tree instances of tomcat. Each instance contains conf, temp, work, webapps and logs folders. Unless I forgot, to copy the global web.xml under conf folder of each tomcat.
e.g: /opt/tomcat/mytomcatInstance/conf/web.xml
The web.xml Deployment Descriptor file describes how to deploy a web application in a servlet container.
So even if my tomcat was up, my web apps could not be deployed properly.
The problems may happen because of memory issue.
java.lang.OutOfMemoryError: Java heap space
please verify the logfile, any issues related to hardware(memory).
Look in TomcatDirectory/logs/catalina.out for the logs. If the logs are too long, delete the catalina.out file and rerun the app.
In my case, the port that tomcat was running on was defined in an application.properties file for 8000, not 8080. In my case, it looked like the same problem described here. Just leaving this here in case anyone has a similar setup and issue! :)

Starting Jetty via launch script does not work

I have a problem with starting Jetty via the startup command /etc/init.d/jetty. When I execute the command the following output is generated:
/etc/init.d/jetty start
Starting Jetty servlet engine.:
Jetty Rotate logs
Jetty servlet engine started, reachable on http://jagadguru:80/.: jetty.
It does start successfully when I type java -jar start.jar in my Jetty directory.
Can anyone help me with this?
This is likely a file permission issue. Even if you are running the start script with sudo, the script defines a jetty user (default is jetty). I had an issue similar to this where my permissions on /tmp prevented jetty from creating a file there. I adjusted the permissions on /tmp and all is well! The jetty user also needs permissions on the jetty folder of course.
Also, for checking if Jetty is finding java correctly, run sudo service jetty check
It's probably an issue due to wrong permissions on some work or log folder. I assume the start script tries to change the user and therefore doesn't has the same permissions as the one you use when running Jetty via "java -jar".
Another possibility is that you don't have JAVA_HOME set and the start script doesn't find your java bin.
Please attach some kind of log file as it is really hard to say more without more detailed information.
As answered here, the default configuration for Jetty in /etc/default/jetty only allows connections from localhost, you need to set JETTY_HOST to 0.0.0.0 to allow Jetty to accept connections from any host.
Add the following line to /etc/default/jetty:
JETTY_HOST 0.0.0.0

java.net.BindException: Address already in use:8080

I am trying to run a Java webapp build instance but it stops in the middle of the build with this error:
java.net.BindException: Address already in use:8080
It's obviously trying to bind to the 8080 port but another process has already done so and wont share.
So, I checked to see what process is using the 8080 (netstat -anp | grep 8080). Apparently the jsvc.exec process is listening to my 8080 port. Upon checking (ps -fp) I find out that this is Tomcat (boostrap.jar).
So, to see if the build would at least complete, I killed the process. And yeah!! The Webapp build installed completely. But when I navigated my browser to localhost:8080 it says the service is not running - coz I killed Tomcat! I even tried localhost:8080/manager/list. Still said service not running.
So I restart Tomcat, checked localhost:8080 and Tomcat was back up. Checked localhost:8080/manager/list but did not see the Webapp instance I had just built.
What I am not getting here! My webapp wont build if I run tomcat (cant share 8080). And If i kill tomcat to complete the build, the webapp obviously cant run coz Tomcat is dead.
Please help me. Running Tomcat 5.5 in a LAMP environment on a remote server. NOTE: I am running a pre-built webapp build application (war) which I cant make changes to.
During a build? A build process usually doesn't require a port to be open. The issue is that two programs are attempting to use the same port. Without fixing the underlying issue, the immediate fix is to change the port Tomcat is running on. To change the port Tomcat runs on, edit install_dir/conf/server.xml and change the port attribute of the Connector element from 8080 to 8081.
If this is your first time running Confluence or you have recently added applications or made changes to the system, investigate what's running on port 8080.
If Confluence was not shut down properly, you can restart the machine or kill the process:
On Windows:
Hit Ctrl-alt-delete and look at open programs. Look for {{java.exe}}.
From a command window, run {{netstat -an}}. Check which ports are in use. You can identify which application is running this way, then close it from the Task Manager.

Categories