Running a Java project remotely - java

I've got this new project at work. We are using Eclipse for the project. There are two run configurations, server and client. I have to launch the server and the client independently, and connect to the server using the client. Now, it so happens that this has to be done on both Windows and Linux. (four possible combinations: WS-LC, WC-LS, WS-WC, LS-LC, where W-windows, L-linux, C-client and S-server)
I have Linux on my machine (in which Eclipse is running) and run Windows on a VM. Is there a way I can make Eclipse launch the application in the VM?
I understand I have to build the application locally to a shared folder and send a launch command to windows (using openssh?, not sure). What are the best practices used in this scenario.
EDIT: I need to use this during development, to test my changes to the code. The same application provides both client & server. (yes, horrible, i know :X )

You can publish the server functions as JMX Beans using the MBean interface standard. Then use JMX Console to remotely connect to the server JVM and launch the application.

Eclipse has integration points for remote servers, look to "tomcat configuration" for an example of how it integrates with one remote server.
Whether your application can use an existing server integration solution or not depends heavily on details which aren't present. If you want to actually launch a stand-alone Java process from your remote machine, you generally need a program to capture the request and launch the process.

Related

Run application on server by application on client computer

I have an Linux server, and i have 2 Java applications.
1- ServerApp.jar. This application is on my server.
2- PcApp.jar. This application is on my computer.
May i make ServerApp.jar application run, by click on button in PcApp.jar application?
There are ways to download and execute the remote jars at client place.
But for your problem of invoking some operation on remote machine itself, you'll have to fall back to RMI or services implementation on server side and trigger them inside PcApp.jar

How to debug a jar remotely from netbeans

I'm trying to figure out how to debug my jar that is running remotely. Here is my scenario:
My .jar will be running from a VPS. This jar basically runs a server
for a game, so it also connects to a mysql db. I start the server with 3 .bat files that looks something like this:
set CLASSPATH=.;dist\aries.jar;dist\mina-core.jar;dist\slf4j-api.jar;dist\slf4j-jdk14.jar;dist\mysql-connector-java-bin.jar
java -Xmx500m -Dwzpath=wz\ -Djavax.net.ssl.keyStore=filename.keystore -Djavax.net.ssl.keyStorePassword=passwd -Djavax.net.ssl.trustStore=filename.keystore -Djavax.net.ssl.trustStorePassword=passwd net.world.WorldServer
pause
What I want to do is start the server on the vps like normal, but debugging the server on my local machine via Netbeans IDE. I don't know if this is possible because people will be connecting to the server (although, I will be debugging a test server which will only have me online).
Note: I have done a lot of searching before coming here and a lot of what I found had to do with using xdebug & php which has doesn't have much to do with my situation (I don't think)
-Thanks
There's a NetBeans FAQ page about this.
In brief:
Add the remote debugging options to your Java command. For example:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n
Then, use the attach debugger option in NetBeans and select your server and the port you used above (8888). It's pretty much that easy.
You may want to think about network and firewall considerations, as you may have noticed there are no passwords involved, so anyone who can connect to the port can debug your app. This could be a big security risk. Your VPS provider probably has some tools to help with setting up a secure, private connection.

OpenShift upload jar and run it

Hi there I have a simple jar that works like a server, can I upload it to my OpenShift account and run it ? How by the way ? Thanks alot in advance.
You might need to provide a few more details. If you want to upload a .jar file and have it run, you will need to add it to your git repository and then create an action hook that runs the .jar file (java -jar /path/to/file.jar &) and then do a git push. if you want to include the jar file for your .war web application to use, you can check the KB articles section of the openshift website for examples of how to do that.
Only port 8080 on a specific IP is exposed to the outside world. Check the docs for the environment variables such as ${OPENSHIFT_DIY_IP} and ${OPENSHIFT_DIY_PORT}. (Note the public connect via port 80 but they are connecting to the openshift infrastructure which forwards to your app running on port 8080.)
An example of running a jetty server as a jar is given at https://stackoverflow.com/a/33114072/329496 which builds a WAR file then has a start script which runs jetty as a JAR assigning the host and port using those environment variables.
To be honest if you are building a JAR and pushing it to the server you could use just use Amazon Web Services to get a host without any added extras. OpenShift is PaaS (platform as a service) whereas Amazon Web Services is IaaS (infrastructure as service). If all you need is linux and java that is very well supported with any IaaS. They also have less restrictions on a raw linux virtual machine such as being able to run on port 80. As an example I used to build JARs to run on OpenShift but they don't have full support for websockets (you have to use a high port which is not acceptable to many corporate web proxies). So I moved over to AWS and it was very easy to get things running there.

Can a local Java program start jobs remotely via SSH using DRMAA?

How does DRMAA work? Can a local Java program using DRMAA start jobs on a remote cluster over SSH (so that nothing will need to be installed on the server-side)?
Background:
I'm developing a general (or as general as possible) HPC client in Java/Eclipse RCP, and
wanted to use DRMAA in order to support any resource manager as backend.
I have the SSH connection functionality through the Remote System Explorer (RSE) Eclipse plugin already.
Most of the DRMAA implementations use the native API calls (the same which are used inside the qsub/bsub/sbatch... commands). One can see DRMAA as the "ODBC for the batch systems".
Most of the DRMAA implementations require you to run it from submit host of your local cluster, there is no SSH inside. What you can try to do is to build a portable, DRMAA based "drmaa-run" command (example: http://apps.man.poznan.pl/trac/drmaa-misc/browser/drmaa_utils/trunk/drmaa_utils/drmaa_run.c) and run it via SSH.

Run commands before remote Java debugging in Eclipse

I would like to debug my Java application usually locally, but sometimes on a remote server. I was thinking about rsyncing the class files and the jar dependencies to the remote server (perharps in an ant script) that is run occasionally, and then running the application remotely by ssh and using an ssh tunnel for connecting to the remote JVM.
This is easily achieved by running the rsync part as a Builder and the ssh tunnel as an external tool which is ran before debugging sessions. However, I would like to simply launch the remote debug configuration and have it up & running. Ideally, I would like to execute some code snippet before Eclipse tries to connect to the remote JVM, and possibly have its output appear in a Console view.
Is there any way of achieving this with some plugins (it is not supported out of the box)? I suppose I could write a quick hack as an Eclipse plugin, but I would prefer not to reinvent the wheel.
If installing CDT is an option, then you could use its launch groups for running your external tool together with the normal launch configuration:
Alternatively you may want to have a look at the EclipseRunner plugin. While it can organize launch configurations in groups, I'm not exactly sure if the groups can be launched as such.

Categories