I have a Java Application written that forwards selected files to an ssh server. I want this application to be automatically run every time windows starts.
I am aware that this question has been asked multiple times, and I have followed those leads. I have tried Java Service Wrapper (which is no longer accessible because of a dns problem), Apache Daemon, and JSL. Though I have at times been able to get the application installed as a service, I have never been able to get it to run properly on boot, or even start it manually from the command line.
My question is whether anyone is aware of a full first step through final step tutorial of how to make this work. I have come across a few things, but they all either assume that you have implemented something that they do not explain how to implement, or rely on applications that I do not have installed.
Thanks
I use Java Service Wrapper to install as windows or linux service: http://wrapper.tanukisoftware.com/doc/english/download.jsp
~> create one runnable JAR to your app.
~> Download the proper service wrapper (they are diffrent to windows and linux)
~> Configure the service in wrapper.conf
Important: set wrapper.java.classpath correct (your jar must be here too)
Set wrapper.java.mainclass with org.tanukisoftware.wrapper.WrapperSimpleApp
Set wrapper.app.parameter.1 with the name of your main class, for example:
wrapper.app.parameter.1=Main
~> Test the service as console (windows bat)
Related
I have created a java application in intellij ide. The application is working well. Now that my application is ready I want to transfer my java application from my machine to server and make it live. I have one server, domain and all the basic rights in the server. Can any one help me figuring out?
I am very new in this part. I dont know anything about hosting my own website and application.
The answer depends on what technology you use. If you use application that needs to be deploy into servlet container you can deploy it onto e.g. Tomcat.
Whatever technology you use you definiately should build your application - it also depends on what building system you use.
E.g.fFor gradle, you can use gradlew build.
For maven: mvn compile.
Tell us more details about technology you use to allow us to help you.
You have a java application (Dropwizard) and first need a server to run it on, which means that it must be a server with java installed or where you can install it yourself.
Then you need to transfer the application "fat" jar (typically you find this in the target directory, depending on how you built it) to this server and start it with java -jar my-application.jar.
Then you need to make sure that the port that the application runs on is available externally. This usually means that you need to have a web server installed (commonly nginx or httpd) which redirects from port 80 or 443 to the port of your application.
Only then is you app "live".
Let's imagine that your company asked to develop a real-time chat application and wanted it to be finished in hours. Since you already know that it's super duper easy with Node.js, you developed it in Node.js but the company uses Java Application Servers(like WebSphere, JBoss or WebLogic).
So the server administrator expects .EAR files to deploy.
Is there any way to provide an .EAR file that runs your Node.js app behind?
this is so frigging dirty that any sane checks on the released EAR should kill you on place. that being said, yes, it's possible. you have to know a bit of things first.
is the target JVM is enough priviliged to run processes or security on the execute right sufficently lax to enable the JVM to execute shell process by using it's API methods. (i'm talking about Java security, not OS security)
you must know first hand exactly which type of OS the ear container is running on.
the EAR/WAR must be "expanded" to a real filesystem known by the OS.
you must know if the credential under which the ear container have enough privilege to execute a OS command.
once you know exactly those four points, this is no biggie to use the Process java API to execute a Node.js process that the executable (statically linked and OS compatible) is conveniently to a known position...
even as Bruno Grieder said, sharing port is not possible, so you'll just have the web application acting as a front proxy for the "real" application running on Node.js, HTTP or HTTPS being not relevant at all as the final communication between the web application container and the web application itself is no longer encrypted.
awwww... so cute ... :) but, you have to know that using a sneaky method like this in company environment, is not a good thing.
No.
You cannot properly package a "pre-installed" nodeJS inside an ear.
NodeJS installation differs between Windows and Linux; the EAR would not be portable.
On a side note, I would not like to be in your shoes, should the server administrators learn that you are packaging executables not meant to be run on the JVM, inside the EAR.
(note1: as noted in the comments above by #mlan, it would be impossible to share ports between the JVM and nodejs process - faking it would require a fronting reverse proxy dispatching HTTP requests, assuming all traffic is HTTP)
(note2: don't put me wrong, you can put anything in a EAR, including executables that you trigger from Java using ProcessBuilder for instance, but that a last resort workaround)
I need to call a jar which is kept on a shared windows machine.
The JVM also needs to be placed on this shared machine so that anyone with access to the remote location should be able to call this jar.
I need to write a windows script which shall be run using a service user.
Is this possible? If yes, request you to please provide pointers.
Java Management Extensions provides the tools for building Web-based, distributed, dynamic and modular solutions for managing and monitoring devices, applications, and service-driven networks.
see JMX Tutorial
see example with Linux script
see Windows cmd script
You might have some luck using the Tanuki Software Java Service Wrapper. Jetty uses this for their Windows Service Wrapper.
Another option is Apache Commons Procrun, which is what Apache Tomcat uses.
Both work well to set up a Java application as a Windows service. You will need to ensure your application is designed to run well as a service; you should be able to "trigger" events (start, stop, restart, etc.). You might need a lightweight adapter around the application to get it to work right as a service; but that should be a trivial exercise.
Once you have a service set up, make sure appropriate user(s) have rights to start/stop the service [1] [2]. You could even set the service up to run using a specific account. Then you can use the net start, net stop, etc. commands in a batch file.
I'm in the arduous process of trying to upgrade a couple of our servers to use a current version of the application installed on it and I've gotten a bit stuck. I've gotten everything replaced and have narrowed my issue down to 1 .jar file. If I use the new version of this specific file, I can not get the service to start, and using the old version (and the new version of every other file), it runs fine.
When I try to start the service I get this message: Could not start <service> service on Local Computer. The service did not return an error. This could be an internal Windows error or an internal service error.
I've looked in the event viewer, and all it has are these entries every time I try to start it:
<Service> has started
Could not find the service start class
<service> has failed to start
Is there some place else that I can look that might be able to give a bit more information on why it's failing to start?
We are using the 'JavaService' utility to create the windows process. This server is also running jboss.
EDIT: I have also determined that it is not an issue with my SQL database as I just did all of the upgrades between the versions. I still can't get it to start with the new .jar, and the old .jar still works.
Thanks!
You can't execute a java application as a service. Windows services implement a specific interface that java.exe or javaw.com do not. You will need a wrapper to implement this functionality. One such wrapper is http://wrapper.tanukisoftware.org.
As Pierre mentioned, you can't run java directly as a Windows service. Apache commons daemon (a.k.a. Procrun) is another tool that will adapt a java application for use as a Windows service.
I found the issue!
After days and days of looking around at configuration files, I finally noticed something: We are now using log4j for logging but it wasn't included in the .jar's manifest! I added it to the manifest and it now starts up!
Thanks for your help everyone :]
What is the easiest way to have an application launch at startup on Ubuntu server as daemon? This is a java application (java com.run.run.Run) etc.
How would I have it launch as a user and possibly have access to write to some log file where the user has permissions to write?
And if I don't end up doing that, how would I launch the application as the root user at startup.
Edited: It is a headless server, I don't have access to the desktop applications.
As user upon login:
Depends on when exactly you want it to start. Wanting to run it a a user and write files as the user seems to indicate that you want to run it at login. This can be achieved by adding it under
System -> Preferences -> Sessions -> Statup Programs
or
System -> Preferences -> Startup applications
Depending on your version of gnome.
Or, put a call to your java program it in ~/.profile.
As root upon boot: To run it as root during boot, follow the instructions at http://embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/
So you have a script of your own that you want to run at bootup, each time you boot up. This will tell you how to do that.
Write a script. put it in the /etc/init.d/ directory.
Lets say you called it FOO. You then run
% update-rc.d FOO defaults
You also have to make the file you created, FOO, executable, using
$chmod +x FOO
Using Headless Mode in the Java SE Platform may give you some additional latitude, depending on what your daemon does. In addition or #aioobe's suggestions, consider SuperUser.com for questions about startup and permissions.