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
Related
I have a Java Code where I am able to run it on Intellij using custom configuration. The configuration has following attributes :-
module : java 8 (Oracle OpenJDK 1.8.0_321)
classpath : -cp XYZ.main()
main : com.ABC.XYZ.ManageTraffic
CLI arguements : server XYZ.yml
But when I try to run the jar that was build using gradle from terminal , it gives me Error , could not find or load main class com.ABC.XYZ.ManageTraffic
So far I have tried the following things looking at other solutions at Stackoverflow , still getting the same error
java -jar ques.jar
java -jar ques.jar com.ABC.XYZ.ManageTraffic
java -cp /build/libs/ques.jar com.ABC.XYZ.ManageTraffic
Just to cross check , I unzipped the creataed jar and found that com.ABC.XYZ.ManageTraffic class file is available there , still getting error. What could be the issue?
Run it from the IDE, and while it is running, try to get the command used by the IDE from the process list.
not sure what OS you are using but something like this should work on linux/mac:
ps -ef | grep java
After you have the command you can try to understand why its not working for you, or just use that command
Just want to add how I managed to run it. I created a new shaded jar file of the same application. refreshed its dependencies and now it works. I am yet to find out how creating a shaded jar instead of normal jar helped. Right now the only reason I could figure out is there may be version clashes with some dependencies but I wonder how it could throw could not found main class error.
Anyways , then I ran the file with the following command from terminal:
java -jar ./build/libs/ques-shaded.jar server XYZ.yml
I am helping on a project which consists of a Docker stack with a bunch of services all working together. All of them start except for one.
Using docker service ps my-service --no-trunc gives me: task: non-zero exit(1)
Using docker service logs my-service gives me: Error: could not find or load main class
This particular container has a Java application running in support of a NodeJS server. After npm install, npm run init, npm run build, and mvn clean install, I was able to successfully build the Docker image. No errors.
However, now it's not actually starting. I can't figure out how to diagnose it any further. The error message doesn't tell me a whole lot. The Java code is old, but it should work, I never touched it.
Mainly, I don't know where to progress from here. Google searches turn up only stuff where they have access to a lot more debugging information, and I just don't have enough to go on. Java is not my strength. What am I missing?
UPDATE 3/21/19: Thanks to #VinDev, I was able to get some more detailed information (it should've been obvious to me to try this, but it's good to learn).
Used docker run --name TestMyContainer -it my-image bash to start up the container, then ran the normal starting command for the container in the stack, which is catalina.sh run. That gave me the following output:
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /docker-java-home/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Error: Could not find or load main class
UPDATE #2 3/21/19: I was able to solve the issue. I should've included more information: I'm on a Windows machine, but making Linux containers. I found the answer here: Tomcat startup - Error: Could not find or load main class
Windows had reverted the setenv.sh file to CRLF EOL. I changed it back in Visual Studio Code, ran the container again, and everything works!
Run docker service ls to see if the service shows up ...
also run docker service inspect my-service
This should give you a container id you can use to get the logs
docker logs CONTAINER_ID
You can also run the container by itself
docker run IMAGE_NAME
to see the result of just running it as a container
/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Seems it can't find bootstrap.jar or tomcat-juli.jar
Maybe not being copied by Dockerfile?
I added this to the original post, but adding it here as well to properly mark the question as answered:
I was able to solve the issue. I should've included more information: I'm on a Windows machine, but making Linux containers. I found the answer here: Tomcat startup - Error: Could not find or load main class
Windows had reverted the setenv.sh file to CRLF EOL. I changed it back in Visual Studio Code, ran the container again, and everything works!
I am trying to run the 'TableauSDKSample' java program on an Amazon EMR machine running Linux (64 bit) using my own custom jar. When I try to run my program, I get the following error:
A fatal error occurred while creating the extract:
Hyper Server did not call back on the callback port: process = 30320
Printing stack trace now:
com.tableausoftware.TableauException: Hyper Server did not call back on
the callback port: process = 30320
at com.tableausoftware.hyperextract.Extract.<init>(Unknown Source)
at com.samsung.tabluea.TableauSDKSample.createOrOpenExtract(TableauSDKSample.j
ava:119)
at com.samsung.tabluea.TableauSDKSample.main(TableauSDKSample.java:234)
Exiting now.
Here's what I did:
I downloaded the Extract API for C/C++/Java (64-bit) (.tar.gz file)
I untarred the above file in install-dir using tar -xvzf
extractapi-linux-x86_64-10-5-0.tar.gz
I created a jar using maven
for my very simple custom project having only one file
TableauSDKSample.java
To install the shared libraries, I copied all
the files from
install-dir/hyperextractapi-cpp-linux-gcc-x86_64-release-2017.4.0.127.r9c0f968e/lib64/tableausdk/
to /lib64/. By doing this, I avoid setting LD_LIBRARY_PATH
explicitly. See this for details: https://software.intel.com/en-us/articles/install-a-unix-including-linux-shared-library
Then I tried to run my program using
the following command:
sudo java -cp install-dir/hyperextractapi-cpp-linux-gcc-x86_64-release-2017.4.0.127.r9c0f968e/lib64/tableausdk/:install-dir/hyperextractapi-cpp-linux-gcc-x86_64-release-2017.4.0.127.r9c0f968e/lib64/tableausdk/Java/:/path/to/my/custom-jar.jar fully.qualified.MainClass
(where my main class is TableauSDKSample)
There is definitely no issue with the code as it is running on my local system where I use Eclipse IDE to run it. What am I doing wrong?
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 try to deploy java on Heroku. I follow the steps on Heroku
,But I get error on
java -cp target\classes;"target\dependency\*" HelloWorld
the error is :
Error: Could not find or load main class HelloWorld
How can I solve it? Is it case sensitive?
I found helloworld key word in pom.xml, so I try to change it to HelloWorld. It still does not work. btw, I am running windows 7(64 bit) with jdk1.7.0_05.
Looks like you are using Windows-style path for the -cp flag. Heroku runs on Linux, so you probably need to change that to java -cp target/classes:"target/dependency/*" HelloWorld in the Procfile you are deploying to Heroku.
For any avid readers who are trying to follow Heroku's getting started tutorial and are attempting to deploy locally and are receiving this error...
It is likely that you haven't built the target classes locally (they don't explain it very well in the tutorial).
If you are following the getting started guide with Maven then execute the following maven command in your project root folder to build your target locally:
mvn clean install
After that the local deployment commands like:
heroku local web -f Procfile.windows
should work as expected. (Obviously substitute Procfile.windows with just Procfile if you are not deploying under Windows)
You should then see something like:
Started ServerConnector#4d29c891{HTTP/1.1}{0.0.0.0:5000}
and can access your application locally by navigating to localhost on the port that was displayed:
localhost:5000