How to debug a .jar file remotely using Intellij Idea - java

I am currently using intellij idea to code my project that I am working on, after creating of .jar file using OneJar command i deploy the .jar file on my linux server who address is something like 192.164.1.125.there I run the command sudo nohup java -jar fileName.jar & on server to start the jar file in the background and use the rest-client app to send rest calls to my .jar file.Whenever something goes wrong I can only see error message in nohup.out file and what I actually wanted is to debug my jar file using intellij idea i.e how can I debug my .jar running on 192.164.1.125 using intellijIdea running on my client machine.I know I have to use that EditConfigurations option in run menu of intellij and provide IP and Port, but how to do it exactly.

You can do the remote debugging on IntelliJ IDEA 2019.2 version very easily!
Click on "Run" -> "Edit Configurations"
Click on "+" and select "Remote"
Enter your remote IP and select source code folder path
Optional : change the name and port of your wish
Run your remote server jar with the command which is mentioned in the Command line arguments for remote JVM box .
something like this,
sudo nohup java "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8911" -jar fileName.jar &
You are all set. add the breakpoints and click on Debug symbol to debug your remote jar from local

You must run the remote "java -jar .." command in debug mode by adding the additional magic flags. You can then tell your local IntelliJ to create a new debug configuration targeting a remote application - IntelliJ provides the magic flags you need.
The help page for this feature is at https://www.jetbrains.com/idea/help/run-debug-configuration-remote.html

Related

Cannot open .jar files with java installed (windows 11)

Environment: Windows 11
Problem: cannot open .jar file(the MARS assembly language simulator)
Hello, I am currently trying to install the MARS assembly language simulator. It is a .jar file so I downloaded java to open it. However, I still can't open the file even with java downloaded.
I checked if java was installed using my cmd:
Command prompt showing java successfully installed
I tried double-clicking it did not work. So I right-clicked it to open with other apps. But I did not see java in the given options.
Cannot find the java option to open the file
Thank you so much for helping!
Use your prompt
CD into the directory with the jar
then execute
java -jar Mars.jar
...any more troubles , open file properties tab with right click on the jar and check permissions to execute the file.
Installing Java usually means installing a JVM, which is a Java Virtual Machine. You won't be able to launch files from a Windows context menu like this, because "Java" is not a program that opens files.
Instead you need to:
Either a terminal and call javaw.exe with the parameters -jar and your .jar-file. E.g.:
C:\your\java\binaries\javaw.exe -jar -SomeJarFile.jar
Or add the Java installation to your environment variables, then you can call javaw.exe without providing some specific path

How to enable remote debugging for an Eclipse Application?

Im trying to enable remote debugging for an eclipse plugin project, for the purpose of using IntelliJ IDEA as a debugger.
The steps I've taken so far:
Launch Eclipse.
Run -> Debug Configurations...
Create a new "Eclipse Application" (as to launch a local workspace which loads the plugin).
Add -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n to VM arguments.
Press the Debug button.
I get the following error:
ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
Error occurred during initialization of VM
agent library failed to init: jdwp
What steps should I be taking to get IntelliJ IDEA to be able to debug an Eclipse Plugin running in a runtime workspace?
Run -> Debug Configurations...
Add -Xdebug -Xrunjdwp:transport= dt_socket,address=1044,server=y,suspend=n to VM arguments.
This is redundant. Using a debug configuration already starts the application with the eclipse debugger attached to the process. Start it as a run configuration instead if you want to enable debugging through a server socket.
You can then create an additional "remote java application" debug configuration to attach to that socket.
I would suggest you NOT try to launch the Eclipse app from within Eclipse.
Export the app to be a stand alone eclipse application.
Modify the eclipse.ini file and add the necessary debug parameters to the '-vmargs' entry.
Launch the stand alone app as you normally would.
Attach the development Eclipse instance to the test app as you would normally do for a remote debug.
Tomcat Configuration:->
By default remote debug happens at 8000 port.If you want to change this then go to catalina.bat file and update this line
set JPDA_ADDRESS=localhost:8000 to desired port no.
And you can also set this property in setenv.bat file. Generally this file is not there in tomcat so just create one batch file with name
setenv and write this line set JPDA_ADDRESS=localhost:8000.
Now go to bin directory then open command promt and write "catalina jpda start". It will make the tomcat run in debug mode. You can verify it
by seeing something like this "Listening for transport dt_socket at address: 8000"
1)Eclipse
Go to run->debug configuration->Remote Java Application->Click on new Launch configuration
And then fill the detials like project ,port(Give same port no as you have configured in tomcat), host(If you are using local you can give
local then apply and debug
I am using eclipse 2020.09 .
Eclipse remote debug img
2)Intellij Idea:
Go to Add configuration->click on +->and select remote jvm debug->Then give the same port no and name(any name) then apply.
Intellij Idea Remote Debug img

error when trying to run Google app engine- Usage: <dev-appserver> [options] <war directory> [duplicate]

I want to try the Google Eclipse plug-in for the Google App Engine, but I get stuck in the tutorial...
I want to start the web application from the Google tutorial, but when I click on "RUN AS > Web Application", I only see this message on the console:
Usage: <dev-appserver> [options] <war directory>
Options:
--help, -h Show this help message and exit.
--server=SERVER The server to use to determine the latest
-s SERVER SDK version.
--address=ADDRESS The address of the interface on the local machine
-a ADDRESS to bind to (or 0.0.0.0 for all interfaces).
--port=PORT The port number to bind to on the local machine.
-p PORT
--sdk_root=root Overrides where the SDK is located.
--disable_update_check Disable the check for newer SDK versions.
What's the problem? It seems like the command to start the server is wrong, but I haven't edited it... can someone help?
It is because your launch configuration file (location: WORKSPACE/.metadata/.plugins/org.eclipse.debug.core/.launches)is corrupt. All you need to do to solve this problem is to delete the existing launch configuration (in Run > Run configurations)
Check if your Eclipse Project or GAE SDK has spaces in the path.
The problem occurs when using blank spaces in the project name.
"Run Configurations> Arguments > Program Arguments", insert quotation marks in the project path. i.e.:
--port=8888 --disable_update_check {PATH}\My Project
To:
--port=8888 --disable_update_check "{PATH}\My Project"
I found it from this thread
Thanks a lot
Some additional information to what's already been said.
You need to install "m2eclipse" otherwise you will not have the "run as" option.

Using Bumblee (Graphics Drivers) with Eclipse IDE [duplicate]

Does anyone know how to make eclipse or netbeans use the graphics card in optimus laptops by invoking optirun (bumblebee) inside the IDE so that one can just use the run button in the IDE to run the program in a graphics card within the IDE.
In simplest form I just want the IDE to do the equivalent of optirun ./javaproject
The way I did this in Eclipse was to first start the Java debugger jdwp and listen to a port. Then start the JVM with optirun java ... and use jdwp to connect to this port. Both tasks can be started at the same time in Eclipse by creating a Launch Group in the debug configuration settings (Run -> Debug Configurations). In detail:
Create a Remote Java Application debug configuration with "Standard (Socket Listen)" Connection Type and some arbitrary port, e.g. 56789. This attaches the Java debugger jdwp on port 56789 to a virtual machine which accepts debug connections at this port.
Now we need to start a JVM with optirun. This can be done with a External Tool Configuration (Run -> External Tools -> External Tool Configurations). Create a new Program configuration in the left side of the External Tools Configurations window. You could directly start optirun java <additional arguments> by filling in the required fields. However, I have decided to use a shell script which is reusable by different projects (As can be seen below, there is one part missing to make it entirely reusable. I'm glad for any help from more experienced Eclipse users...). Hence, the Location field points to this shell script. The script itself accepts three arguments: the classpath for the project, the name of the Java executable, and the port number. These arguments can be passed to the script in the Arguments field of the Main tab, e.g.
${project_classpath:${selected_resource_name}}
ExecName
56789
The shell script looks like this, assuming optirun is in your PATH:
#!/bin/sh
CLASS_PATH=${1}
JAVA_EXECUTABLE=${2}
PORT=${3}
# TODO: fix this java library path: pass it as an argument as well. Is there an Eclipse variable which stores this?
JAVA_LIBRARY_PATH=/usr/local/share/OpenCV/java
#------------------------------------------------------------------------------
optirun ${JAVA_BIN} -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:${PORT} -Djava.library.path=${JAVA_LIBRARY_PATH} -Dfile.encoding=UTF-8 -classpath ${CLASS_PATH} ${JAVA_EXECUTABLE}
#------------------------------------------------------------------------------
Finally, the two pieces are brought together in a Launch Group in the Debug Configurations window (Run -> Debug Configurations). Create a new Launch Group and add the two previously generated Debug configurations by clicking on Add in the Launches tab and by selecting the appropriate configurations.
Note that due to the classpath variable in step 2 (i.e. ${project_classpath:${selected_resource_name}}), the appropriate package needs to be selected in the Package Explorer before clicking on the run debug configuration button (make sure that the Launch Group is selected).
This solution works perfectly for me: I can debug Java code inside Eclipse which calls native code involving CUDA optimizations and Bumblebee only activates the discrete graphics card when necessary.
Just use optirun to start the IDE. For example, optirun eclipse or optirun netbeans
I build the project in Netbeans (F11) and run the following in a terminal:
optirun java -jar path/to/javaproject/dist/javaproject.jar
Mind that if you have any java parameters in your project, you need to add it manually. My workflow is like this:
Locate the Java options from the project, open Project -> Properties, Run. At VM Options I see -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux. I also have some parameters that I want to pass to main(String[]). With this information, I open a terminal and run:
cd path/to/javaproject
optirun java -Djava.library.path=lwjgl/native/windows;:lwjgl/native/linux \
-jar dist/javaproject.jar some paremeters
Another hint, if you have to open and close the program frequently, run optirun bash in a different tab so that preparing the use of the graphics card becomes faster. Alternatively, you can run optirun netbeans, but that means that the nvidia card will always be on even if you are programming which increases power use and increase the heat.
Important: if you are using a 32-bit JVM or Java libraries on a 64-bit machine, you also need to install the 32-bit drivers and libraries. For Ubuntu, the nvidia package already contains 32-bit drivers, see this answer. For other distros, you likely need to install lib32-* packages for Mesa, VirtualGL and nvidia-utils.
You can also rename java to java_real and use this portion of code as your java command :
#!/bin/bash
path=$(dirname $(readlink -f $0))
args=""
runner="$path/java_real"
for var in "$#"
do
if [ "$var" = "-3d" ]; then
runner="primusrun $runner"
else
args="$args $var"
fi
done
$runner $args
NOTE : I had to do this in /usr/lib/jvm/java-7-openjdk-amd64/jre/bin, not in /usr/bin to make it work with Eclipse.
In Eclipse, just add "-3d" in your program arguments and you're good to go !

Unable to start google app engine server [duplicate]

I want to try the Google Eclipse plug-in for the Google App Engine, but I get stuck in the tutorial...
I want to start the web application from the Google tutorial, but when I click on "RUN AS > Web Application", I only see this message on the console:
Usage: <dev-appserver> [options] <war directory>
Options:
--help, -h Show this help message and exit.
--server=SERVER The server to use to determine the latest
-s SERVER SDK version.
--address=ADDRESS The address of the interface on the local machine
-a ADDRESS to bind to (or 0.0.0.0 for all interfaces).
--port=PORT The port number to bind to on the local machine.
-p PORT
--sdk_root=root Overrides where the SDK is located.
--disable_update_check Disable the check for newer SDK versions.
What's the problem? It seems like the command to start the server is wrong, but I haven't edited it... can someone help?
It is because your launch configuration file (location: WORKSPACE/.metadata/.plugins/org.eclipse.debug.core/.launches)is corrupt. All you need to do to solve this problem is to delete the existing launch configuration (in Run > Run configurations)
Check if your Eclipse Project or GAE SDK has spaces in the path.
The problem occurs when using blank spaces in the project name.
"Run Configurations> Arguments > Program Arguments", insert quotation marks in the project path. i.e.:
--port=8888 --disable_update_check {PATH}\My Project
To:
--port=8888 --disable_update_check "{PATH}\My Project"
I found it from this thread
Thanks a lot
Some additional information to what's already been said.
You need to install "m2eclipse" otherwise you will not have the "run as" option.

Categories

Resources