Is it possible to debug PL/Java (ideally from Eclipse)? - eclipse

Although I found PL/Java a powerful add-on for PostgreSQL, I couldn't find a way of remotely debug the clases loaded on the PSQL DBMS.
Is this possible to achieve?
Thanks in advance!

I suppose you could set pljava.vmoptions to enable debugging and include a port number to listen on, and then use Eclipse's "debug remote application" launcher to connect to it.
So a JVM option -agentlib:jdwp=transport=dt_socket,suspend=n,address=localhost:55000 will make the JVM listen on port 55000 for debuggers. You then open the "Debug configurations.." dialogue in Eclipse, right click "Remote Java Application" in the launch types pane on the left and update the connection properties on the right to use port 55000. You should connect up the debug launcher with a project as well, to pick up that project's class path and sources.
Note I haven't actually tried this in postgresql, but this corresponds to how I always used to run JBoss from a shell script rather than from within Eclipse.

I needed a slight change to the option line. The working one is-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:8000. Without the server=y part, the debugger complains about missing transport. With the above, everything worked.

Related

how to setup a debugger for AEM or CQ?

how to setup a debugger for AEM or CQ? I'm using Eclipse IDE and Maven 3.2.5 for build and AEM version 6.0. I'm new to AEM and Java.
This Adobe article walks you through it: https://helpx.adobe.com/experience-manager/kb/CQ5HowToSetupRemoteDebuggingWithEclipse.html
Step 1: Add the Remote Debugging JVM Parameter
To use remote debugging, you must start CQ5 with this JVM parameter:
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
You can add the parameter by doing the following;
Start your server like this: crx-quickstart/bin/start -d --debug-port 8000. The -d parameter adds the jvm parameter to the CQ5 java process.
Add it to your crx-quickstart/bin/start script CQ_JVM_OPTS environment variable (so your server always starts in debug mode).
Include it as a parameter when starting CQ5 with java -jar directly. For example, java -Xmx512m
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -jar cq-author-4502.jar
Notes
If necessary, you can change the port defined under "...,address=8000,..." from 8000 to something that works better in
your environment.
Starting CQ 5.5, using the last solution, when Quickstart forks a new process it does not start the JVM with the debug options. You can
prevent forking by specifying the -nofork command line option.
Te start script is located under crx-quickstart/server for CQ versions < 5.5
Step 2: Start a remote debugging session
To start a remote debugging session from Eclipse, do the following:
Open Eclipse.
Choose Run > Debug Configurations.
Right-click Remote Java Applications and select New.
Select your CQ5 project under Project.
Type in the port from the "address" configuration of the jvm parameter defined above. In the example, it is port 8000 (and the host
name of the machine you are connecting to, most likely localhost)
To start a debugging session, double-click your new configuration in the Debug Configurations screen after saving it.
Applies to: CQ 5.x and Adobe Experience Manager 6.x
If you're on windows follow these steps.
Open AEM crx-quickstart, move onto bin, open start.bat(Right click and edit), find default JVM options, add the line
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=3000 next to headless=true in the start.bat file, save it. Open cmd in the bin folder. Type start.bat and hit enter which will open the instance with debugging port 3000.
Open Eclipse. Add breakpoints to the java file. Run > Debug Configurations > Remote Java Application, right click and select New Configuration, provide a name, select project(the one with .core), change port to 3000, apply and debug. Change the perspective to Debug, Window > Perspective > Open Perspective > Other > Debug.
Open AEM Page containing the component which uses the java class for which the breakpoints have added. If you’ve added breakpoints for the HelloWorldModel.java, open the page with helloworld component or refresh if already opened. And that’s it, eclipse will notify and the program will be paused at the breakpoint.
Possible Errors you might encounter with:
Failed to connect to remote VM. Connection refused. Connection
refused: connect
The debugger has already started when you hit apply and debug and trying to run the debugger again will get you this error.
Debugger not pausing at breakpoints and no notification in eclipse.
If the instance was already running and you hit start.bat in cmd, you’ll find this unusuality. Close the instance, and enter start.bat(in the bin folder). You’ll find the message below when the instance is ready. It might or might won’t open the browser by its own. So just open the browser and enter http://localhost:[portnumber]/.
SUCCESSFULLY LOADED validation.properties via the CLASSPATH from ‘/ (root)’ using class loader for DefaultSecurityConfiguration class!
RAWProcessor succesfully installed
17.10.2019 12:59:41.437 *INFO * [main] Startup completed
Step1: Start AEM service in debug mode with -debug parameter and a port number.
Step2: Setup debug configuration in IDE with the above port.
References:
How to start AEM in debug mode?
CQ5How To Setup Remote Debugging With Eclipse

Eclipse CDT Remote Debugging ("Attach to Applicaton" or "Remote Application")

I just created a Amazon EC2 due to limited ram size on my workstation. Thus I need to figure out how to conduct remote debugging on this remote instance.
First of all, I am not quite sure I understand the difference between "Attach to Applicaton" or "Remote Application" in debugging configuration tab. From what I've learned, the first one is just using Eclipse as a front-end GUI to connect a remote gdbserver. But I have no idea what the second one means.
Right now I can connect to the gdbserver on my EC2. However, gdbserver gives me a warning message
Could not load vsyscall page because no executable was specified
try using the "file" command first.
I've already defined the executable as well as project in Eclipse's debugging page. Is there anything I missed?
I have done the same thing some time back and it was working absolutely fine and I have mentioned all the step in my blog. Check the link for detail description.

Passing proxy settings to a bundled JRE install4j application?

We provided an application installed with install4j, with bundled JRE, to one of our customers. This customer needs some proxy settings configured manually for this application.
I tried to put deployment.config file in the JRE's lib directory but it didn't seem to change anything. I couldn't find a relevant vmoptions either.
Is there a way to pass these settings to the app/jre?
Is there also a way to instruct the JRE to open the Java console when it runs?
Thanks!
/Shmulik.
You can configure the proxy by setting the VM parameters
proxySet=true
proxyHost=...
proxyPort=...
and for authentication
proxyAuth=true
proxyAuthUser=...
proxyAuthPassword=...
You can set them either in a "Run script" in the startup node of the installer action by calling System.setProperty() for the properties or by passing them on the command line like this:
-DproxySet=true -DproxyHost=... etc
As for your second question (better to ask a separate question on stackoverflow)
Is there also a way to instruct the JRE to open the Java console when it runs?
I assume you mean a terminal window, which can be done by selecting the "Windows console executable" property of the installer. You cannot change this property on the command line because this sets a static flag in the binary format of the Windows executable furing compilation.
I created an installer for WINDOWS as well as for MAC. The
application is using an embedded JRE. While the application runs, it's not
able to detect the proxy settings of the network even the option in
the browser is set to be "Auto Detect". But when the proxy settings provided explicitly in the browser, it's able to detect the proxy settings.
Even the proxy settings are not detected when "LAN Settings->Use automatic configuration script" option is selected and points to the .pac file.
Any suggestion, how to provide the proxy settings with BUNDLED JRE and java program can detect those settings without make any further changes in each machine.

How to run build using graphics drivers by using optirun (Bumblebee) from IDE (Netbeans, Eclipse)?

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 !

Timeout with GWT

I received a new computer at work today and for some reason all of my GWT programs are timing out when I try to build them in eclipse.
Specifically I am seeing this message:
INFO: Unable to access http://appengine.google.com/api/updatecheck?runtime=java&release=1.3.5&timestamp=1277158890&api_versions=['1.0']
java.net.ConnectException: Connection timed out: connect
I tried to build just the basic sample project and it does the same thing. I am behind a proxy, but I have set up all the correct information in eclipse (i think). I don't understand what else it could be though.
Any suggestions?
Try this:
Right click your GAE project, Debug As>Debug Configurations...
In the dialog window, select (x)= Arguments tab
In the VM Arguments part, add in the end
-Dhttp.proxyHost=<your proxy server> -Dhttp.proxyPort=<Proxy port>
try to debug application, it should work now.
Looks like it's a firewall issue - check that your firewall allows java to connect to the network, or that the proxy settings are correct.
It actually ended up being a jar file that was not included in my classpath for some reason. Like I said I was building these projects from scratch again so I must have forgot that one. Thanks to all who answered.