I have an EC2 instance and i have a .jar that i already took (wget script command) from S3.
I want to run this .jar file, but not on start-up, just when i decide.
I'm using Java with "Eclipse Juno" with help from AWS SDK.
Running a user data script doesn't help me here.
Can some one help me with this?
Thanks in advance.
What you are looking for is unix cronjobs,
take a look at the cron job manual here and set it to run whenever you want.
also, you can install WEBMIN on your system, it gives you a great server management including cronjobs and scheduled commands as you need via web interface
if you want to run something with java, just use
String[] command={"java","-jar","myfile.jar"};
Runtime.getRuntime().exec(command);
You should try using JSch for remote invocation of shell scripts it's basically SSH within Java.
And here's a simple example.
Related
I have built a Java Play app using the latest version. Currently I am running the application using the batch file that gets generated. There's a zip file created inside target->universal folder (When I go to the bin folder inside the extracted folder this batch file is available).
How can I run this in production Windows environment? This play app is a backend service that needs to run continuously. Should this be created as a Windows Service? As in, should I try to run this batch file as a Windows Service through some means? I can't find any online references on this. Any help would be much appreciated.
There are service wrappers available, that can take almost any arbitrary application and run it as a service or daemon on some operating systems. I would highly recommend that you avoid them. Writing secure, performant services for Windows is not trivial. You can however run any script using Windows TaskManager (GUI) or Task Scheduler, and it has all the knobs you need to easily control how your application runs, when it starts and what to do if it crashes.
See schtasks.exe for command line interface reference.
So as I started deploying my web app with jetty server, I noticed there is about a 10 second downtime whenever I redeploy the web app after making some changes. I know there is a solution out there, I have found some good leads such as this one. However since i am using chef i am not sure how to implement this.
The link you have provided is a bash script. Check out chef's own bash resource.
Using bash resource, you can a run a shell script via chef.
This is handy as you already have a script to do what you want to do. So run that script via chef. Of course, there might be a chef specific cookbook/recipe/attribute lying somewhere written. But bash resource is the quickest possible way in this regard to do what you want to do (presuming the bash script you referred is all you need to get the job done).
UPDATE:
Check out my answer where I got something done for which a chef resource does not exists
I want to connect a remote machine(has a Linux operation system) from my Java Program and I want to run a script on it. I will process the result of that script(it writes something to console) too.
What do you suggest for me? If anything needed I can explain more.
There are SSH libraries in java. you can use them to execute scripts on a remote machine.
a very noob question.
Can I run a .jar file on Tomcat. I am not building a web-app. I simply need to run a .jar with
say HalloWorld in it. Is this possible/appropriate.
Thanks
You can run a Java archive without Tomcat, simply with a Java Runtime Environment:
$ java -jar myhelloworldapp.jar
Tomcat is a servlet container, only needed for web applications.
I don't really know what your use case is, but what you probably need is a virtual private server (VPS) provider. They give you a virtual host which runs OS of your choice and you can install JVM on it. There are many VPS' available. Try Linode or Slicehost.
It would help if you would explain what you are trying to achieve, then we might be able to give you a better answer.
I think what you want is Java's webstart
It sounds like want you want to do is deploy batch code to your server and then run it. You could either create a new web-app that contains your jar, or add the jar to an existing web app. Then you can trigger execution with a servlet. You could even have a JSP that contains:
<%
String [] args = new String[0];
MyClass.main(args);
%>
Of course you'd want to secure that JSP so that not just anyone can run your job.
We use the quartz scheduler to schedule batch jobs from within tomcat. This let's us monitor our jobs much more easily than if they were run from the command line.
http://www.quartz-scheduler.org/
I want to facilate my client to run java program through UNIX command prompt using some shells. It'll look more effecient if they would be able to give input through some GUI. So it can be tested immedietely. I dont want prefer unix commands fro input.
Can somebody tell me how to run Java swing or applet programs in UNIX?
As Thompson mentioned, looking at Java Web Start could be a good idea.
Otherwise, if what you want is to execute, using a *NIX-like terminal, an application located on a remote host and have it rendered on your local display, then you need to do a few things:
you need a working X server on the local machine
you need to export the DISPLAY to the local machine (you can do this by setting up the DISPLAY environment variable on the remote system)
then you need to start your Java app from the command-line.
Hope this helps.
Here's an example of how to export your display over SSH.
Java programs use the X windows system (just like any other GUI on Unix). Assuming your X windows system is setup correctly, you should just open up a JFrame and do your GUI coding just like Windows.
Using the command prompt to launch a GUI is so last millennium. If you can distribute from a server, look into Java Web Start to provide the end-user with a simple and painless install.
Oh, and of course, follow Starkey's advice to throw a JFrame into the mix.
If you have an X-server installed locally, Putty can tunnel the X11-graphics generated by Linux Java back from the server to your local machine, and view it there.
If the above doesn't make sense to you, your next best bet is either running the Java code locally with Java Web Start (and code it to communicate back to the remote server) or run Servlets inside a Java Web Server running on the remote host.
In other words, GUI over a Putty connection is not something which is easily done.