Tomcat 8 Maven Plugin for Java 8
Asked Answered
S

6

81

Is the tomcat7-maven-plugin working with a tomcat 8 server and java 8? I can't find any tomcat8-maven-plugin.

Serilda answered 12/11, 2014 at 9:49 Comment(4)
Unfortunately it is not ready issues.apache.org/jira/browse/MTOMCAT-234Harlow
Try using Cargo See answer : #24271713Skaw
Could you explain what you mean in Tomcat7-maven-plugin working with a tomcat 8 server? how you make plugin to work with stand-alone server? plugin starts its own server..Guru
Does this answer your question? Tomcat 8 integration with MavenRecept
O
81

Yes you can,

In your pom.xml, add the tomcat plugin. (You can use this for both Tomcat 7 and 8):

pom.xml

<!-- Tomcat plugin -->  
<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>    *(From maven > settings.xml)*
  <username>*yourtomcatusername*</username>  
  <password>*yourtomcatpassword*</password>   
 </configuration>   
</plugin>   

tomcat-users.xml

<tomcat-users>
    <role rolename="manager-gui"/>  
        <role rolename="manager-script"/>   
        <user username="admin" password="password" roles="manager-gui,manager-script" />  
</tomcat-users>

settings.xml (maven > conf)

<servers>  
    <server>
       <id>TomcatServer</id>
       <username>admin</username>
       <password>password</password>
    </server>
</servers>  

*** deploy/re-deploy**

mvn tomcat7:deploy OR mvn tomcat7:redeploy

Tried this on (Both Ubuntu and Windows 8/10):

  • Jdk 7 & Tomcat 7
  • Jdk 7 & Tomcat 8
  • Jdk 8 & Tomcat 7
  • Jdk 8 & Tomcat 8
  • Jdk 8 & Tomcat 9

Tested on Both Jdk 7/8 & Tomcat 7/8. (Works with Tomcat 8.5 and 9)

Note:
Tomcat manager should be running or properly setup, before you can use it with maven.

Good Luck!

Outmarch answered 28/1, 2016 at 10:33 Comment(10)
> mvn org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run INFO: Starting Servlet Engine: Apache Tomcat/7.0.47Maggi
that's nice only if you have tomcat on your local PC. Doesn't solve the problem for embedded tomcatKrall
Putting the username and password in the POM is redundant and a security risk (especially if you check your code into a repository). The whole point of identifying the server by ID in the POM is so that Maven can look up the username and password in the user-specific settings file (not checked into source control). But otherwise this post was really helpful---thanks.Grenoble
tomcat7-maven-plugin, what does 7 stands for? Is it java version or tomcat version. Can I use tomcat7-maven-plugin with Tomcat-9?Aslam
Where can I find the following files: tomcat-users.xml - (PROJECT_NAME\target\tomcat\conf\tomcat-users.xml?), settings.xml - (???). I have maven project but still can't figure it outCravens
In this solution, it uses a separate apache tomcat installed and you can find in the location or path where you installed tomcat (or extracted if coming from a zip or tar.gz file). For example, C:\apache-tomcat-8\conf\tomcat-users.xml. If you are in ubuntu... example would be /opt/tomcat/conf/tomcat-users.xmlOutmarch
@BorgyManotoy "will test Tomcat 9 soon" – did you try?Amortizement
I just did and it works... just note that when you update maven, you might lose the old configuration. Goodluck!Outmarch
Is it possible that I deploy my app with the plugin only without the tomcat server installed?Cottar
Yes it is possible, but I am not sure if it is advisable to deploy/run the application with just plugin, when in production mode.Outmarch
M
6

Plugin run Tomcat 7.0.47:

mvn org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run

 ...
 INFO: Starting Servlet Engine: Apache Tomcat/7.0.47

This is sample to run plugin with Tomcat 8 and Java 8: Cargo embedded tomcat: custom context.xml

Maggi answered 6/7, 2016 at 13:39 Comment(0)
G
1

Almost 2 years later....
This github project readme has a some clarity of configuration of the maven plugin and it seems, according to this apache github project, the plugin itself will materialise soon enough.

Glimmer answered 7/9, 2016 at 13:17 Comment(1)
linking my answer through this url #37371427Unaccomplished
R
0

Since November 2017, one can use tomcat8-maven-plugin:

<!-- https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin -->
<dependency>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat8-maven-plugin</artifactId>
    <version>2.2</version>
</dependency>

Note that this plugin resides in ICM repo (not in Maven Central), hence you should add the repo to your pluginsRepositories in your pom.xml:

<pluginRepositories>
    <pluginRepository>
        <id>icm</id>
        <name>Spring Framework Milestone Repository</name>
        <url>http://maven.icm.edu.pl/artifactory/repo</url>
    </pluginRepository>
</pluginRepositories>
Recept answered 11/2, 2020 at 20:19 Comment(2)
tried but saw Could not transfer artifact org.apache.tomcat.maven:tomcat8-maven-plugin:pom:2.2 from/to icm (http://maven.icm.edu.pl/artifactory/repo): Authentication failed for http://maven.icm.edu.pl/artifactory/repo/org/apache/tomcat/maven/tomcat8-maven-plugin/2.2/tomcat8-maven-plugin-2.2.pom 401 UnauthorizedNull
Moreover, it is not secure to download anything on your laptop from third-party like maven.icm.edu.pl/artifactoryLucas
A
0

An other solution (if possible) would be to use TomEE instead of Tomcat, which has a working maven plugin:

<plugin>
    <groupId>org.apache.tomee.maven</groupId>
    <artifactId>tomee-maven-plugin</artifactId>
    <version>7.1.1</version>
</plugin>

Version 7.1.1 wraps a Tomcat 8.5.41

Attested answered 21/4, 2020 at 14:10 Comment(0)
L
-1

groupId and Mojo name change Since version 2.0-beta-1 tomcat mojos has been renamed to tomcat6 and tomcat7 with the same goals.

You must configure your pom to use this new groupId:

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat6-maven-plugin</artifactId>
      <version>2.3-SNAPSHOT</version>
    </plugin>
    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.3-SNAPSHOT</version>
    </plugin>
  </plugins>
</pluginManagement>

Or add the groupId in your settings.xml

.... org.apache.tomcat.maven ....

Lorinalorinda answered 24/1, 2018 at 3:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.