What is the purpose of tomcat-maven-plugin? - maven

I'm having some difficulty understanding the purpose of this plugin. Is it to modify the settings in Tomcat during the build?
I am deploying to tomcat using maven, without the plugin and it seems to work fine. Not sure if I am missing something
Cheers

Maven Tomcat plugin basically just bootstraps an embedded Tomcat container for you. Saves you the trouble of configuring an external Tomcat instance for development purposes. It can also auto-start this Tomcat instance during the build and run integration tests on it, stopping it afterwards.
If you already have a functioning workflow that you're comfortable with, no need to introduce the plugin, but it's pretty easy to configure, can run multiple web apps, can run unassembled applications etc so it's convenient to have for local development.
An even more light-weight alternative would be the Jetty plugin which starts an embedded Jetty server instead.

Maven is actually a plugin execution framework where every task is actually done by plugins.
Maven Plugins are generally used to :
create jar file
create war file
compile code files
unit testing of code
create project documentation
create project reports
A plugin generally provides a set of goals and which can be executed using following syntax:
mvn [plugin-name]:[goal-name]
For example, a Java project can be compiled with the maven-compiler-plugin's compile-goal by running following command
mvn compiler:compile
for more information go to http://www.tutorialspoint.com/maven/maven_plugins.htm
so pulgins is used to execute goals.
suppose if you don't include plugin that is required in your execution environment then it will throw an error like
A required class is missing: Lorg/apache/maven/plugin/BuildPluginManager;
so by adding appropriate plugin in pom.xml it will resolve the dependencies and execute the goal succesfully.
to remove above error just add the following plugins :
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
</plugin>

Maven is a framework used to build JAVA applications, it provides the following
Directory Structure
Configuration Files
Build Settings
It helps in easy and structured development, primarily used for REST API Calls.
Applications built on Maven Framework, would require the same to be deployed
Its better that you get the plugin installed, since on a long run you never know what dependency may go missing
-If this helps, Mark as Answer

Related

Running springboot using maven vs. via java directly?

Essentially, the Jenkins CI job runs mvn spring-boot:run .... in a productions cluster as the only way to run the application. With this build step, in effect, we are running the springboot app only via maven and this has led to a very unstable jvm behavior. Also, I am unable to configure all the possible tweaks to the jvm e.g, turning on gc logging or changing to G1GC etc.. etc..
I just wanted to know if running my java springboot app should indeed be packaged into a fat jar and run with standard jvm flags, rather than from maven.
Please let me know your thoughts
Spring boot maven plugin has jvmArguments in order to set jvm settings.
......
<configuration>
<jvmArguments>-Xdebug</jvmArguments>
</configuration>
.......
The second option is to create a self-executable jar/war and use a standard way to run app - java -jar app.jar <jvm properties>
Our teams have been running fat jars similar to how others have stated with the simple java -jar ****.jar commands. However, once in production, you can utilize a container clustering system to construct the many microservices that make up your app. Seems like running maven and deploying source code, rather than artifacts seems dangerous. Hopefully this helps!

What does maven clean install -U do?

I have eclipse ide with m2e plugin, maven and weblogc app server running from my local box.
I have imported someone else's multiple maven projects from bitbucket to my box. I was told that one of them is main and rest are dependencies in which I never seen anything like that before. I have always dealt with single maven project. Anyhow from the instruction, it says I have to run maven command such as "clean install -U".
In the IDE so I touched run configuration for each mvn project by setting goal as "clean install -U". By reading maven guide, I kind understand what each term means but when you combine together with a passing parameter, what does it do actually? I didn't expect a jar (web app) to be deployed to an application server but it did also.
-U forces maven to check any external dependencies (third party dependencies) that might need to be updated based on your POM files.
clean install are both basic maven lifecycle phases (https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html).
install normally would simply take the artifact that is built and put it in the local repository, i.e. a directory on the box you are building on (.m2 directory most of the time). It would not do a deployment to a server - typically the deploy phase would be used to do that.
However, developers can override and add to what maven does in the various phases, so just like in the days of ant things can easily devolve into chaos no one can understand on complex projects ;-).
sometimes in the integration-test phase, developers will tell maven to start up a container temporarily to run the web app on, so that tests can be run against it, and then that container is shut down when the integration-test phase completes.

How do I deploy a maven created webapp to tomcat

So I was following http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ for a simple tutorial on how to use maven and jsf. I created a maven project by running mvn archetype:generate -Dfilter=org.apache:maven-archetype-webapp in my command prompt. Then I continued with the tutorial, I wound up creating all necessary files, but then when I got to the end, I realized I did have a server created. So I created one real quick, but when it came to the point of adding files to the server (from the add or remove dialog box), no projects or files showed up. I am not on my computer where the project is located so I can't copy/paste the .pom file in, but it looks practically exactly like the pom in the tutorial (only difference is groupId, artifact, ect.) No additional plugins, dependencies, or configs.
Do you want to deploy the webapp within Eclipse to Tomcat? Or as some sort of automatic/continuous deployment?
Within Eclipse you often need to add the Dynamic Web project and JSF facets to your project so Eclipse recognizes the project as deployment capable. If you are using m2eclipse make sure to install the m2eclipse wtp add on so this is done automatically.
If you want to add auto-deployment to the pom.xml I recommend using the maven cargo plugin: http://cargo.codehaus.org/Maven2+plugin - it supports the major containers.
For tomcat you need to modify the tomcat-users.xml to allow auto-deployment and leave the tomcat-manager application in place. If you have startet tomcat and pointing your browser to http://localhost:8080/manager/html/list it should either tell you to login or what to add to that file.
The configured user is then used in the configuration to deploy the war file via the tomcat-manager using the mvn cargo:deploy goal. The configuration has to be added to the pom.xml using war as packaging, not to the parent-pom.xml

Hot deploy war maven project in embedded tomcat

I have maven war project.
I know inplace. it deploys to a given server. But i want to deploy on embedded tomcat and dont want to restart everytime. just say
for first time run deploy
Then change some java class and say redeploy. All in embedded tomcat.
Is this possible ?
Could the Tomcat Maven Plugin help with this?
You can use it by using the command tomcat:run
This page describes how to set up your POM/settings to make calling the plugin easier (using a prefix vs having to use full groupId/artifactId of plugin on the command line).
Maybe you can have a look at the executable war/jar feature see http://tomcat.apache.org/maven-plugin-2/executable-war-jar.html
So that will produce a simple jar which contains tomcat classes. You will be able to simply run: java -jar pathtofile.jar.

Issues with classpath running Jetty via Maven

I'm using Maven to manage my build. For developer testing I use Jetty which I launch using the jetty:run goal in the Jetty Maven plugin. I should also note that I have war:exploded running in an earlier phase which builds the directory that Jetty runs against.
The problem I'm having is that the war:exploded task puts the build dependencies into WEB-INF/lib (as it should) and furthermore, Maven appears to be feeding Jetty the build classpath via the system classloader. This leads to every jar getting loaded twice which should be OK except that, sadly, the Datanucleus library throw an exception the second time it gets loaded onto the classpath.
The only solution I can think of at the moment is to create two profiles, a build profile and a developer test profile. The developer test profile would exclude all the dependencies and jetty:run would run in the developer test profile. This seems like a lot of configuration for something I think would be simple.
Does anyone know if there is a way to prevent Maven from loading the build classpath into Jetty?
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<useTestClasspath>true</useTestClasspath>
...
The option "useTestClasspath" should have the effect you are looking for.

Resources