I'm trying to make a java project run on a remote server.
I've used Maven and the project uses a Mongo database. I've got access to a home directory on a remote web server. MongoDB, Tomcat and java are installed so the only thing I have to do is to transfer my Mongo Database and my project and making this all work and run.
However, I'm new to all this and I've got no clue in how to do this. I also can't find anything online on how to archieve this.
How would I go about doing this via SSH?
Additional info:
My project includes:
.js files
.java files
.html files
1 main java class which should run constantly
Actually if you are new for this kind of development, (actually it is more about deployment so popular tag DEVOPS anyway...) take it easy so use your application server and database in the same machine(which is not a suggested way for large systems).
Step 1 For ssh you need to create key read this document and create a key
Step 2 Make a ssh connection to your remote machine like
ssh username#yourIp
it will ask a password enter the password which is given by you when creating the SSH key.
Step 3 Install Mongo DB, Maven, Tomcat, Java to your remote machine.
Step 4 Copy your war to under remote machine webapps
Secure Copy war to remote machine
scp -vC ~/.m2/repository/com/foo/Example/foo.war username#yourIp:/home/Development/tomcat/webapps
echo "Copy to server"
Step 5 Run tomcat server Go to tomcat/bin directory run startup.sh
/tomcat/bin/startup.sh
Related
I think it can divide as three steps:
list only changed .class
upload them to sftp server
restart server
I can do 2. and 3. with wagon-maven-plugin, but I don't know how to do 1. with the wagon-maven-plugin.
some background:
This is a very old project(spring 3.x), plain spring web project without any maven stuff and running on tomcat server.
Our current deploy way is:
build project with IntelliJ IDEA
manually upload changed .class files to server via sftp
restart tomcat server with ./shutdown.sh and ./start.sh script.
I want improve the deploy way, because it's error-prone when we choose which files need to upload and I can't just upload all the class because it may overwrite other people's work.
I know we should just use jar/war format, but because history reason we can't.
Project is Developed in Netbeans IDE in Java Language.
Database connected to it is MySql that runs using Xampp.
The project is complete. Now I want to launch it.
I do not know..
1. How to create the setup which will install this project on clients Windows.
2. How this setup will use the database that I have created and Install it on clients PC.
3. How the database will start automatically on his PC as on my PC I have to run Xampp manually first in order to make connection through code with project.
I have tried using clean and build but when I run that result file it waits for a second and then nothing happens.
Nothing appears on screen when I run build file unlike when I run my project in Netbeans. How to solve this issue?
The database and xampp are two different things. Xampp provides a database (MariaDB if im not wrong) and thats all.
Java doesn't create "installable" outputs. it creates a jar which can be run with java
(something like java -jar your-jar.jar )
So for your setup you can either install xampp and use its database or install a database as a standalone service and use it. The boot with the system depends on the database but xampp is the easiest as you have to boot the db when xampp opens and you can put xampp to open when windows startup.
As for the jar file it depends on what your program does. Is it a service? then it needs to start-up on its own and you will need to provide a service for windows.
Is it an app that a user will run? Create a wrapper or a configuration that will setup the system to run jar files with double click as the user shouldn't need to learn java -jar the-jar.jar ( have a look at this Running JAR file on Windows )
Lastly about the db / java connection. If your program does not require the database to start up then try to "Delay" the call until its needed. Else you will need to create a retry logic to try and connect to the database after a failure instead of failing the program.
I hope that helped!
I am trying to deploy a war file in tomcat7. I am using MySQL JDBC driver to connect to database server. The jar file of MySQL JDBC driver is copied to $CATALINA_HOME/lib/ directory and the web application works correctly.
Now, I want to deploy the .war file in Amazon Elastic BeanStalk service. By default, Amazon doesn't place the MySQL JDBC driver in $CATALINA_HOME/lib directory by default and I can't run a script which will ssh into each instance and download the jar in the directory.
Is there any way, in which I can bundle the jar file for JDBC driver , so that I don't have to download and place the jar file in $CATALINA_HOME/lib directory ?
You can place the jar file in an S3 bucket, and then use a EB container command to copy the file to the lib directory, like:
"copy-lib-file":
mode: "000644"
owner: root
group: root
source: https://s3.amazonaws.com/<MY_BUCKET>/<my-JDBC-driver>.jar
No you can't bundle JDBC JARS for Tomcat7:
I've had this issue and it was a nightmare to debug. In my trials and in the documentation you can't bundle JDBC drivers inside your WAR file. Or at least you can but the classloader will ignore JDBC classes that are not in the Tomcat Lib folder. Its in the first paragraph of the Mysql section of the documentation here -> Tomcat7-JDBC I don't know of Tomcat8 or Tomcat9 beta...
Short Term Solution
What I do is exactly what you said you don't want to do and similar to Mark B's solution. I use a script that copies it from s3 but this is really easy and is only 1 line of bash if you use the aws s3 cp command. The aws s3 tool comes installed on the EC2 instance your application will be running on.
aws s3 cp s3://mybucket/mysql.jar /usr/share/tomcat7/lib/mysql.jar
*You will need to restart tomcat another reason you should see the longterm solution
Long Term Real Solution = Automate Your Build Steps
In the end you'll eventually have to run provisioning scripts if your application becomes complex, which is why I stopped using elastic beanstalk and started using AWS cloudformation which gives you a "STEP" where you can throw in all your setup scripts similar to docker build steps. It will also run those configuration steps for every new instance that gets created so there is no needed for you to ssh onto every box.
Cloudformation is all about turning your infrastructure setup into code which you could actually check into github and build without any manual intervention. You go through the headache of configuring your build scripts once then save your environment as a json or yaml file. You can include the MySQL server, tomcat version, firewalls, load balancers etc etc and build that all from a file.
Tomcat, like many application servers, installs a variety of class loaders (implementation of java.lang.ClassLoader) that will give your application access to the JDBC jar resource.
The order is:
Bootstrap
System
Common - $CATALINA_BASE/lib
Webapp - /WEB-INF/lib
Put the jar into the WEB-INF/lib directory inside the application. Note, this JAR will be only visible to this specific application and no others.
In order to do so you need to use .ebextensions.
With .ebextensions you can copy files from your application package to the beanstalk file system.
However keep in mind that no other application deployed in a beanstalk environment will use your driver. Your beanstalk instance is dedicated to one application. Every time you upload the application you have to upload the mysql driver in order to be deployed to the tomcat installation.
Therefore you do not gain anything in terms of upload size or memory footprint in a tomcat (shared jdbc connetion pool through jndi).
It seems that uploading your application with the jdbc driver included (non provided in your maven config) is a more beanstalk oriented solution.
However there are cases you don't want to make any changes in the way your war gets packaged, for example your application gets deployed to an on premises tomcat server containing the jdbc driver and you want to upload it to an elastic beanstalk environment.
In such cases you can consider docker with elastic beanstalk as an option too.
As the question explains I want to deploy a Java servlet based application which is developed on a local server (Apache Tomcat 6.0). I have the IP address, Host name for the new virtual server. I want to know, if it will be just a normal site migration process where I'll have to install Tomcat on the new server and configure the server, web XML files or is there a bit more.
As I have not done Tomcat config before. Any Help would be great
Is there a step-by-step documentation to perform this
Thanks
Download and install Java
Download Tomcat http://tomcat.apache.org/download-70.cgi
Read http://tomcat.apache.org/tomcat-7.0-doc/setup.html
Build your webapp into a war file with your build scripts
Copy the war file into webapps directory under your tomcat installation directory. More details can be found http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html
I find it best to create a script that deploys my webapp from running my build script. And scp and ssh task comes in handy for installing it quickly. There are probably other maven tasks that might work for you.
We have a couple of JBoss instances using the same JBoss installation and would ask if its possible to declare a datasource(or JMS connection factory) in one location that will be available to all instances.
If you have one data source definition and just you want to install it on all servers you can use one of these methods:
Use RHQ platform to monitor your JBoss server and deploy new application (and also data sources)
Use twiddle command (you can find in your JBoss bin directory) and MainDeployer bean:
twiddle invoke "jboss.system:service=MainDeployer" deploy /some/path/myapp.ear
Just remember that your data source should be accessible from server and will not be install after server restart - after each JBoss restart you need to tun these twiddle command. More info: Application Deployment
If your JBosses servers works in cluster you can try and use farm directory: Farm Management.
You can use SSH (or maybe FTP) server and copy the data source on each location. scp command can be very useful when you connect it with login by keys.
You can create some directory and export it by NFS. Than mount on each machine that directory and tell JBoss to deploy application from it. More info: How to deploy my application in an external directory in JBoss-5.
You can access the data source configured in one instance out side that instance. Check http://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/beta500/html/ch13s15.html. Is this what you are looking for?