Hot depoyment in Jetty Application Server - java

We are migrating from Jboss-as to Jetty. As of now as part of the continuous build and deployment process, Jenkins/Maven is being used to build and deploy the WAR to remote Jboss using the management native port(hot deployment). No physical WAR file is placed under the deployments folder. Below maven plugin is being used.
org.jboss.as.plugins:jboss-as-maven-plugin:7.6.Final:deploy-only -Djboss-as.hostname=server name -Djboss-as.port=server port
We cannot copy the WAR to webapps folder due to some restrictions. I am looking for a solution similar to jboss-as-maven-plugin, since Chef/Puppet/Ant Script/Shell Script, is not feasible for us.
Is there any similar process for hot deploying to remote jetty server without physically copying the WAR file?

You could write a Servlet which does this.
It only needs to accept a POST request, which contains some additional parameter headers required for the deplyoment (for example the file name), and the WAR in the request body.
Then upload the the WAR by POSTing it to the Servlet URL.
The Servlet would just write the binary data to the Jetty webapps directory.

Related

Deploying WAR package TOMCAT

I have two identical WAR files: one packaged without Maven and one packaged using Maven. When I try to deploy the Maven packaged WAR using Tomcat I get an HTTP status 404 error (The requested resource is not available) The original WAR (packed without using Maven) runs smoothly.I am sure that the WAR packaged using Maven has all the required files since it is exactly the same as the original package. Any idea on how to solve this issue?
What is the name of the war files ? If they differ, tomcat deploys them on a different context path.
Maven usually puts the version at the end for example:
myproject.war would be deployed to localhost:8080/myproject
while myproject-1.0.0.war whould be deployed to localhost:8080/myproject-1.0.0/ (Not sure if it handles the dots)
You can try to rename the war files to the same path, or ROOT.war for "/"
Have you checked the catalina.out log ?
In scenarios like this I only trust tools that visualize if the bundles are really identical or not. I will show you some tools below (MS Windows tools).
Checksum tool:
http://code.kliu.org/hashcheck/
The tool will very quick give me a checksum of the entire bundle. And I can compare this against the other file.
Diff tool:
http://kdiff3.sourceforge.net/
If checksum are not the same you will need see the difference in the bundles.
In this case I would use some diff tool, like kDiff.
The web.xml - deployment descirptor
Some files are very important and you will need to check first, like the deployment descriptor web.xml in the WEB-INF folder. Verify its content, the security settings, configuration of your servlets etc. The "entry" to your web service.
Unzip and check the folders/files
You know that your war file is a normal "zip" bundle. Just unzip it and check the content. You can deploy to your tomcat as a unzipped war (i.e. the entire folder, the folder name will be your context-root).
Verify tomcat logs
Check your output upon deployment and access to the web solution. Look the tomcat logging level and increase the level and watch your logs.

Compile and Deploy the Selected Modules in java

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.

Deploying Spring MVC project

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)

Reduce war size for frequent redeployments(uploads) to a remote server

While development I need to frequently update my web app source code & deploy the updated war to a remote Tomcat server. Uploading a big war(25MB) takes too long(around 30 min) on my connection which is very unproductive. Is there any way I could reduce the war size ? There are a lot of external dependencies in my project. Could I deploy just the changes(may be dependencies remain intact) ?
It depends how much control you have over the upload process. If you have remote access to the filesystem, the following should work:
Upload the WAR
Let Tomcat expand it
Stop Tomcat
Delete the WAR
Start Tomcat
Tomcat should run your app from the expanded directory
Upload changed files only and replace the old ones in the expanded directory
For static files, no further action is necessary
If up update classes or JARs, you'll need to restart Tomcat
What you are asking (Could I deploy just the changes?) cannot be done. There are other things you can do though to reduce the file size of your war file:
You can place libraries in tomcat's common directory (tomcat-dir/common/lib) and remove them from your dependencies in your war file (Does Tomcat load the same library file into memory twice if they are in two web apps?).
Place static file on a cdn or another web application on your tomcat (that would require code modification though)
You can use git hooks (http://www.git-scm.com/book/en/v2/Customizing-Git-Git-Hooks). Altough, this requires a git repository on your webserver. Deployments may triggered by push events.
Actually, if exploded war deployment is an option for you then you could use kwatee. It's a free and unrestricted tool (I'm the author) with a simple web interface (or CLI automation) that can do incremental exploded war updates and many other things.

Deploying GWT RPC app in Tomcat

As per the Google tutorial, I have developed the basic StockWatcher application, that makes an RPC call to the server, which sends some data, which is displayed on the client.
I now want to deploy it in Tomcat, such that if call something like localhost/StockWatcher, I should get the same experience as when running the app from GWT in development mode.
How do I do this? There is a similar topic here, but I couldn't much understand it. If I only copy the compiled war folder, what happens to the GreetingServiceImpl class which handles the RPC? And how do I do the mapping such that localhost/StockWatcher maps to localhost:8080 (something like Mod_Rewrite)?
Steps to deploy war on TOMCAT
1)Compile you gwt web application
2)Copy the war file
3)Add all libraries(jar files) in lib folder of war file
4)Rename your war as "myapp"
5)create a .war file with that "myapp" folder
6)start tomcat with catalina.bat run.
For step5 (generating .war file ):Preparing .war file from command line
Normally if you deploy well your war directory and you are able to start tomcat you have done everything. If you access your page using this url : localhost:8080/StockWatcher gwt will know that it must use that url as a baseURL for all gwt/rpc requests.
To generate the war using Eclipse : right click on the project -> export -> war. You will have the war exported with all the dependencies inside. just unzip it in the ROOT directory

Categories