Deploy Maven project with integrated Tomcat - spring

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.

Related

Vaadin 8 + AudioVideo Addon: "Failed to load the widgetset"

I added the AudioVideo Addon to my Vaadin 8 (version 8.7.2, Maven 3, Tomcat) project and everything woks fine in my Eclipse development environment (I did run Maven clean install). But if I export the WAR file to the deployment server the app fails to start with the following error:
Failed to load the widgetset: ./VAADIN/widgetsets/AppWidgetset/AppWidgetset.nocache.js?1556793473728
I found the following in my Maven POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Exclude an unnecessary file generated by the GWT compiler. -->
<packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
</configuration>
</plugin>
I think I need to change something in the Maven config. I tried the "packagingIncludes" instead of "packagingExcludes" but this did not help.
I would be glad for your help since I cannot do "experiments" on the deployment server.
How do I have to configure Maven or what else do I have to do to get the following folder from the eclipse depolyment environment into my exported WAR file?
myApp\target\myApp-0.0.1-SNAPSHOT\WEB-INF\classes\VAADIN\widgetsets\AppWidgetset

Deploying a Maven Spring Boot project on a server offline

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)

How to see changes without building maven project?

I have simple java web application. web application has some js, css, html files. when I change js files, i am not able to view new changes in browser. For new changes i have to perform "mvn clean install" command then only i am able to see new changes. So Is there any way to see changes without performing this command ?
thanks.
it's not recommended to perform "mvn clean install" unless you want to use your code into another project.
That's what I do when I want to publish code change into a webserver for debug purposes
1/ I configure tomcat7-maven-plugin into the parent pom project:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
2/ then
mvn tomcat7:run
will launch an embded tomcat7 server with your resources deployed.
to publish your code to a remote tomcat, you can use
tomcat7:deploy
after having configured tomcat7 plugin correctly
alternatively, import your maven project as an eclipse project (plugin name: m2e) then right click on the projet, debug on server will launch the eclipse configured tomcat.
whenever you save a resource, it will be automagically deployed on the eclipse-managed tomcat.

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>
...

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