I have access to a server using SSH. I need to run a stand-alone Java application on it to access a MySQL server installed there. How do I go about in doing this?
Assuming you have the requirement to copy the JAR file on the *nix box and then run it(and not connect a Java process to it remotely)
Create a standalone JAR which contains all the dependencies required to run the application
Make sure you have Java installed on that machine
Assuming it's a *nix box, set the $PATH environment variable to point to $JAVA_HOME/bin
Log on to that box using a SSH client. Any decent SSH client also comes with a FTP plugin which allows you to transfer files between your local box and the server
Copy the JAR to the appropriate directory and run it using the java -jar your.jar command
Assuming it is a linux machine, you have to connect to by using SSH it and use scp command to upload the files and deploy it...
than you have to run the JAR you deployed:
java -jar /path/to/file.jar
Or, provide more details please
Related
I want to deploy my java spring backend to AWS .
I figured the way to deploy jar file on aws. But the problem is as soon as I terminate the terminal deployment stops. I created a jar file on build and hosted on aws EC2 linux Instance by copying jar file there and running below command .
java -jar jarfile
I want this deployment to be persistent. Is there any tool similar to pm2 for nodeJs in JAVA so that I can run this jar file permanently. ?
Thanks for help.
You should use nohup to deploy jar file. It will run even though you close terminal
E.g:- nohup java -jar javaservice.jar > nohup.log &
I have a very basic question regarding environment variables. The Tika python library that I'm trying to work with mentioned the following:
TIKA_SERVER_ENDPOINT: set to the host (local or remote) for the running Tika server jar
I downloaded the server jar from here and ran it with java -jar jarname.jar I'm trying to set the environment variable to the localhost, but I'm not sure how exactly to do this. I tried the following:
TIKA_SERVER_ENDPOINT=http://localhost:9998
But this simply resulted in a 404, with Network Error (dns_unresolved_hostname), Your host cannot be resolved by the DNS,
I also ran ps aux | grep java to check if the jar file was running and saw that it was running on the port 9998..... i.e:
java -cp /tmp/tika-server.jar org.apache.tika.server.TikaServerCLi -- port 9998 --host localhost
What exactly am I doing wrong here with my environment variable? I'm just very new to messing with jar files and environment variables, so any help would be greatly appreciated, thanks!
I had a similar issue and was able to resolve it by simply downloading the latest server jar from the Apache downloads page and then starting the server on my local machine from bash with:
java -jar tika-server -x.x.jar --port xxxx
Which started the tika server. I was then able to access tika in python through:
from tika import parser
parser.from_file('path_to_file')
Maybe java is installed incorrectly. You can check java installation here
Installation (with pip)
pip install tika
Installation (without pip)
python setup.py build
python setup.py install
Environment Variables
These are read once, when tika/tika.py is initially loaded and used throughout after that.
TIKA_VERSION - set to the version string, e.g., 1.12 or default to current Tika version.
TIKA_SERVER_JAR - set to the full URL to the remote Tika server jar to download and cache.
TIKA_SERVER_ENDPOINT - set to the host (local or remote) for the running Tika server jar.
TIKA_CLIENT_ONLY - if set to True, then TIKA_SERVER_JAR is ignored, and relies on the value for TIKA_SERVER_ENDPOINT and treats Tika like a REST client.
TIKA_TRANSLATOR - set to the fully qualified class name (defaults to Lingo24) for the Tika translator implementation.
TIKA_SERVER_CLASSPATH - set to a string (delimited by ':' for each additional path) to prepend to the Tika server jar path.
TIKA_LOG_PATH - set to a directory with write permissions and the tika.log and tika-server.log files will be placed in this directory.
More information you can get here.
I want to deploy a a project to ec2. It was modify in Intellij which used MAVEN. It work perfect in Intellij. Below is the configuration of Intellij.
I have tried command line like java, javac. These kind of comment lines are all failed. I am wondering there must some way to convert Intellij configuration to command lines. I was relying too much on IDE. XD. Now I am regreted.
EC2 is the amazon cloud service for instances. If you aren't very experienced with it - the easiest you can do is to hire a machine with your fav operating system - for example Windows and use remote desktop to log in it and just do your normal IDE setup and run your app. You will have your app running on your instance and it will be working, even it is done the hard way. I will get downvotes for that, but it will work as a Swiss watch.
It depends from the kind of EC2 instance you're using.
For me would be simpler if it was a Linux instance.
I'll connect via ssh and git clone my project there from my bitbucket/github repository.
Then I'll use Maven, and there are many different options to run your project with Maven.
As suggested in the comments you could use the exec plugin.
But even in this way you'll have a list of problems to overcame.
For example your linux instance does not came with an preinstalled Java Runtime.
You have to install at least Java and Maven (choose ubuntu distro, so you can do easily with a package manager like apt-get).
Or, for example, another not easy task is connect via ssh to a Linux instance.
AWS generates a key.pem file that you have to use in order to successfully connect to your instance.
ssh -i .ssh/your-key-file.pem username#your-ec2-instance-address
And again, AWS does not tell you the name of the default user you must use to connect to your EC2 instance (if you choose ubuntu distro the username is ubuntu).
And again, when you save your-key-file.pem in your computer it must have the right permission
-rw-------# 1 freedev staff 1692 Apr 21 09:46 /Users/freedev/.ssh/your-key-file.pem
or your ssh client wont read it.
...looking back it was really a long way make a deploy on a EC2 instance.
I have solved it by myself.
Use mvn package to generated jar file for maven project.
nohup java xx.jar debug.xml & use this to run jar in shell. By using this command line, when exit (abort remote connection), the process / command will not get killed.
Command line jcmd is used to check running process pid.
I'm able to run Dropwizard application on https on my local machine trough this commands.
mvn package
java -jar target/dropwizard-example-1.2.0-SNAPSHOT.jar db migrate example.yml
java -jar target/dropwizard-example-1.2.0-SNAPSHOT.jar server example.yml
Here is the example I am following dropwizard-example on github
Once we create package of Dropwizard application with Debian. it converts into single jar file.
Q1:
How can I run the command ends with server example.yml? because this file is not going to found?
Q2:
How can I run jar file of dropwizard application packaged through debian on windows machine?
Q3:
On local machine it runs sucessfully on https port. How can it will be achieve after packaged through debian?
You need to ship .yml file because it is a setting file JAR always looks for this file.
Once we create package of Dropwizard application with Debian. it converts into single jar file.
All Dropwizard applications are a single jar file. That is what you are making on your local machine (when you do mvn package) and running on your local machine (when you do java -jar...), so you will run that single jar on whichever other machine you deploy your app to.
How can I run the command ends with server example.yml? because this
file is not going to found?
The github project you cloned included the file example.yml. This needs to be on the machine you are going to run the application on. You can call it whatever you like, but you must pass its name to the jar as an arguemnt.
How can I run jar file of dropwizard application packaged through
debian on windows machine?
The same as on debian, java -jar target/dropwizard-example-1.2.0-SNAPSHOT.jar server example.yml
On local machine it runs sucessfully on https port. How can it will be
achieve after packaged through debian?
If you look in the example.yml you can see where this is configured:
applicationConnectors:
- type: http
port: 8080
- type: https
port: 8443
keyStorePath: example.keystore
keyStorePassword: example
How do I run a Java .jar file as a Windows service on a Windows 2008 server? I have a jar file called SomeJavaFile.jar located under the C:\SomeDirectory directory on a Windows Server 2008 box. I usually just run this jar manually in the command line with: java –cp SomeJavaFile.jar com.ctg.SomeJavaFile and I let it run 24/7.
The problem with our Windows Server is if it restarts I need to run it as a service so it will automatically start as a service upon startup, because our processing for Vistakon runs 24/7. I have Googled around and tried to use a service wrapper and the sc.exe command to create the service.
I put the wrapper service.exe in the C:\SomeDirectory\. I use the following command to create it: sc.exe SomeJavaService binPath= “C:\SomeDirectory\service.exe \”java –jar C:\SomeDirectory\SomeJavaFile.jar\”” type= own start= auto error= ignore. This creates the SomeJavaService service correctly but when I try to start it I get an error that says the service on Local Computer started then stopped.
Some services stop automatically if they are not in use by other services or programs. Do I need to alter my sc.exe command to have the exact previous working command line maybe, by adding in the com.ctg.SomeJavaFile? So should I change This jar should just run in the background and constantly poll/ping the C:/poll directory then if there is data present it processes the data and sends an export file to another directory.
I have used this same .jar file for years successfully and it hasn't changed, but I cannot get it to run as a Windows service. This is the site I use to get the service wrapper http://code.google.com/p/simple-service-wrapper/. Any help would be greatly appreciated!
"winsw" is the standalone version of the Windows Service installer shipping with the Glassfish Java EE reference implementation.
Works well, but is not a fully polished product - I have used it for exactly this purpose for a couple of years. Requires .NET in some recent version on the Windows machine.
https://github.com/kohsuke/winsw
I think that the best bet would be wrap your java app with Procrun of Apache Commons Daemon .
Procrun is a set of applications that allow Windows users to wrap
(mostly) Java applications (e.g. Tomcat) as a Windows service.
The service can be set to automatically start when the machine boots
and will continue to run with no user logged onto the machine.
As per my analysis,
The Idle Solution will be writing a VC++ (.net) Windows Service creation program to launch the .bat (that triggers the jar file)/.exe as a System service with all the required call back methods to SCM.
Note : 1. Wrapping the process with sc.exe / srvany.exe would not work as it does not have any call back process to the SCM (Service Control Manager). 2. And java service Wrapper is a third party API (many are LGPL licensed).
If you start your Java code from commandline by using java -j some.jar does it run until you terminate the program, or does it stop by itself?
There needs to be a NON-Deamon Thread, that is running all the time. A JVM will terminate, if there is no thread running, that is not flagged as daemon.
If you have a little budget, buy an installer tool. I use instll4j. With that tool, you can create service launcher and install them during instllation.
The following solution is working fine for me having OpenFire Connection Manager (which is a jar file) running as service on Windows Server.
Download and install the Non-Sucking Service Manager
I didn't use the batch made by OpenFire team, because it didn't work for me (dependencies not found error...) So, make a batch file with the following code :
#ECHO OFF
cd /D "E:\connection_manager\lib"
java -jar startup.jar
and save it as cm_startup.bat in the bin folder of connection manager.
After that you can create the service with NSSM.
So, open a cmd.exe and run the following command :
nssm install ConnManager "E:\connection_manager\lib\cm_startup.bat"
.
Doc & examples
More documentation and examples for the Non-Sucking Service Manager here : https://nssm.cc/usage Actually NSSM as a lot of options available.
Here is a more complexe example :
nssm install solr "%JavaExe%" -Dsolr.solr.home="\"%CD%\solr"\"
-Djetty.home="\"%CD%"\" -Djetty.logs="\"%CD%\logs"\" -cp
"\"%CD%\lib\*.jar"\";"\"%CD%\start.jar"\" -jar "\"%CD%\start.jar"\"