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/
Related
What I want to do is to have my main Java application to update another java application using Java Web Start and then run the second application "silently" upon user request.
I know Runtime.exec to call javaws and silently import the second application in the cache. I can do that when the first application runs and then I am sure I have an updated copy of the second application. My problem is how to run the second application without showing the Java Web start "Verifying application" window.
Doing some research I see no way to avoid that if I execute the .jnlp. I am wondering whether I can run the second application calling directly the downloaded jar files by passing Java Web Start.
Any Ideas?
Thanks
You have basically two possibilities here:
you can use the JNLP Api service and use the DownloadService;
or use the URLClassLoader and load the remote class.
I don't know if this what you want to do, may be for you it seems as a trick around, forgive me if so...
Why don't you run it as exe, by using process object?
Process process = new ProcessBuilder("C:\\...Desktop\\MyExe.exe").start();
And you can convert your app to exe easily by using jsmooth
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.
I have a Java Application consisting of a Main Class and Java Proxies(Created using Axis 1.4).There are no Servlets or JSP`s
The program takes i/p from an excel sheet.Queries an internet application using Webservices.This process continues until all the records in the Excel have been executed.
Now my First question is how do I deploy this application on Weblogic:As a WAR, EAR or JAR(Not as WAR ofcourse)
If it is a web application we can invoke it by a path like
http://server:port/contxt_root/abc.jsp
but this aint a web application, so how would I invoke it.
In Jdevloper I right Click on Main Class, Click RUN and it starts executing.Now I have to deploy over a Weblogic Server in a Linux System
Second Question: How do I shedule it.Suppose if i want it to run weekly or daily.
For this, you don't need any kind of web related servers, but some kind of a task scheduler, like cron to schedule a command line starting your Java application
You can run your compiled classes too, I'd advise to create a JAR file of them, that makes things a lot more clean.
You could make your program a timer EJB:
http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html
Just note that Java EE entities don't work to well with local files, so you need to consider where your excel sheet is located.
I'm not so sure you need to make it a Java EE app, just a scheduled program.
Good luck
I have written a very simple Java application. Can anyone tell me how to create a launcher like icon to run that application both in Ubuntu and Windows ??
Thanks in advance..!!
An executable JAR should work fine for a launcher on both Windows and Linux. However, that won't get you a custom icon.
On Windows, you can use JSmooth, which will create a .exe wrapper around your JAR file. The JSmooth program will let you create an icon for the EXE as well (it also has options such as getting the user to download the necessary version of the JVM, or only permitting one instance of the program to run).
If your java application is to be distributed from a web server, you should have a look at Java Web Start which can do what you ask for based on a JNLP-file. Notably see
http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/guide/javaws/developersguide/faq.html#104
Ubuntu and Windows will both have different ways to launch the application. I see two routes to follow here. One is to use Java Web Start and use a web interface to start your application. The other is to search for some sort of 3rd party installer that will create setup/installation programs for all the platforms you want to use.
I actually used a third party install program before, InstallAnywhere, but it was almost ten years ago. It offered the functionality you are looking for, though.
There are different ways to do this, sometimes the simplest is the best approach. One solution as suggested is a simple starting script. Roll your application into a jar, then include a script that does nothing more than "java -jar myscript.jar". I do this all the time for internal customers that may be running various types of *nix and whatever version of windows (a few macs as well). How sophisticated you need it to be depends on the audience served.
Create a bat/shell script which starts your application.
And than create a shortcut/launcher for it.
Shortcut file in windows has extension lnk.
Update
See example - SQuirreL launch file.
We are required to add export DISPLAY=:0.0 in tomcat's startup file and batch server's startup file. This is to make java see the X11 Display libraries on Unix and run our applet. Without this export in the startup files, the applet throws a Headless Exception.
Though this explicit export makes the java applet run, it disrupts the other applications running on the server. Is there a way where I can make this export DISPLAY=:0.0 run from within java code instead of adding it to startup files? And if it is possible, would that be a good approach?
I have already tried setting the system property to -Djava.awt.headless=true , but it didn't work. As the link given above http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ also says that setting headless=true would work only for few components like Canvas, Panel but it will not work for the top level components.
So I feel the only option left for me is using export DISPLAY=:0.0. This is making my applet work when set in the startup files but causes problem for other applications running in the server. So if anybody could help me to make export DISPLAY=:0.0 work such that it doesn't interfere with other applications in the server. One way I thought was to export the display through code.
Any help would be highly appreciated.
I believe you can actually set the system property -Djava.awt.headless=true which will allow access to the graphic libraries without actually needing a display.
See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ for more info.
From your question it seems that there is something seriously wrong with your configuration.
Tomcat should always be able to run server-side without a display.
Applets always run in browser and get the x11 environment from the browser. The applet's jar could be served by tomcat, or apache, or something else, but that's irrelevant.
If your applets communicate with the server, make sure that the server code is completely separate from your applet code (keep them in separate projects) and that it doesn't use any awt code. If it does (for image manipulation, etc.), then use -Djava.awt.headless as jdewald said.
How is this affecting other applications? How are you defining the environment variable in your start up scripts? If you're defining the variable correctly, it should only affect programs started by your start up script, i.e., Tomcat and the batch server.
Also, your original question doesn't really add up. Are you running both the server and client (Tomcat and the web browser) on the same machine?