Run application on server by application on client computer - java

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

Related

Running java application as windows service

I have a Java Application(works as server for a client application) with a GUI. This application has to run always even after restarts of the server.
I have created a windows service using Apache daemon for this purpose.
When the server starts I can see my services running as system service. But when I open the GUI of the application another instance starts.
I need the GUI to be attached to the same instance which started after restart, is this possible.
A Windows Service (as well as daemons on Unix-systems) can't run with a GUI because it starts without a Window Management System like Windows Desktop or KDE, Gnome, etc. I'm actually surprised that your application starts as a service because attempts to start GUI-elements should lead to an error.
You have to separate the GUI from the server components. The GUI then needs to communicate with the server by some protocol. Because you already have finished your application I suggest RMI as protocol of choice, that should be the easiest to implement because you essentially just have to add some interfaces to your classes to get RMI on its way instead of adding a complete layer of complexity by your own (an additional server to receive commands from the client, etc.).
RMI can be set up to only listen for connections from localhost, so in terms of security you should be good as well.

Running a Java Application to run on a tomcat sever

I have created a Socket Server application that will accept Client connections from other computers on the local network. This is application is run from a public static void main method. and is a very standard java application.
I have also created a web service that runs on tomcat, it also uses java. The web service will http post accept request from any internet connected device.
Once the web service receives a request I would like it to send instructions through the socket server and send some data to the client connected.
I would like to run the socket server applicaiton within the web service so that the web service has access to the socket server without having to connect as a client.
What is the best way to run a standard java app so that the tomcat server will start the application when it starts up? should i run it as a servlet or is there a better way to have the web service access the socket
An application opening its own server socket within a proper application server is pointless and possibly counter productive IMO.
Think about it: Tomcat is probably running on port 8080. Your application is hypothetically going to be running on port 9080. What port do you think clients will need to connect to, to consume your service? And if you answered that correctly, what service/benefit are you then expecting Tomcat to provide you, if your clients are in fact, not going to interact with tomcat at all?
You don't need a (full) application server to run your own personal server. You have the option of:
a Java web service without a web application server, which lets you deploy a full JAX-WS webservice within the vanilla JSE, no application server required
Using the jdk's embedded HTTP server to process your requests
Deploying your standalone application as a windows (or other OS) service

chat application deploy

I have created one sample chat application. In that chat application, I used JApplet and front end.
Till now I was testing my application in my desktop. It is working fine. Now I want to deploy my application over any webserver.
Now I have a few questions. Currently I am using Server socket as 8989 in my chatserver. When I was testing the application in my desktop, I used to start the server as stand alone.
What are the steps I have to follow when I deploy the application over tomcat or any other web server? Which port the client will listen?
How do I start my chat server? I am new to the socket concepts.
when you say you are hosting on the webserver, i believe that its an servlet/jsp based application , which will listen to your requests , in that case the listener will be invoked at the webserver default port either 80 / 8080 (being default). In case you want to change or check , you can go to the TOMCAT_INSTALLATION_DIR/conf/server.xml and check for tag containing the port number for weblistener, and change it to whatever value you feel like.
if thats not the case and you have your own thread which opens a socket for you , you really dont need a webserver, all you need is a host machine which will start the socket listener ( your custom) and then it will listen at the port that you have configured it to be at.
As far as I got it, you're having standalone application as a server, where you handle connections to particular port.
I think there is some confusion that should be clarified.
The very basic question is:
Why do you need your chat server to be running on the web server?
This should be clear to you prio to any later steps.
As web server is there basically to handle HTTP/S requests and that's not your case, as far as I got it. As you're probably running socket TCP/UDP communication.
For the web server however your client applet implemnentation could benefit of. If it would be referrend on a simple html page (deployed inside war) it could be simply redistributable to clients via url call in a web browser.
Maybe I'd preffer to use HTTP + JSON commununication, where you could benefit from web server usage (also on the server side) and would not need any other ports than standard ones.
Not sure if it still makes sence to answer your questions as it might be irrelevant for you, but let's see.
Answers to your questions:
Basically you need war archive (rather than jar one), as that's the one accepted by web servers. once you create it (you need to follow the correct folder/file structure inside) your app could be deployed to web server.
Which port the client will listen? Basically server is the listener here => no client port listening here.
This depends on your communication implementation decision. If still sticking with TCP/UDP one, I don't think web server would be beneficial here.

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.

How to Create a Java programe through which I can run a DOS batch file remotely from client; I dont want to put batch file on server

We have client side Windows server in which we frequently observe many services going DOwn,
Now Either we have to individually Login to Server and restart Service,
But I have written A Batch file which when run can automatically Restart all the services, but teh problem is I dont want to put them in Each server, tehre are 50+ server,
how to remotely connect to those serevr and execute this batch file, I have server Credential also,
Please Reply
Considered actually running your "services" as a Windows Service, so Windows will restart it automatically?
winsw - http://kenai.com/projects/winsw/pages/Home - is the one used in Glassfish for this purpose. We've used it for other Java based services too, works nicely.
Being able to run externally submitted batch files is a security disaster just waiting to happen. I would recommend against it.

Categories