Remote debugging(NOT localhost) tomcat using eclipse. Connection refused from remote machine - java

I have started tomcat with jpda option in a remote machine(not localhost). I was not able to access the port. It throws a connection refused. I was able to do this in localhost successfully. Then why not from a remote machine. I am using tomcat 9.X and ubuntu 16.04 and java 8
Edit 1:
The JDWP port 8000 listens only to 127.0.0.1. Is it possible to change this?

Finally, I found the issue. By default Catalina.sh(Tomcat script) binds only to localhost. If you want to access from another machine, then do
export JPDA_ADDRESS=0.0.0.0:8000
sh catalina.sh jpda start
0.0.0.0 allows from all the interfaces. You can also configure to one IP.
Another working solution is to do ssh tunnel from the remote machine to debugger machine.
ssh -L 8000:localhost:8000 user#remotemachine
If you still face any issues, then check the firewall. In ubuntu you can do it using UFW(Uncomplicated firewall)
sudo ufw enable
sudo ufw allow 8000

Related

How to make port 8080 free for Tomcat in ubuntu 20.04 LTS

I am using Ubuntu 20.04 along with JDK-8.
I have installed Tomcat9 for making Web Application in net-beans but when ever i start tomcat9 it shows port 8080 is busy.
I ran following command
# netstat -tulpn | grep 8080
and killed the process using
# kill -9 <process_id>
but after that when I start tomcat9 it shows the server port 8080 is already in use. and I again killed the process but another process again starts on port 8080 immediately and I can't start the Tomcat9.
I tried by changing port number but still error is same.
Can anyone tell me where's problem occurring and what should i do now?
This is most likely a service configured to be restarted if it crashes.
Figure out what sits on the port and disable the service or remove the package completely.

Tomcat does not listen on configured JMX port

On my Windows 10 PC I try to get JMX working on my local Tomcat9 installation which I start via Netbeans.
I added this line to catalina.bat
set CATALINA_OPTS="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
but without success. netstat /an does not show port 9000 listening and of course I can't connect using VisualVM.
When I check the local tomcat in VisualVM, I can see that my options are used though.
Tomcat overview in Visual VM
What am I missing to get access to JMX? Any hints are highly welcome.
Harry.

Adding Java to Boot2Docker Linux VM?

I have images which are based on Alpine Linux with only JRE, and I'd like to be able to debug some through the host machine on Boot2Docker's Tiny Core Linux VM. Is this possible, or is there a better way, besides adding JDK right into the container? I'm having trouble finding out how to get Java working in this
There's no need to install Java in the boot2docker VM. You can attach a remote debugger running on your host directly to the JVM running in your docker container. You'll need to bind the container port to the boot2docker VM (for example: docker run -p 4000:4000 myimage:latest), then connect your debugger to the exposed port on the VM (e.g. 192.168.99.100:4000).

Failed to Start Apache tomcat from eclipse juno in linux at port 80

At the window platform I have run tomcat from eclipse juno. But at linux I face this problem
When I run web project from eclipse I got this error message, while from command line I can able to run tomcat.
Error Message is - Port 80 required by Tomcat v7.0 Server at localhost
is already in use. The server may already be running in another
process, or a system process may be using the port. To start this
server you will need to stop the other process or change the port
number(s).
I already check my port using nmap and other command
The main point is that when I run tomcat from command line then it start, but when I start this from eclipse I got this error
First, check again whether the port is indeed in use. I believe that you have apache web server (httpd) that is taking the port.
Second, on linux only processes running under root user can use lower ports (under 100). Probably when you run tomcat from command line you run it as root (e.g. using sudo), however when you are running it from eclipse it is running under your user.
The solution is:
for development use other port. E.g 8080.
For production:
use special user account (not root) to run tomcat. E.g. user named tomcat. Configure it to listen to port 8080. Run apache web server (httpd) under root user configured to listen to port 8080 and configured to be connected to tomcat using mod_jk. This is most secure and reliable commonly used configuration.
After starting Tomcat from the command line you also stopped it? Because if Tomcat is still running from the command line you get this error while trying to start it again out of eclipse.
Is it right that you run your Tomcat on Port 80? This wont work in an Linux environment, because Linux comes up with an Apache Webserver listening on Port 80.
I believe linux comes with a apache server, which may be running on port 80. So when you try to run the tomcat on the same port, it is complaining port already in use. To find out if apache is installed you can use the rpm command. I believe it is rpm -qa will tell you all packages installed. Now as far as the directory for apache files it is normally
/var/www/htdocs.

How do I monitor Tomcat6 with JVisualvm in Ubuntu Linux?

I'm trying to set up JVisualVm to monitor a Tomcat 6 instance (running on Ubuntu Server 10.04 LTS). I've seen other questions, but none of them directly answer my problem. I try to connect to Tomcat with JVisualvm and it comes back with a "Cannot connect" error - but there are TCP connections being made to the server; the server drops the connection after a short burst of traffic.
I have already added this to /etc/default/tomcat6 and restarted tomcat6
# This enables JMX in order to permit VisualVM to profile the JVM.
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
I started rmiregistry using default settings:
rmiregistry &
I haven't started jstatd; installing it on the server requires the full JDK which requires X libraries. I'm not about to install X just to get one single binary.
I wonder if not running jstatd would have something to do with it; I was of the impression that I needed neither RMI nor jstatd, as long as I could use JMX directly via the JMX port.
There is no firewall in between the server and the JVisualvm client, and the iptables host firewall is open. Using jconsole results in the same error.
Running JVisualVM against the local Ubuntu 10.04 machine (by using its IP address and JMX port) and adding a JMX instance works fine - and I'm running neither rmiregistry nor jstatd - though the monitor shows RMI threads running.
Question: What must I do (either on the server or the client) in order to be able to monitor Tomcat (and other Java programs) via JMX with JVisualVM?
Thanks in advance.
If there is no firewall, try to set java.rmi.server.hostname system property for your Tomcat. Add this to your Tomcat's JAVA_OPTS:
-Djava.rmi.server.hostname=<IP address of Ubuntu Server>
You don't need to start rmiregistry and you don't need to run jstatd to be able to monitor your Tomcat remotely.
For the record: jstatd does not require X libraries, it only depends on them via some other recommended package. You can make aptitude or apt-get skip installation of recommended packages and have jstatd installed without any X11 libraries.
For aptitude, go into options ➞ preferences ➞ Install recommended packages automatically. For apt-get, see this question on askubuntu.

Categories