Deploying a Maven Spring Boot project on a server offline - spring

I have a situation in hand where I have no internet connectivity on my client's server (because it is an intra-net server) and I have to deploy my Spring Boot application on it which uses Maven build. The thing is, I am not allowed to connect the server to the internet due to security reasons but I am able to access internet on my development machine. So I have two questions:
How do I get all the dependencies on the server in question? Can I somehow copy the downloaded files from my development machine to the server? If so, how?
Do I need to setup Apache Tomcat or should I just run the war file from the command line? What are the best practices?

It's better to make a jar file instead of making a war file. That should help you to run without Tomcat since it embeds a web server.
Dependencies are packed with the jar when you do a Maven build. You need to have an internet connection to build it. Copy the jar to the production environment and run.

Here is striaght forward example to deploy spring boot application on tomcat server
Follow the example and add one more tomcat6/tomcat7 plugin
<!-- Tomcat 6 plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<configuration>
<url>${serverUrl}:${port}/manager</url>
<path>/${contextpath}</path>
<username>${username}</username>
<password>${password}</password>
</configuration>
</plugin>
plugin properties as follows
<properties>
<!-- Server Details -->
<serverUrl>http://kpServer</serverUrl>
<port>8080</port>
<contextpath>kp-cxf</contextpath>
<username>admin</username>
<password></password>
<!-- Skip test execution during default steps -->
<skipTests>true</skipTests>
</properties>
And you can use mvn tomcat6:redeploy command to deploy to your server(in shore maven deownloads plugins/dependencies from internet to your development server, when you run mvn tomcat6:deploy/package it creates war by taking jars from you local maven directory)

Related

How to undeploy a .war with Jenkins?

we are working on our Selenium Grid Setup.
We did it like this:
We got 2x Jenkins Jobs and 2x Tomcats.
We are using Maven!
First Jenkins Job deploys the application (to test) on a tomcat. This job got a post action where the second job is triggered. (of course with ignored testing)
Second Jenkins Job tests the application deployed on the first tomcat and if its successful it will deploy the application on the second and final Tomcat.
Now we need to undeploy the application on the first Tomcat if its deployed on the second one.
Is there any option to integrate this in the second Jenkins Job?
It would be nice if you could give me some advice.
Thank you
-T
Typically, the way to deploy and undeploy on Tomcat in an automated fashion is to use the Maven Tomcat plugin. Disregard the fact that it seems to be only for Tomcat version 7 - it will work the same for 7+.
Behind the scenes, this plugin utilizes the Tomcat manager REST API.
Your Jenkins commands would probably go like:
mvn tomcat7:deploy on first server
If the deploy and startup is successful, you'll get a verifiable response that looks like: "OK - Deployed application at context path /foo" (and likely the relative error code)
You could also write a curl and parse command
for the manager command at http://localhost:8080/manager/text/list
to check if the application deployed as a sanity check
If it deployed
Do a mvn tomcat7:deploy on the second server and
Do a mvn tomcat7:undeploy on
the first server.
Just for all of the information to be here, the basic maven configuration for this plugin is:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<path>/myAppContextPath</path>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>

Deploy Maven project with integrated Tomcat

I've researched many resources how to deploy Maven project to jar file and then to tomcat. So my question: is it possible to integrate tomcat server to my maven project and then deploy it to jar file, because I want to launch my web application just by double clicking on the jar file.
You can use Apache Tomcat Maven Plugin. Add to your pom.xml the following lines:
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
Source: http://tomcat.apache.org/maven-plugin-2.2/
After that you can start your web application via command line:
mvn tomcat7:start
I want to launch my web application just by double clicking on the jar file.
This solution doesn't allow you to run web application just by double-clicking on packaged Java archive, but I provide you with common approach in Java web-development and recommend it.

How to auto-deploy EJB jar with TomEE maven plugin

I have a stateless EJB SOAP Web Service that is packaged in jar file.
Is it possible to setup auto-deploy with Tomee maven plugin when the app consists of only one EJB jar file?
For example, this site indicates that a web context defined in server.xml is required. My synch setup is same as the site suggests.
mvn compile
command does nothing but compile the sources as it normally does.
Is there a possibility to setup something like this with EJB jar or is a WAR package needed in any case?
Thanks.
UPDATE
In order to get the TomEE Maven plugin to work at all with jar files, I added the following in pom.xml configuration section
<apps>
<app>my.group:my-ejb-app:1.0:jar</app>
</apps>
We use the maven tomcat7 plugin to do exactly this. Here's the trick, because Apache TomEE is JEE6, you can deploy EJBs in wars.
So there are two ways to do what you want... One, skip the Jar packaging for your application and make your EJBs be WARs. If this doesn't sound appealing, the other way is to create a separate project that's a WAR, but pulls in your EJB jar as a dependency.
In either case, then you can then use the tomcat7 plugin to deploy your projects easily to Apache TomEE like this mvn tomcat7:deploy provided you fill out the server section of your pom correctly. Example:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<server>crabs</server>
<url>http://crabs/manager/text</url>
<path>/${project.artifactId}</path>
<update>true</update>
</configuration>
</plugin>
</plugins>
</build>
Make sure you have a user in tomcat-users.xml on the server that has the proper deployment permissions to manager-text. Also, put the server configuration into your ~/.m2/settings.xml:
...
<servers>
<server>
<id>crabs</id>
<username>deploy</username>
<password>your password</password>
</server>
...

how to deploy Maven dependencies automatically into JBoss as OSGI bundles?

I have a project that deploys an standalone OSGí Apache ServiceMix application. It has tons of dependencies and it is built with Maven. Now I want to deploy this application into a JBoss AS. I found an interesting Maven plugin called jboss-as-maven-plugin (org.jboss.as.plugins) to deploy anything. I use maven-bundle-plugin (org.apache.felix) to construct my bundles and it works fine, but when I deploy the project bundles, the deployment fails because dependencies are not satisfied.
How can I automatically bundle and deploy all the dependency tree with a Maven goal? Is it possible? My project has dozens of dependencies declared on the pom.xml and some of them are other projects in my workspace.
Currently the only solution to this I know are the Karaf features. You can create a feature file out of your pom dependencies.
I found that jboss seems to support subsystems. That may help to specify the bundles required to run your application. It does not seem to be the OSGi subsystem spec but for jboss this may already help. For OSGi spec 5 there is the standardized subsystem spec which may provide a standard way to do this across containers.
If jboss supports OBR (OSGi bundle repository) then you can limit the number of dependencies you have to specify.
If your application do not use OSGi per see, you may consider packing your application as a WAR which is deployable in JBoss.
Then you would need to use web.xml to bootstrap your application, such as using a Spring XML file.
There is a Camel example as a WAR here: http://camel.apache.org/servlet-tomcat-example.html
You can autoinstall your bundles with org.apache.sling plugin
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<executions>
<execution>
<id>install-bundle</id>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
<configuration>
<slingUrl>http://localhost:8181/system/console/install</slingUrl>
<user>karaf</user>
<password>karaf</password>
</configuration>
</plugin>
you can find detailed pom.xml from Adobe website :https://docs.adobe.com/docs/en/cq/5-6-1/developing/developmenttools/how-to-build-aem-projects-using-apache-maven.html
or http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/build-deploy-osgi-1.html

Deploying Maven project to JBoss AS7 (standalone)

I am new to JBOSS AS7, and am strictly using MAVEN 3 via command line. I would like to deploy the *.war of my project to JBOSS AS7 without ECLIPSE. I have spent couple of days Googling and trying out difference approaches. I am able to deploy the *.war to Tomcat. I would highly appreciate any help on this. So far this is what I have done:
I have entered the server info(Jboss) to C:\maven\conf\settings.xml
I have included the plugin to the POM
I think I may be declaring the path to JBoss AS7 within my JBOSS plugin wrong.
This is how I am including the plugin in the POM file:
<plugins>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.0.2.Final</version>
<configuration>
<url>http://localhost:8080/
<server>jboss</server>
<path>/web-app</path>
<configuration>
</plugin>
</plugins>
Did you have a look at the README on the corresponding GitHub page:
https://github.com/jbossas/jboss-as-maven-plugin
When deploying to your localhost (which is the default value) you don't need to define the <url> in the <configuration>, as well as the <server> and <path> elements (besides: I haven't seen a folder named wep-app in AS7).
We run a project where this works even without touching the settings.xml.
So when you have checked this, post what exactly goes wrong, what is the concrete failure message and what is the maven command you use (mvn jboss-as:deploy).

Resources