Run java program on remote UNIX machine in JSP - java

I am developing Web Application in local machine using JSP. I want to execute a Java Program that resides on Unix box from my local JSP file. I have all the credentials of the UNIX box. Can you please advise me.

Well there are various ways to execute [instruct remote machine to execute your java program]
RMI
WebServices
Defining your protocol and then Socket server client

Related

How to deploy java vertx server on linux?

i have made a java server that uses vertx, eventbus, and socket. The client connects to it using javascript. But all of this works locally, How can i deploy this software on a linux server so people online can use it?
you should build a jar file and deploy that on the server. Then start the file with
java -jar filename.jar
I don't know the context of your application, but it may be necessary to create a web server to let others connect to your application.

How to execute a bat file on a different machine and fetch the output in Java

I need to execute a Windows .bat file on a different machine. I know :
the IP address of the remote machine, and
the executable file location.
How do I execute that particular file and how can I get its output?
Both the machines run Windows.
I already saw these links:
http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html
http://www.onezerozeroone.eu/html/rmi_howto.html
But I am still not very clear on how to start?
You can't do this just using Java and RMI.
For obvious reasons, there isn't a way of running code on a remote machine unless that machine is set up to allow that sort of access. Otherwise, anyone could run anything on your machine at any time!
If it's a .bat file that you want to run, then you should look at setting up something like an ssh server on the other machine. That way, your machine will be able to connect to it via ssh (using a Java library if you like), execute the .bat file, and capture the output.
But if it doesn't need to be a .bat file, and you just want some of your own code to be triggered on the remote machine, you could write a (Java) application to run on the remote machine and listen on a particular port for messages instructing it on what to calculate, and then return the results.
That is pretty much the standard pattern for all remote services, including web servers.

Running a Java project remotely

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.

Executing batch file on remote system using Java

How to execute a batch file located on Windows remote system? Batch file should run on remote system.
Abhinav,
For your problem I see RMI is the quickest possible solution
Check out the basics from these links (1,2)
Start the server from where you want to run the batch
In the Remote object on the server side Use Runtime.getRuntime().exec() to run your batch.
From the client machine give call to this remote object and method.
Another approach is to use SSH like sshj. This only requires the remote system to have SSH installed and is more secure than RMI.
You can use Jsch and Expect4j for executing commands on remote machine(window/Linux). Further more, if your system allows, transfer the batch file on remote machine using some FTP utility like Apache Commons Net and then execute commands that executes the script.

What is Problem in Runtime.getruntime which does not open notepad.exe

when try to execute the servlet containing following code
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("notepad.exe");
It doesn't launch the application in the environment windows server 2003 and Tomcat 5
but a process is being created as notepad.exe in the windows task manager.
In windows xp and tomcat 6 environment launches the notepad
i need to work on the windows server 2003 and tomcat 5
Thanks in advance
In other words, it get launched on your local development machine (WinXP + Tomcat6), but not at a production/test server (Win2K3 + Tomcat5)?
Do you realize that Java Servlet code runs at the server machine, not at the client machine, which are in real world usually two physically different machines connected by a network? The notepad is opened at the server machine (there where the webserver (Tomcat) runs), not at the client machine (there where the webbrowser runs). That it works at local development environment is just because both the webserver and webbrowser runs at the physically same machine.
Login to your Win2K3 environment and you'll see that notepad is opened there.
If you really intend to launch notepad.exe at the client machine using Runtime#exec() (I don't see any business reasons for this, but that aside), then you'll need to provide the client a Java application in flavor of an Applet or Web Start Application served by a HTML/JSP page. This will get downloaded to the client machine and will be executed there.
If you could tell us the requirement to launch notepad.exe, then we could suggest a solution/approach to you.
I think your tomcat runs as a service at the background. When running notepad it is executed with the same logon that your tomcat runs with. Most likely thats a different logon than your desktop-logon and thus the notepad won't be displayed at that desktop!
In your dev environment you started tomcat by executing the wrapper scripts directly. Try to install it as a service and you will get the same problems with XP.
Btw: I don't see a point in running an AppServer and calling notpad at the server. Are you really sure about the design?

Categories