How to configure properties and deploy application from Jenkins to tomcat - java

Is it possible to deploy a war file from Jenkins to tomcat with an application properties configuration?
Instead of building the war file from any version controll, I want to give a war file directly to Jenkins for deployment. Before that, some application properites(e.g., db connection, third-party services URL) will need to be configured according to the original deployed app and then deployed to tomcat. This might need to be done by writing some script?
For example, the deployed app is version 1.0 and db connection properties is port 5433. The war file which I gave is version 1.1 and the db port default is 5432. So, I have to update the properties in the war to 5433 for db port and deploy to tomcat to get a version 1.1 app and with correct db connectino settings(5433)
Does there have any plugin of Jenkins can achieve this?

Yes, you can do this through the scripts.
In the Build section of the Jenkins there is an option called Execute Shell - there you can do these things
1) Execute the script - which updates properties
sh script_with_changes.sh
2) Copy the war file as shown below using rsync command
rsync -avz /path/where/war/exists/xxx.war username#machineip:/tomcat/path/to/copy/xxx.war

Related

Spring boot application in windows server

I am planning to deploy a web application built on spring boot in windows server.
I want to use tomcat container.
Can I deploy the spring boot fat jar directly or is it recommended to deploy the war file.
please suggest how to deploy and the preferred method?
As Josh Long likes to say "Make Jar not War!" It really allows an application to have flexibility on where it can be run and allows for everything to be packaged as one artifact. Windows has no issue running the embedded Tomcat that is part of Spring Boot and that is exactly what it is doing when running it in your IDE. The one edge case to this is keeping the process running on the server. Normally in Windows you would do that by setting up a service and having that service run java -jar myapp.jar. I haven't personally seen it done so might take some playing around but it is possible.
A simple way to run a spring application in Windows Server is to run it as a service. You can do it using the winsw, that you download its .bin file here
winws download
Then, rename it to something like my-app.exe and create a XML file like this:
<service>
<id>my-app-service</id>
<name>my-app-service</name>
<description>Back end service for app</description>
<env name="HOME" value="YOUR_JAR_FILE_PATH"/>
<executable>java</executable>
<arguments>-Xrs -Xmx256m -jar "YOUR_JAR_FILE_PATH\YOUR_JAR_FILE.jar"</arguments>
<logmode>rotate</logmode>
</service>
Then, using the terminal, run:
my-app.exe install service
Your application is now a windows service and you can start\stop it in the tasks manager on the services tab.
Starting from the latest Windows versions, you could also deploy your Spring Boot app inside a Docker Windows Container. I wrote a complete guide: https://blog.codecentric.de/en/2017/04/ansible-docker-windows-containers-spring-boot/ (as already mentioned, Tomcat is already embedded in Spring Boot).
Spring boot internally has a tomcat server.
If you want to deploy it on tomcat then while building with maven build it as war.
If you want to deploy it has inependent application then build has jar and then place it in some folder and run it using below commands java -jar yourjarname.
Apache tomcat is a web container you cannot deploy a jar in tomcat server. If you created a web application then export your application as war file and put it in tomcat webapp directory, start the server and your war will be deployed.
How to deploy created .jar file in Apache Tomcat server in Eclipse IDE?

autodeploy web service java with glassfish server 4.1.1?

How can I do to deploy the web service automatically,I have the webService.war file ?I'm working with glassfish 4.1.1 and use a external library postgresql-9.4-1203.jdbc4.jar and I dont know how deploy the .war file thanks.
Not sure what you mean by deploy automatically, however, DeshanR's suggestion is still workable even for 4.1.1. You also have two other options:
You can deploy the war file from the browser by pointing your browser to yourdomain:4848. This will bring you to the glassfish admin console (provided glassfish is up and running and your glassfish is set to use port 4848, which by default it should be). You can then deploy your war file under the applications menu.
If this is a dev environment you can also deploy to your local glassfish from your IDE. This is an example for Eclipse. Connecting your IDE to your local glassfish has the advantage of allowing you to publish changes as you make them.
If you're using the postgres jar file for the JDBC driver and Glassfish's Connection Pool, you will need to restart the server to deploy that file after copying it in to your domain/ext/lib directory.
For the WAR, there is the asadmin command line client, your IDE may have direct support to deploy it from there, you can use the GF administration console, or you can copy the WAR in to the domain/autodeploy directory (assuming you have autodeploy enabled, which is it by default).
There are also HTTP and JMX interfaces, but those are probably not what you're looking for.

maven deployment of configuration information to tomcat

In my current development/deployment workflow I deploy my (Java/Spring) web apps to a remote tomcat containers by using the tomcat7 maven plugin.
This makes easy for me to simply deploy the new version of my app by invoking
mvn tomcat7:deploy
My specific problem now is how to correctly handle configuration information: at the moment I keep configuration information (db connection info, passwords, etc.) in .properties files which are packaged with my war and then deployed remotely to the container as described above. An improvement of this process is the use of maven profiles to include different versions of .properties for different target deploy environments.
The problem with this approach is that sentitive information (eg. passwords) are packaged with the war file, while I would prefer to have them somewhere else on the server, visible to the web app (e.g. as part of its classpath), but manageable independently (so as to allow a change in some config settings withouth having to rebuild/redeploy the app).
The only solution I've found so far for this implies the following steps:
1) do not include the .properties in the packaged war
2) deploy the war to the remote server with mvn tomcat7:deploy
3) manually copy the .properties on some server folders where they are accessible from the web app via classpath
In step 3) "manually" means not using maven-based mechanisms for this step. Can someone suggest me some mechanism through which both the packaged war and the configuration files can be separately deployed to a remote server (for instance some ?
For example , you can do this :
1. Create module_config.zip with maven-assembly-plugin contains : *.properties
2. Deploy war with mvn tomcat7:deploy
3. Start script to copy module_config > dir_deploy_application
4. ReStart tomcat7
You can do it with (sh script) or (jenkins)

How to deploy WAR manually to JBOSS 5?

I've used tomcat previously for simple apps. When I needed to deploy my application I just packed it with maven to WAR file and then put that app.war to tomcat\webapps and started tomcat.
But now I need to do the same with JBOSS v.5 and I totally cannot understand the JBOSS way :(
PS: I use JBOSS through integration with my IDE but in this particular case I need manual deployment
Place your application inside \server\default\deploy
and from cmd go to
<JBOSS_HOME>\bin
and execute the command
run.bat ---> to run local access only
run.bat -b 0.0.0.0 --> run in broadcast mode, (can be accessed from other system in LAN)
check your app in browser
http://localhost:8080/<AppName>/<Path>

How to transfer file to server using maven

Once maven creates a WAR file (with mvn package) I would like to somehow transfer the war file onto another server and then execute a command on the server to deploy the war to tomcat. I am connected to the destination Windows 2008 Server via VPN. I can also ping the destination server while vpn'd in from my local machine.
Is there a way to do this transfer of the war from my local computer to windows 2008 server? Would I need to install something additionally on the windows server?
This blog entry details how to use the Maven Tomcat plugin to do this.
Issue “mvn tomcat:deploy” to package your project in a WAR file, and
deploy it to Tomcat server. To verify it, just access to the Tomcat’s
manager page and make sure “/mkyongWebApp” path is existed.
Basically you configure Tomcat to accept a remote deployment, configure your settings.xml with your Tomcat credentials, and set up the Tomcat Maven plugin with the hostname/port etc of your Tomcat server (phew!)
There are many ways, but none of them are ideal. I would personally discourage the use of Maven as a deployment or "devops" tool. If you really need to do this there's a good chance that your requirements are going to evolve and become more complicated as your application develops. Why not just start with CFEngine, Chef, Puppet, or other tools?
Warning aside, you could do the following:
Deploy with scp - The Maven Deploy Plugin can scp a file to a server. This overrides the real purpose of a deployment in Maven, but it will work. (Again the downside here is that you'll be overriding the real way that Maven was designed to work) For this to work you may need to explicitly add the SCP wagon provider, it used to be present by default, but it was removed.
Use Cargo to manipulate whatever server you use - http://cargo.codehaus.org/Maven2+plugin

Categories

Resources