Remote debugging java - Could not find or load main class - java

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.

Related

Java on Windows command line - NoClassDefFoundError again

This question has so many answers, yet nothing works for me. I try to run a JAR file which I created and which depends on org.json library. I have my WebCfgSigner.jar and json-20180130.jar in C:\bin directory. It all works fine on my computer development computer:
java -jar c:\bin\WebCfgSigner.jar some parameters
I need to run it on my server (Windows Server 2016), where I installed first Java 1.8.something, then 17.0.2... All I get on the server is:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
I know about CLASSPATH environment variable, so I set it to all the variants below in turn, and nothing changes:
CLASSPATH=c:\bin\
CLASSPATH=c:\bin\*
CLASSPATH=c:\bin\json-20180130.jar
Then I try to add -classpath or -cp to the command line, no difference.
java -classpath c:\bin\json-20180130.jar -jar c:\bin\WebCfgSigner.jar some parameters
java -classpath c:\bin\* -jar c:\bin\WebCfgSigner.jar some parameters
java -cp c:\bin\json-20180130.jar -jar c:\bin\WebCfgSigner.jar some parameters
What else could I do? The json-20180130.jar is what works fine on my dev computer, but again not on the server...

Differences when starting selenium-server-standalone-3.141.59.jar by double click vs command line java -jar selenium-server-standalone-3.141.59.jar

I'm using selenium-server-standalone-3.141.59.jar to run some automated tests with maven.
Everything works fine when starting the Selenium server by double-clicking on that jar file.
I see that this starts javaw.exe (javaw.exe" -jar "%1" %*).
When starting the Selenium server using CMD start java -jar selenium-server-standalone-3.141.59.jar, I get the following error:
Unable to create new service: ChromeDriverService
I think this is related to variables inherited by CMD cause even if I change the command to
start C:\"Program Files (x86)"\Java\jdk1.8.0_151\jre\bin\javaw.exe -jar src\selenium-server-standalone-3.141.59.jar
Can someone explain what are the differences between running the jar by double click vs from command line?
Thanks

Remote debugging in java error

I want to do remote code debugging. So I ran below command in my remote machine:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8998,server=y -jar myapp.jar.
Then I created debug config in eclipse. But I am getting a error in remote machine stating:
Could not find or load main method
I have set the buildpath of eclipse correctly. The jar has the manifest which states the correct main method in jar. Still I am facing this issue. So what am I doing wrong?
Thanks.
First, does the program by itself run correctly?
I mean, in the remote machine: java -jar myapp.jar
Second, the parameters you have used are typical for JRE1.4.
For a more advance Java version, take a look here:
Remote debugging a Java application

Debugging a java jar file

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

Remote debugging in eclipse issue

echo "LSE Parser v1.0"
javac -d ../build -classpath ../build:${MY_CLASSPATH} *.java
cd ../build
jar -cf ../lib/lse.jar .
cd ../src
The above is my build script for a java application. there is a serperate run file which has all the CLASSPATH defined and runs the application.
I am trying to remote debug the application on eclipse but facing issues. The code is sitting on unix server host. i've closely followed instructions about debug configurations... for eclipse.
This is what I'm doing:
I locate my build (above) in putty terminal and execute with . ./build
I type java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999
On eclipse debug config... I enter a random name, project is lse, gave correct host and gave port number as 9999. checked termination of remote VM. When I click debug, it does not stop on the breakpoint.
NOTE: in the project "lse" are 3 .java source that the application uses. the "lse" project has only src content, however in the Unix host it has all the lib, scripts, config folder.
Please can someone tell me what I'm doing wrong. after step 2, I managed to get
Listening for transport dt_socket at address: 9999
then after step 3, I get some messages on putty
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is server,
because you are running on a server-class machine.
....
and see on eclipse a terminated status on debug mode. java hotspot server [host bla bla]
I imagine you solved this by now...but looks like you forgot to provide the name of the class for java to run. If your main method was in a source file like foo/Bar.java, then you would need to add foo.Bar to your java line. Something like:
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9999 foo.Bar
You might also consider adding -g to your javac to generate debug info.
You could avoid all (or most) of this pain if your source was in the IDE that you're trying to debug with...

Categories

Resources