I've developed a small MVC project using Spring MVC, Hibernate, MySQL, Maven and Tomcat. I can run and test the application (locally) smoothly.
Now I need to publish/deploy this project on an (online) server that have only Tomcat installed on it. How can I publish/deploy the project online? Is there any special build I should do? What files I shall upload and to where?
There are several types of development options available.
For development on localhost EAR (Exploded ARchive) type of project is usually used (because you can easily make hot deploy on servery). But for production WAR (Web ARchive) is used (basically it's the same EAR archive, but compressed using ZIP algorithm).
If you want to deploy your project to remote Tomcat server then make your project as WAR archive and upload it to Tomcat's webapps directory. Then you might need to restart Tomcat. But it's manual way of deploying.
Better option is to use automated build tools (like Maven) which can compile your project, run unit tests, deploy on web server (local or remote) etc.
This one is a great example of how to deploy your project on Tomcat server by using Maven's tomcat-maven-plugin: http://www.mkyong.com/maven/how-to-deploy-maven-based-war-file-to-tomcat/
Good luck ;)
Do a mvn clean install and you will get a .war file in your target directory of web module.
Copy it and paste it in tomcat_home/webapps directory and restart tomcat. Thats it. now, you can access it in whatever configured port (eg: http://localhost:8080/<your webapp war name>). lets say your war name is myapp.war, then tomcat would have extracted it into myapp folder in webapps.
so your url will be http://localhost:8080/myapp
With maven deploy command, usually gets errors for various reasons.
if you work in Unix/Linux system, I recommend using "rsync" method on console. (You can write own shell script to manage easily). It helps not only deploying without a problem but also helps to get time while redeploying (only uploading changed / new files). Because maven deploy / redeploy uploads your project as a bundle in jar/war. However "rysnc" method uploads your project files one by one.
Before using it, you should sure that two conditions.
1- your project is built in target folder (Spring Tool Suite)
2- you have access to tomcat via ssh
example code : (v_ : prefix which is variable(customizable))
rsync -avz v_your_project_in_target root#v_ip:v_tomcat_name/webapps/v_project_name
(Second sharing)
Related
I'm looking for a way to be able to deploy war-artifacts to an IntelliJ-started Tomcat when I choose to. I have one project which has a configuration that starts a Tomcat 8 server and deploys some artifacts. LaterI now want to deploy more artifacts from different projects to that same IntelliJ-started Tomcat.
Step: Start project which includes the Tomcat
Step: Deploy war from another IntelliJ-project (from within IDE)
Step: Deploy another war from IntelliJ (from within IDE)
I'm having to solutions in mind but couldn't figure either out:
Maven: so that the war file gets deployed to the tomcat
IntelliJ-Config: that deploys the war file to the already running server
I'm looking for a possibility so that I don't need to take care of the Tomcat myself.
You could always set up a Jenkins instance, and have it build your war every time you push to Git or Subversion, then deploy your war to Tomcat immediately after the build. Just ensure that Jenkins is running off a different port than Tomcat.
Does anybody know a gradle 'hot deployment' plugin (or middleware as shell script) which is coping files from source folder directly into project folder at tomcat's webapps directory (not embedded server like gretty or gradle tomcat plugin; version7, environment independent)?
At the end I want to realize a smart dev workflow to (re-, un-) deploy a java web application during code crafting. I'm searching for something like grunt watch tasks.
Scenario: Java web application with self contained, executable jar file at WEB-INF/lib folder.
register watcher tasks on top on gradle task
java source is changed
tomcat stopped
remove jar file at WEB-INF/lib folder
deploy jar file
copy jar into WEB-INF/lib folder
(delete all log files)
start tomcat
Restart tomcat is not needed if static sources are changed (e.g. JSP, JS, ect.).
Solution
I thought about our working practices at the office. My colleagues and I, we program on Windows machines and we use a key map configuration in IDEA to start and stop our local installed Tomcat.
The easiest way for me is to define a user related CATALINA_HOME system environment variable which references the path to Tomcat server.
CATALINA_HOME = C:\Program Files\apache-tomcat-7.0.56
I define a deploy task which copy compiled war file into webapps folder ((re)start Tomcat manually via IEDA).
task deploy(type: Copy) {
def WEBAPPS_HOME = System.getenv()['CATALINA_HOME'] + '/webapps'
from 'build/libs/app.war' into WEBAPPS_HOME
dependsOn war
}
Nobody need to change Tomcat path inside build.gradle file or there is no additional user.config file which is ignored by git.
But I don't like manual Tomcat handling and it is unusual to work with environment variables on Mac's.
So, I decide to search an embedded Tomcat server as Gradle cargo plugin for local development. It is recommanded from Benjamin Muschko (Gradleware Engineer) at How to use local tomcat?... and he describe the differences between Cargo or Tomcat plugin....
Setup of this plugin is quite easy. I don't need to explain.
Nobody need to install there own Tomcat and everybody work with same version server.
For our nigthly build I use the power of Gradle wrapper as Jenkins task configuration.
I execute a wintods batch command.
cd "%WORKSPACE%\app"
gradlew.bat clean build
I use Jenkins to manage deployments for our applications.
There are a number of plugins which help with such tasks along with having the ability to write your own scripts.
Jenkins is highly configurable so you are able to adapt it to your own needs.
Jenkins URL
Hello all master minds,
I have created a java spring application in eclipse with mysql db.
Now I can run this application using >Run on server in eclipse,but I want to know how to deploy this application on my own laptop(windows 7).
I have already configured server,by localhost://8080 I can see Apache tomcat is configured.
Give me simple steps so that i can just run that software using browser via its link like
http://localhost:8080/PMS
PMS is my project name.
Thanks in advance.
You can install tomcat-manager in order to deploy your war using a web interface: Tomcat 7 manager
Another option is to copy your war file into tomcat webapps folder. Your container will auto deploy your war: http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html#Deployment_With_Tomcat.
The easiest way, since you are using eclipse is to just export your project as war and then put that war (naming it PMS) in webapps directory in your tomcat.
Once started, Tomcat will deploy that war on http://localhost:8080/PMS
You have to do the following steps:
Right click on project>> Export (Export as WAR file).
or if you are using a maven project then you can give a maven build.
Copy that WAR file, (you will get that war file inside the project folder in your workspace) to the tomcat_Installed_Folder/ webapps
Inorder to deploy the app from outside eclipse,
goto tomcat_Installed_Folder/bin
and double click on startup.bat
then you could see a console.
For detailed logs of deployment, goto tomcat_Installed_Folder/logs
ALL THE BEST :)
In my application I have three java modules. I have to deploy it into the tomcat server dynamically by selecting module 1 and module 2 or module 3. The selected modules will gets packaged and form a war file and gets deployed in server without restarting. How can I achieve this? Is there any Apache products/tools or any available to do this?
The products/tools you should look at is the Tomcat Manager. The default installation of Tomcat comes with the Tomcat Manager. As the names says it can manage (deploy, undeploy, reload, start, stop) applications for Tomcat without reastart. I'm not realy sure what are your needs and how your precondition look like, but i see four ways how you may can do this:
If you already have a WAR, you can simply use the Tomcat-Manager via a Browser. Just call the manager URL (e.g. http://localhost:8080/manager/html). There you have options to upload a WAR and undeploy a application. (Before you can login, you have to edit tomcat-users.xml - just google a bit).
Use Apache Ant. Ant is a XML-based build tool for Java. With Ant you can compile your SourceCode and pack it into a WAR. If you tomcat runs local, you can copy the WAR via ant in the webapps directory of the Tomcat. Tomcat will auto-deploy it (if auto-deploy is active, as it is by default). And if you remove one WAR from webapps, tomcat will auto undeploy.
Tomcat provides a library with ant commands, to deploy the WAR via HTTP over Tomcat-Manager to the server (Tomcat Ant Commands). So if the tomcat is remote, use this command via ant.
You don't like Ant? Use the Tomcat Manager direct via HTTP. (HTTP Commands). Of course than you have to compile and build the WAR on your own.
I hope it is usefull for you.
I have a project with maven, this a multimodule project
Mainproject
project1 - jar
project2 - jar
project3 - web
Now that I finished the project I want to test it on the server but don't know how to upload them, on my computer I have added a plug for tomcat which deploys the war file to tomcat automatically, but the server doesn't have maven.
What is the way for moving to production with this kind of projects?
Should I just upload the target directories for each module?
Thanks
You're asking a few questions here. There is the "how do I test on a server" one, and there is "what is the way for moving to production" one. And they can be quite different.
I have assumed that the JAR files in the project are used by the WAR file and packaged within its WEB-INF/lib directory. If I'm wrong, that's cool. Just this sort of information is handy to know.
Maven is a build tool. It is not a deployment tool. What you have at the end of this, is a WAR file. If you run mvn install (or mvn deploy) you have a SNAPSHOT version of the WAR file. This would be suitable for quick, ad-hoc testing to other machines. But you would most likely use methods approriate for the hosting container for making them available. Note: a Maven DEPLOY is a different thing from a DEPLOY a war file to tomcat.
To my mind, if you're putting anything into production, or in front of a customer, or in front of a testing group, you should use Maven to make a Release of the product. That is, using the release plugin (via the release:prepare and release:plugin goals) to create a non-SNAPSHOT release of your artifact (in this case, a official version of the WAR file). Once you have that WAR file, you can migrate it to your production server in whatever way is easiest (copy, deploy into tomcat in the best way). You haven't mentioned if there are database requirements for this web application, and that would need to be considered before you change any production application.
But, once you have official versions, you have tags of source code, and you can accurately know what code is being run.
What I don't think you're going to get is being able to automatically copy the WAR file into a production server from your development environment. Here be dragons.