I have a Pure Java Process which needs to be run every day at certain time.
This is a temporary job, so i don't wanted to create a new environment to configure this job.
strong text
Is there any way to configure this batch at certain time in Eclipse or IBM RAD?
Is there any plug in available for that.strong text
Regards,
Lokesh.
To my knowledge there is no standard facilities available in Eclipse to support "run code X at time Y", so you need to turn to operating system facilities.
If you can make a simple program launchable with "java -jar" you have many options. FOr Windows many different EXE-that-launch-jar products exist (we use winsw to launch java as services) and you can then use normal scheduling (e.g. at) to invoke your code.
Related
I would like to write a program that sends an automated email based on a timer that runs constantly. I would then like to somehow export this program from eclipse to a computer that does not run the ide, and run it constantly in the background. I have figured out the code to send emails through java, my question is more regarding how to export this project as an application (or something) that can be run on any computer without running it through the eclipse IDE.
Any help, or directions to a better a resource to learn from, would be greatly appreciated.
The simple (manual) approach to turning a Java program into something that runs outside Eclipse:
Create a runnable JAR following the instructions here: http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-37.htm.
If your application depends on library methods that are not part of the Java SE library, pay particular attention to the "select library handling strategy" step.
Run the application from the command line as follows:
$ java -jar yourapp.jar arguments ....
Obviously, you need at least a Java JRE installation on the execution platform to run java, and you should have configured your system (the $PATH or %PATH% environment variable) so that typing java runs the correct thing.
If you are using a build system like Maven, Ant, Gradle and so on, you can automate the step that generates the JAR. (In fact, you can automate the entire build ... and break your dependency on any IDE.)
I DO NOT recommend trying to create an "executable" for your Java application. For a start, executables cannot be run on any computer. They can only be run on computers running a specific operating system / OS family. A second problem is that you are effectively embedding a JRE in your application. That makes applying the latest Java security patches difficult.
As for the problems of keeping the application running "constantly" and sending emails at specific times, that is just Java programming.
Use Timer & TimerTask - e.g. http://www.mkyong.com/java/how-to-run-a-task-periodically-in-java/
Use a job scheduler. For instance Quartz has an easy to use API for running jobs on a fixed schedule: http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06
You need to create a runnable executable. You can do this by following these steps: http://www.wikihow.com/Create-an-Executable-File-from-Eclipse
Regarding the timer/scheduler, you may consider using Windows Task Scheduler (on Windows platform) or cron (*nix platform).
You will probably need to provide more information about the requirements you have for the timer in order to get a more specific answer there.
Problem: I have a standalone Java app (henceforth known as "the agent") that runs as a service on internal company servers. It acts as a remote agent for some central servers. As the agent gets deployed in more places, managing them is getting more complicated. Specifically: pushing updates is painful because it's a fairly manual process, and getting access to the logs and other info about the environments where the agents are running is problematic, making debugging difficult. The servers under discussion are headless and unattended, meaning that this has to be a fully automated process with no manual intervention, hence Java Web Start isn't a viable solution.
Proposed solution: Make the agent phone home (to the central servers) periodically to provide agent status and check for updates.
I'm open to other suggested solutions to the problem, but I've already got a working prototype for the "status and self-updates" idea, which is what this question is focused on.
What I came up with is actually a separate project that acts as a wrapper for the agent. The wrapper periodically calls the central server via HTTP to check for an updated version of the agent. Upon finding an update, it downloads the new version, shuts down the running agent, and starts the new one. If that seems like an odd or roundabout solution, here are a few other considerations/constraints worth noting:
When the wrapper gets a new version of the agent, there may be new JAR dependencies, meaning class path changes, meaning I probably want to spawn a separate Java process instead of fiddling with ClassLoaders and running the risk of a permanent generation memory leak, which would require manual intervention--exactly what I'm trying to get away from. This is why I ended up with a separate, "wrapper" process to manage the agent updates in my prototype.
Some servers where the agents are deployed are resource-limited, so any solution needs to be low on CPU and memory usage. That makes me want a solution that doesn't involve spinning up a new JVM and is a stroke against having a separate wrapper process.
The agent is already deployed to both Windows and RHEL servers, so the solution must be cross-platform, though I wouldn't have a problem duplicating a reasonable amount of the process in batch and bash scripts to get things rolling.
Question: As stated, I want to know how to make a self-updating Java app. More specifically, are there any frameworks/libraries out there that would help me with this? Can someone with experience in this area give me some pointers?
If your application is OSGi based, you could let OSGi handle bundle updates for you. It is similar to the wrapper approach you suggest, in that the OSGi container itself is "the wrapper" and some of it won't be updated. Here's a discussion on this
Different solution: use (and pay for) install4j. Check out the auto-update features here
No need for wrapper (save memory) or java web start (adds more restrictions on your application), simply let a thread in you application check periodically for updates (e.g. from cloud) and download updates if available, then code these two calls in you application:
launch a shell script (.sh or .cmd) to update your artifacts and launch your application after few seconds pause in the script(to avoid having two instances of your application at the same time).
Terminate your application (first instance)
The script can overwrite needed artifacts and re-launch your application.
enjoy !
Have a look at Java Web Start.
It is technology that's been part of Java since... 1.5? maybe 1.4? and allows deployment and install of standalone Java-based apps through a web browswer. It also enables you to always run the latest app.
http://www.oracle.com/technetwork/java/javase/overview-137531.html
http://en.wikipedia.org/wiki/JNLP#Java_Network_Launching_Protocol_.28JNLP.29
also see this question: What's the best way to add a self-update feature to a Java Swing application?
It appears as though Webstart is the only built in way to do this at the moment.
I am developing an inventory system i-e a java desktop application. I am using Ms Access as database engine and there are certain modules e.g one makes reports using ireport and other such dependencies. I need to ask how can I make installer for my application which will install few fonts, copy database files, install jre to make it run etc. Please guide me in it.
Thanks in anticipation.
This is something I've briefly used in the past, and it may serve your needs. It's an open source installer builder system, tailored towards Java apps.
http://izpack.org/
I've used jsmooth which creates a single EXE-file that unpacks and run transparently. Not a full installer but worked well for us.
Note: I have not seen any Java installers which asks the "There is an update available. Update now?" question.
If this is important to you, then consider Java WebStart which checks for updates at each launch (but do not ask).
What is the alternative to distributing Java?
I don't want to add JRE in my extracted files.
I don't want to give away my .jar file to the user.
The end user just install and use application.
Which database to use so that the user don't need to configure like SQL Server.
How to decrease execution time of my application? It takes more time to execute.
Edit
It is an application without a database.
There should be a setup file which installs in Program Files and shortcut on the desktop and some registry entry to start it with start up application.
You can deliver Java desktop apps as Applets and (more recently) Java Web Start apps. Using these technologies means that users don't need to manually handle files.
As for RDBMS, there is a pure Java RDBMS going by the names JavaDB and Derby which might meet your needs.
There are many ways to improve the execution time of a program, it depends on what you've coded and what it does, for a start. I think you'll need to ask a specific question on that to get a useful answer.
Java Web Start works well as a distribution mechanism. Host the .jar on your site and your clients can download (provided they have a JRE). It'll select the appropriate JRE to use and allow you to update the application at your end with automatic downloads.
If you want a database, check out JavaDB. It's pure Java and comes as standard with Java 6. Your application can check for an existing db on start-up, and initialise/configure if not present. That will then remain for future invocations.
I am looking for the best way to make my desktop java program run in the background (daemon/service?) across most platforms (Windows, Mac OS, Linux [Ubuntu in particular]).
By "best way" I am hoping to find a way that will:
require a minimum amount of platform-specific code.
not require the user to do anything a general computer user couldn't/wouldn't do
not be a resource hog.
I understand that my requirements may be unrealistic but I am hoping there is some sort of "best practice" for this type of situation.
How to go forward?
You can run a Java application as a service (Windows) or daemon (Linux) using the Apache Commons daemon code.
Structure
Daemon is made of 2 parts. One written in C that makes the interface to the operating system and the other in Java that provides the Daemon API.
Platforms
Both Win32 and UNIX like platforms are supported. For Win32 platforms use procrun. For UNIX like platforms use jsvc.
Java code
You have to write a Class (MyClass) that implements the following methods:
* void load(String[] arguments): Here open the configuration files, create the trace file, create the ServerSockets, the Threads
* void start(): Start the Thread, accept incoming connections
* void stop(): Inform the Thread to live the run(), close the ServerSockets
* void destroy(): Destroy any object created in init()
You can turn any Java program into a service/daemon using the Java Service Wrapper. It is used by multiple OSS projects, and ships as part of the Nexus Maven Repository Manager so that it can be installed as a service out of the box. To use it, you, the author, just need to create a configuration file and then run a simple batch file to create the service on Windows or copy an init script to the correct runlevel on Linux.
You can use the SystemTray classes and install your app as any other in the default platform.
For windows it could be an scheduled task that run at startup.
For Linux and OSX I don't know (besides crontab wich is somehow too technical) but I'm pretty sure they both have a way to do the same thing easily.
Unfortunately (as of today) Apple hasn't finished the 1.6 port.
It won't be a real demon, but an app like Google Desktop.
I've heard Quartz is a good option. But I've never used it.
If you dont need free solution, you can use Advanced Installer (www.advancedinstaller.com), it can make win-service as well as MacOS installer from your JAR, and more..
Check out JDIC, the Java Desktop Integration Components project. It supports desktop integration like system tray (or equivalent) with a cross-platform API.
Others have mentioned Quartz, which is an enterprise job scheduler. It can be lightweight, depending on the jobs that are scheduled, but it doesn't have any features that are inherently desktop-oriented. On the contrary, many of its features depend on enterprise support like a relational database. If your application is primarily scheduling tasks, a headless Quartz service executing jobs, with a desktop client to interact with the service is reasonable approach.
The Apache Directory Daemon project sounds like the best cross platform way to do this (with Java wrappers for JSVC under POSIX and procrun under windows).
People sometimes have difficulties finding prunsrv.exe and/or prunmgr.exe (components of procrun), its not well documented on the apache site, generally it can be found in the archives (note. they say that procrun is tomcat5.exe)
for windows you can find it here:
http://archive.apache.org/dist/commons/daemon/binaries/windows/commons-daemon-1.0.7-bin-windows.zip (contains both 32 and 64 bit versions)
you dont need to implement daemon interface nor download it at all, prunsrv can be used to turn any app to windows service
browse that archive for other platforms