Update tomcat war file before explode (uncompressed) [duplicate] - java

This question already has answers here:
Externalizing Tomcat webapp config from .war file
(4 answers)
Closed 7 years ago.
My application WAR has some settings baked in already. I would like to change them on fly before deploying in tomcat container. Right now I deploy them in /Catalina_base/, start the tomcat application, once WAR is uncompressed, I update conf file and restart tomcat. Any best practice to update conf file before starting tomcat ?
Also, how do I achieve this using chef cookbook?
Greatly appreciate your help.

As the comment from Chris Nauroth says, best practice is to keep environment-specific configuration out of the WAR.
However if you are stuck with the configuration being in that WAR, then you can use zip tools to update the configuration file.
If you are on a typical Linux distribution, then assuming your WAR file is called application.war and the configuration file you want to update is WEB-INF/classes/com/example/config.properties then you can run these commands during your deployment before you start Tomcat:
unzip application.war WEB-INF/classes/com/example/config.properties
# edit the configuration file now
zip -f -m application.war WEB-INF/classes/com/example/config.properties
After the unzip command, the file will be in a subfolder matching its location in the WAR (eg WEB-INF/classes/com/example/config.properties) and then the second zip command will delete it from the disk and put it back into the WAR.
I'm not familiar with Chef so I'm not sure how to run those commands automatically as part of the deployment, but presumably it provides a way to run command directly like this.

Related

deploying war file to tomcat servers

System Information: I have a system with 10 tomcat server and load balancer in linux operating system.
Configration: I am running tomcats in linux screen
Problem: When i have to deploy new war file , i need to stop 10 tomcat server, remove old war and extracted old war folder, copy new war file to webapps directory and start it
Question: Is there any way to do this operations faster ?
The best solution is using Curl(linux command) with tomcats manager.
Detailed usage: Using Curl with tomcats manager
I have create a page that uploads war file to file store which all of my tomcats can access then calling curl commands for each server in java.
Normally you don't have to stop the tomcat server to delete the previous war file. When you delete the war file it will automatically delete the corresponding directory of if.
Use a bash script to delete and copy the files.

Installing Hysterix turbine from WAR/JAR file

I am a sydadmin and was evaluating Hysterix Turbine.
https://github.com/Netflix/Turbine/wiki/Getting-Started-(1.x)
It is available as a war/jar file.
Directory structure looks like this after downloading
$ ls turbine-4.0
conf lib LICENSE NOTICE README.txt site sql turbine-4.0.jar
How to get this installed . If I download tomcat and put the above contents in deploy directory , will it work .
I am new to JAVA and Tomcat. So any help to get this installed will be highly appreciated.
Simple Steps-
Download the war file from here. If you are an absolute newbie, go with version 0.5. The version 0.0.1 has weird behaviour where it gives IOException while running multiple application instances on the same machine.
You should then deploy the war file to your tomcat by just placing it in the webapps folder in tomcat and starting the server. If your war name is turbine.war, you should be able to view your aggregated logs at http://localhost:8080/turbine/turbine.stream?cluster={cluster-name}
Before deploying your turbine.war, make sure you configure the file path of archaius.properties in catalina.sh in bin folder in the tomcat. Something like-
CATALINA_OPTS="-Darchaius.configurationSource.additionalUrls=file:///home/mukulbansal/Downloads/oauth-stuff/turbine-archaius.properties"
The contents of turbine-archaius.properties can something be like-
turbine.aggregator.clusterConfig={cluster-name}
turbine.instanceUrlSuffix.user-write=/hystrix.stream
turbine.ConfigPropertyBasedDiscovery.{cluster-name}.instances={IP:port-of-application-producing-hystrix-event-stream}
turbine.InstanceMonitor.eventStream.skipLineLogic.enabled=false
More info can be found here.

Run spring project on server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am using windows 7.
I have written a simple Spring3 Hello World using Eclipse and successfully run it using tomcat on my computer.
Now I have a Server which runs Linux.
I would like to run the project that I just wrote on my server. It has no GUI or anything of the kind so I can't simply start up eclipse and write the same project on the server.
How do I go about doing that? I am completely new to the whole java and Spring thing, and have absolutely no clue as to how to run my project on the server and be able to view it.
I have searched everywhere online trying to figure out how to put my project on the Server, but it seems like Spring isn't the most noob friendly, especially with its documentation. There doesn't seem to be any explanation on how to take your code from one computer and put it into another and make it work.
There doesn't seem to be any explanation on how to take your code from one computer and put it into another and make it work.
That's right, as it is not often considered "not a programmers job". Its not very related to the framework you're using (Java EE or Spring or whatsoever), instead it's more of an infrastructure thing (related to the operating system and application server that are being used). Nevertheless, it can be very useful to know how the process works.
Generally speaking there are two steps:
Packaging - If you use Maven, you simply run the mvn package command. Or using Eclipse, you can export your project as an WAR-file (Right-click your project, click Export, search for "WAR"). I would advice to use Maven, but that's a bit outside the scope of your question probably. Either way, this step will result in a WAR file.
Deployment - This is a bit harder. The WAR file from step 1 needs to be copied to the Linux server where the application must be ran, and then copied into a special directory where the application server looks for apps. If you're using Tomcat on the Linux machine as well, look for the Tomcat installation directory and find the 'webapps' subdirectory. Other application servers have other procedures / locations, though.
This is under the assumption that Tomcat was already set up for you on the Linux server, and that is running.
This has nothing to do with Spring and everything to do with packaging your application and deploying it in a Servlet container/HTTP server.
Setup Apache and Tomcat (or some other servlet container) on your linux server.
Package your Spring application as a war file (either with maven, ant, Eclipse, or some other build tool).
Drop the war file in the /webapps directory of your Tomcat installation.
Start Tomcat.
Well first you need to get tomcat 'http://tomcat.apache.org/download-70.cgi', and set it up on the linux server you are trying to deploy to.
Then you would export your project as a .war archive in eclipse (File -> Export -> war)
Copy the war file to your server, and copy it into TOMCAT_HOME/webapps
Start up tomcat and you should be able to access the application under localhost:8080/{APPNAME}, so if your war name is myapp.war the url will be localhost:8080/myapp
good luck!
Spring is just a 3rd party open source API. You can do without Spring and still be able to "run" your application on a server.
By "run", this means that your project must be placed in a directory in the server's filesystem, most of the time in the form of a WAR file.
I said most of the time, because if done correctly, you can actually put your project directory inside the server, and it will run without transferring it as a WAR file.
A WAR file is just an archive that has a standard directory structure so that it is readable and executable by the server.
Read the following link on how to package your project as a WAR:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fcwwarovr.html
And then just copy the WAR file to the TOMCAT_HOME/webapps folder.
Packaging
cd c:/my_project_directory/Web/
jar cvf web-archive-test.war .
Deployment
cd c:/my_project_directory/Web/
scp *.war
your_username#remote_linux_host:/some/remote_directory_where_tomcat_is_installed/webapps/

deploy war file on Tomcat and run without project name [duplicate]

This question already has answers here:
Deploy war on Tomcat without the war name in the URL
(4 answers)
Closed 9 years ago.
I 've just created war file of my web project (JSP/Servlets).
Project name: TestApp
when I deply it in Tomcat 7, I run itlike that:
localhost:8080/TestApp/ or www.maypage.com/testApp/
ok, everything works, but I need to run it without project name, like that:
localhost:8080 and on hosting www.maypage.com
How can I do that?
thank you.
And I'm fining jsp/servlet hosting, which have that configuration option. do you know hosting like that?
In order to access your application without using the application name, you need to deploy it as the root application. There are multiple ways to achieve it and the related answer describes it pretty well.
Setting default application in tomcat 7
Content copied from the above link:
First Method:
first shutdown your tomcat [from the bin directory (sh shutdown.sh)]
then you must delete all the content of your tomcat webapps folder (rm
-fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)]
Second Method:
leave your war file in CATALINA_BASE/webapps, under its original name
- turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. explicitly define all application Contexts in
server.xml, specifying both path and docBase. You must do this,
because you have disabled all the Tomcat auto-deploy mechanisms, and
Tomcat will not deploy your applications anymore unless it finds their
Context in the server.xml.
Note:
that this last method also implies that in order to make any change to
any application, you will have to stop and restart Tomcat.
Third Method:
Place your war file outside of CATALINA_BASE/webapps (it must be
outside to prevent double deployment). - Place a context file named
ROOT.xml in CATALINA_BASE/conf//. The single element in this context
file MUST have a docBase attribute pointing to the location of your
war file. The path element should not be set - it is derived from the
name of the .xml file, in this case ROOT.xml. See the Context
Container above for details.

Tomcat6 not deploying my webapp

I have access to a Tomcat server that is currently deploy two webapps. When I put my own webapp in the apache-tomcat-6.xxx/webapps directory, it doesn't deploy it. I tried downloading the Tomcat sample webapp, and deployed it in the webapps directory, and it still doesn't deploy.
Is there anything I have to do beyond putting the webapps in the apache*/webapps directory to get them to deploy? I have tried starting/restarting Tomcat ad nauseam.
Thanks,
ktm
When you say you put your own webapp, I assume you are putting your webapp.war file? Make sure you delete the existing webapp directory first before you place webapp.war. Tomcat will automatically inflate the war file to create that webapp directory.
Did you try stopping and starting tomcat?
Is your server getting started? And if yes than your project directory is created in webapps.
Also look for environment variable.
Check to see if the security manager is running. If it is you will need to edit the catalina.policy file to allow your web application to be deployed and accessed.
If you export your .war file from eclipse, make sure your project's dynamic web module facet version is not more than what your production server can handle. For example, version 3.0 works for Tomcat 7, but doesn't work on Tomcat 6, which needs it to be set as 2.5. To knock the project facet version down a notch, see this question.
Ensure that permissions on your war file belongs to the tomcat user and group. Make sure to remove the deployed directory first, and then restart the server.
$ sudo rm -fr /path/to/tomcat/webapps/<yourwebapp>
$ sudo chown tomcat:tomcat /path/to/tomcat/webapps/<yourwebapp.war>
Now restart the server
I had a problem with tomcat 6's deployment system. For some reason the file $CATALINA_HOME/conf/Catalina/localhost/MyAppName.xml was zero-length... I'm not sure about what caused it, but I deleted the zero-lenght XML, deleted the WAR and then I repeated the deployment process (copied the WAR to the webapps directory) and it deployed correctly. I found the failure message in a log file... now I know it for the next time, but I though it would be worth to share just in case...
Hope it helps...
i also meet the problem,i redownload tomcat and check service.xml carefully,finnally i find my WEB-INF/web.xml not exsit.
The problem that I faced was there were too many java processes that were running. Somehow it was not letting Tomcat start and did not throw any error.
For that I killed all the java processes and then restarted the Tomcat and it worked.
In Linux:
> ps -aux | grep java
> kill -9 [pid_from_last_command]

Categories

Resources