Maven tomcat plugin - java

is it possible to run spring mvc application on tomcat(with this plugin http://mojo.codehaus.org/tomcat-maven-plugin/) if yes, where is the application log and deploy web app directory located ?
Let me rephrase the question. I'm asking for some way to start my web app(spring mvc application) from a command line, either with maven or with something inside application that creates web server.
What would you recommend? I found this tomcat maven plugin while googling, no special reason to use it
Currently I use jboss server for this application, but I want to run both server and application from application,any suggestions?

tomcat:run runs a web application in an embedded tomcat instance ... useful for testing during development.
See http://mojo.codehaus.org/tomcat-maven-plugin/run-mojo.html for listing of config parameters for the run goal, including warSourceDirectory which, if not specified defaults to ${basedir}/src/main/webapp

I'm not sure exactly why but we use the mvn cargo:start plugin instead, for testing locally when building with maven. We also utilize Spring and haven't had any issues regarding the mix. When starting up the Tomcat container with the command above it shows the following in the console
C:\SVN\myproject-war\target\tomcat6x\home>
This contains the webapps folder where the war is deployed and a logs folder.
Hope this helps, sorry I don't have direct experience with the tomcat-maven-plugin itself.

If I understand your question correctly, from your application you want to start tomcat to serve a spring MVC application.
If so, you do not need maven or a maven plugin to do this. You can use tomcat catalina APIs to achieve this. Though dated, this article explains how.
As the other answers stated, maven's tomcat and cargo plugins allow you to start and stop tomcat from maven - typically to run some integration tests.

Related

How to run java Google App Engine locally with app-gradle-plugin for yaml?

I am using Google App Engine gradle plugin with yaml file, but the plugin version for it has no task appengineRun or appengineStart like the appengine-web.xml version.
TL;DR appengineRun is only available for appengine-web.xml based projects. If you want to use app.yaml, you must provide your own server, for example Spring Boot with Jetty or Tomcat.
To run your application locally, you must provide your own server.
This guide shows how to test your application using app.yaml alongside with the app-gradle-plugin, on section Testing your application with the development server:
During the development phase, you can run and test your application at any time in the development server by invoking Gradle:
gradle jettyRun
Alternatively, you can run Gradle without installing it by using the Gradle wrapper.
As said on this comment on GitHub:
If you want to use app.yaml from your root directory, you must upgrade to Java 11. Learn more here. With the Java 11 runtime, you must provide your own server, for example Spring Boot with Jetty or Tomcat. The appengine:run goal does not work for app.yaml based projects because each server has a different start up command i.e. spring-boot:run for Spring Boot.

What is the enterprise use of the Jetty plugin in Maven?

Since I learn from some maven tutorials we can import Jetty as a maven plugin like this.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
</configuration>
</plugin>
And can run the plugin like this.
$ mvn jetty:run
Also we can change the port and context path and lots of stuff in this plugin.
As I understood that we can use Jetty as a server like tomcat, and we can deploy an application through it.
But the thing I don't understand is what is the actual enterprise use of Jetty in maven..
From the official documentation:
The Jetty Maven plugin is useful for rapid development and testing. You can add it to any webapp project that is structured according to the Maven defaults. The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found. This makes the development cycle more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project, and the running web container automatically picks them up, allowing you to test them straight away.
However (and maybe this addresses what you call "enterprise use"):
While the Jetty Maven Plugin can be very useful for development we do not recommend its use in a production capacity. In order for the plugin to work it needs to leverage many internal Maven apis and Maven itself it not a production deployment tool. We recommend either the traditional distribution deployment approach or using embedded Jetty.
The main usage is for testing, Jetty can also be started programmatically (see this example Java code) which means you can start server directly from your code and interact with your REST API for instance.
You can also use it for easier deployment of small applications, just package everything into the JAR which runs server from main method when executed via java -jar your-app.jar. You don't need any dependencies installed except Java then.
As a side note, I currently work in Clojure (JVM language based on Lisp) and many people deploys their application as JAR which internally runs embedded Jetty because this way it's also starts REPL which you can connect to remotely and debug your application when it's running.
I don't know exactly what you mean by enterprise use, but let's say you're developing a web application and it's a Maven project.
Each time you want to test whether the web application works correctly, you need to deploy the web archive (WAR) on a web server, e.g. Jetty or Tomcat. Usually this involves a couple of manual steps like:
Start the web server
Deploy the WAR on it
Where the Maven plugin comes in handy is that it allows you to just execute
mvn jetty:run-war
and it does all these steps automatically for you in a single command, saving you lots of time. The plugin is even able to redeploy the application once it notices changes have been made.

tomcat-maven-plugin in GWT project. What is the difference between: org.codehaus.mojo and org.apache.tomcat.maven plugin

I am trying to set up tomcat server for gwt application. I would like to configure server to update my server side code changes immediately.
While looking for some helpful examples over the web, I found that there are to plugins for maven.
One from:
org.codehaus.mojo (which also provide plugin for gwt in maven echosystem).
And second from: org.apache.tomcat.maven.
What is the difference between them? Which one should I choose for:
GWT 2.7 Maven Project. I will develope app in Eclipse IDE. So I would like to have good integration with it to. F.e.: the Eclipse tab/view "Servers".
From https://tomcat.apache.org/maven-plugin-2.2/
This is the new home for the Tomcat Maven Plugin (previously hosted at Codehaus).
The CodeHaus Mojo (now MojoHaus) Tomcat Maven Plugin is obsolete.
I have Maven archetypes that use the Tomcat Maven Plugin to fire up a server for development, with automatic redeployment of the webapp when classes change, at https://github.com/tbroyer/gwt-maven-archetypes
Note that they use a different Maven Plugin for GWT than the one from MojoHaus (ex-CodeHaus Mojo), one that works much better with multi-module builds.
I've never used Eclipse WTP though (tried it and had too much trouble, probably because I didn't really know how to use it properly though) so I can't really comment, but I see no reason why it wouldn't work.

Implement tomcat in java to deploy war

I am trying to deploy my war using tomcat (implement in java) before running my functional test. Initially I implemented Jetty Server in java and I successfully exposed the URI and I could execute my test. But I want to deploy my war to test it and not just expose the URI,I can obviously use jetty plugin and cargo in my pom file, but I want to use tomcat to do so. I thoroughly searched online, I found sample code on deploying war using tomcat implementation in java [1], so that I can start tomcat, deploy my war and then run my functional test. But it is not clearly explained. Can I refer to any good documentation online which will help me with deploying my war using tomcat?
[1] http://www.programcreek.com/java-api-examples/index.php?api=org.apache.catalina.startup.Tomcat
Depending on your level of testing the recommended maven approach would be one of the following
For unit tests
Put any startup of maven and possibly deployment in the pretest phase
process-test-classes
Then run the tests in the test phase
test
This approach will work if the unit tests themselves need to be deployed to tomcat to run small parts of the code base note there is no way here to shutdown tomcat you will need to find a phase to bind the shutdown to.
For integration tests that need to run the whole war file Put any startup of maven and possibly deployment in the pre-test phases
pre-integration-test
Run the test in the test phase
integration-test
Undeploy and shutdown during the post test phase
post-integration-test
Under this scenario the link you included in your question becomes relevant.

What is an alternative to jetty-maven-plugin?

Is there any workable alternative to jetty-maven-plugin? This particular plugin is not supported properly. I even failed to find its source code repository.
What I need is an embedded container for integration testing.
There is a very similar Tomcat Maven Plugin. Works exactly the same, except... it uses Tomcat. You might also try Maven Cargo plugin that uniforms deploy process to several different containers/servers.
There's an embedded-glassfish plugin that can be used for this.
I often use an embedded jetty server that is started in the #beforeClass part of an junit test. That embedded jetty along with openejb provides most things you need without having to deploy your application anywhere

Categories