I have a jar file and i don't have source. It should connect to a server. It doesn't run at the first time and i need to run it second time. I am trying to find a way to get it's logs. How can i enable it's logs?
Here is how i call it
java -Xms512m -Xmx512m -jar mcon.jar
I have found and tried the code below but i think it is for server sockets
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n -jar mcon.jar
what you found is mostly correct but you do not need the address , that is to do remote debugging to connect to server
from command line , what you need is
java -agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n -jar mcon.jar
then you can connect java debugger
jdb -attach jdbconn
you can refer to the doc to find out the command you can use
Related
I am trying to generate a thread dump of a java process being run on a Linux instance in AWS. I am using the jstack command on OpenJDK version 1.8.0. The current command I am running is sudo -u <user> jstack -l <java pid> where <user> is the user that started the JVM.
When I run this, I receive the error Unable to open socket file: target process not responding or HotSpot VM not loaded
Potential Problem:
While reading about how jstack works, I noticed that jstack is supposed to generate a socket file /tmp/.java_pidXXX in order to attach to the process. This file is not generated.
My potential solution is that if I can get the socket file to generate, hopefully jstack will be able to run properly.
I am unsure why this error is occurring, but my only idea is that this could this be some kind of permissions error to create files in the /tmp directory. I tried testing my permissions by creating text files in the /tmp directory and I was able to create text files.
How can I get this socket file to generate? Any potential solutions would be greatly appreciated.
Edit
Here I have added the command that was used to create the JVM. The command used to get this command was ps -aux | grep java
java -server -Xmx8192m -XX:+HeapDumpOnOutOfMemoryError ->XX:HeapDumpPath="/tmp" -XX:MaxPermSize=256M -Djava.awt.headless=true ->Dsling.run.modes=dynamicmedia_scene7,,
<instance_name>,samplecontent,crx3,crx3ta>r -Djava.locale.providers=CLDR,JRE,SPI -jar crx-quickstart/app/cq-?>quickstart-6.5.0-standalone-quickstart.jar start -c crx-quickstart -i >launchpad -p 4502 -Dsling.properties=conf/sling.properties
Solution:
An update for anyone who comes across this in the future. I found a solution that worked for me by changing the command that I was using to initially start the JVM. I added the flag -XX:+StartAttachListener which forces the process to generate the /tmp/.java_pidXXX socket file during the booting of the JVM.
Other tips I came across in my journey to finding this solution:
Make sure the user executing the jstack command is the same user that who ran the process that you are trying to take the thread dump of.
Also, make sure the socket file /tmp/.java_pidXXX is not being automatically cleaned up by any background cleanup processes in the /tmp directory.
I can run kubectl get secret/rabbitmq-expressmode -n expressmode in shell successfully.
However when I try to run it in java with either ProcessBuilder or Runtime.getRuntime().exec, the error:
Error from server (BadRequest): the server rejected our request for an unknown reason
is thrown out.
What's the possible reason?
Best approach would be to use official java client library.
Installation is pretty easy, and code examples shows you how to use it.
If the official one does not meet your requirements, there are also community-maintained client libraries:
Java (OSGi)
Java (Fabric8, OSGi)
Java
I had same issue but resolved by programmatically creating bash file containing kubectl... command I was trying to execute directly.
For example, create bash file and put your kubectl command there (i.e.: some-file.sh). Then try then executing it in bash process running within your java code (bash some-file.sh).
I have a Java (Vert.x) application on my machine that I am trying to attach Eclipse to for debugging.
I usually start the Java application in my console like so:
java -jar build/libs/my-app.jar
Upon reading about debugging, I am attempting to start the app as follows:
java -jar build/libs/my-app.jar -Xdebug -Xrunjdwp:transort:transport=dt_socket,address=8001,server=y,suspend=n
The app seems to start up in the console fine when I run this.
I then go into Eclipse, and try to connect to the app via debugging via Run -> Debug Configurations. This is what my debug configuration looks like:
When I click debug, I get an error box that pops up and says that the connection is refused (I covered the name of my real app). See below:
What am I doing wrong? How can I get remote debugging to connect to my app with Eclipse?
According to my reading of this JDWP documentation, your -Xrunjdwp option is incorrect:
-Xrunjdwp:transort:transport=dt_socket,address=8001,server=y,suspend=n
should be
-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n
If your system has multiple IP addresses, there could be some confusion about which IPs the agent is listening for connections on. You could force a specific address; e.g.
-Xrunjdwp:transport=dt_socket,address=127.0.0.1:8001,server=y,suspend=n
and use the matching IP and port in the Eclipse debug connection parameters.
AND ... as Dave Thompson spotted ... all JVM options must be placed before the -jar argument. (Anything after the -jar name.jar will be treated as command line arguments for your application.)
I'm trying to debug a java program on my remote computer, which the following command:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y suspend=y -jar Test.jar
When I try remote debugging with eclipse on my local computer, I see this error on the remote computer:
Listening for transport dt_socket at address: 9999
Error: Could not find or load main class suspend=y
I don't understand since I do have a main class in the program.
P/S: I also have the same error when trying to run the jar file by
java Test.jar
The project is built with Eclipse IDE.
Can someone show me where I did wrong?
Thank you
java -Xdebug -Xrunjdwp:transport=dt_socket,address=9999,server=y suspend=y -jar Test.jar
You're missing a , between server=y and suspend=y. Even the introduction of a space in the parameters can confuse the VM.
This is the right syntax.
java -Xdebug -Xrunjdwp:transport=dt_socket,address=9991,server=y,suspend=n -jar my.jar
If your jar has the right main class attribute it should work correctly.
I have written a java program with jar file. The java program is to update status of linux server so it need to keep running, but the linux server is in data center, so I need to remote to server to open the program. I use ssh to login linux server. Use command of "java -jar file.jar" to run the program.
However, the java program of the linux server will close if I close the terminal in my computer. Since I cannot keep opening my computer, I wanna know how to open the java programming without holding my computer terminal.
you need to use nohup to keep the program running after you log out.:
server:~name$> nohup java -jar file.jar &
this will keep your program running
Two ways
One
nohup java -jar file.jar &
Another
java -jar file.jar &
In both cases your process will go in background however the process will terminate in the second approach when shell terminates in second case.
If this program is intended to be running on all your machines for monitoring purposes, you should be running it as a service from your server's init system (systemd for most systems these days). You can use the Java Service Wrapper or jsvc or write your own init script.
Another solution apart from the proposed one:
screen -d -m java -jar your.jar
You will then have a detached screen with your java command in it. List with screen -l, reattach with screen -D -RR <screenid_obtained_via_screen_-ls>