Tomcat 7 - Maven Plugin? - maven-2

I just wanted to double-check, has anyone found or is working on a Tomcat 7 plugin? If not, is anyone interested in helping me get it up and running?
I want another quick alternative to Glassfish, JBoss AS 6.0 is a bit heavy still for quick mockups.
Walter

It work for me as the following.
My setting.xml
<server>
<id>local_tomcat</id>
<username>ray</username>
<password>password</password>
</server>
My plugin configuration
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>local_tomcat</server>
<url>http://localhost:8080/manager/text</url>
</configuration>
</plugin>
My tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user password="password" roles="manager-gui, manager-script" username="ray"/>

i use the official Tomcat7 Maven Plugin from Apache as follows:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/${project.artifactId}</path>
<port>8080</port>
</configuration>
</plugin>
and to run it: mvn tomcat7:run

There is t7mp - a Tomcat 7 Maven Plugin - on Google code.
Cargo (and its Cargo Maven2 Plugin) also has support for Tomcat 7 (this was CARGO-790).
Apache Tomcat Maven Plugin 2.0-beta-1 supports Tomcat 7.

Using maven cargo your can coufigure your project that way :
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.6</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>installed</type>
<home>${catalina.home}</home>
</container>
<configuration>
<type>existing</type>
<home>${catalina.home}</home>
</configuration>
<deployer>
<type>installed</type>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
don't forget to configure your catalina.home property
The you can deploy it using:
mvn cargo:deploy

There is the Tomcat Maven Plugin 7 plugin developed by the Apache Tomcat team.
Currently you have to checkout the sources and install it to your local repository.
After that you can use it in the plugin section of your pom:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<executions>
<execution>
<id>start-tomcat</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<path>/</path>
<serverXml>src/main/tomcatconf/server.xml</serverXml>
</configuration>
</execution>
</executions>
</plugin>

After I had this error for three days in a row, here's my solution:
The user you are using to connect needs at least the role manager-script.
In your /conf/tomcat-users.xml
<role rolename="manager-script"/>
<user username="test" password="test" roles="manager-script"/>
In your pom.xml, include the following plugin
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://server.url:8080/manager/text</url>
<path>/YourApp</path>
<username>test</username>
<password>test</password>
</configuration>
</plugin>
Contrary to what I found in the internet you DON'T need to edit your maven setting.xml. The tomcat7-maven-plugin can be configured directly in the configuration-tag
A word to the url-tag: I tested the suffix
/manager
/manager/html
/manager/text
of which only /manager/text worked
My versions:
Tomcat: 7.0.33
Maven: 3.0.4
tomcat7-maven-plugin: 2.0
Java: 1.7.0_07

I'm using tomcat7-maven-plugin for my embedded tomcat instance. Here is how I have configured it. Since my app requires jaas authentication I can also provide that in the setting itself.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<!-- http port -->
<port>8080</port>
<path>/gcs-explorers</path>
<contextFile>${basedir}/src/main/webapp/META-INF/context.xml</contextFile>
<addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
<systemProperties>
<java.security.auth.login.config>${basedir}/conf/jaas.config</java.security.auth.login.config>
</systemProperties>
<url>http://127.0.0.1:8080/manager/html</url>
<username>admin</username>
<password>admin</password>
<addContextWarDependencies>true</addContextWarDependencies>
<addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
<configurationDir>${basedir}</configurationDir>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.2.0</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.company.package.jaas</groupId>
<artifactId>gcs-jaas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.company.gcs</groupId>
<artifactId>package-file-share</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>

Actually, the standard plugin works for me . I just had to create the role manager-script in tomcat users and change the url parameter to http://localhost:8080/manager/html in order to make it work :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/html</url>
<server>local</server>
<path>/${project.artifactId}</path>
<update>true</update>
</configuration>
</plugin>

For Tomcat 7,
Step 1:
Modules tab of server add
Document base: <PATH>\Apache-Tomcat-7.0.0\webapps\manager
Path: /manager
Step 2:
Update POM to:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/text</url>
<update>true</update>
<warFile>target/${project.artifactId}-${project.version}.war</warFile>
<path>/${project.artifactId}</path>
<username>tomcat_user</username>
<password>tomcat_password</password>
</configuration>
</plugin>

Related

Where do I specify my custom reverse engineering class when using the hibernate-tools plugin for maven?

I have a custom strategy but I can't figure out how to get this plugin to use it.
My relevent pom section is:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
</plugin>
<plugin>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools-maven-plugin</artifactId>
<version>5.4.1.Final</version>
<executions>
<execution>
<id>Display Help</id>
<phase>validate</phase>
<goals>
<goal>help</goal>
</goals>
</execution>
<execution>
<id>Entity generation</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<templatePath>src/main/resources/templates/</templatePath>
<!-- Defaults: -->
<outputDirectory>generated-sources/</outputDirectory>
<ejb3>false</ejb3>
<jdk5>false</jdk5>
</configuration>
</execution>
<execution>
<id>Schema generation</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<!--Possible targetType: SCRIPT (default), STDOUT, DATABASE -->
<targetTypes>
<param>SCRIPT</param>
<param>STDOUT</param>
<param>DATABASE</param>
</targetTypes>
<!-- Defaults: -->
<outputDirectory>generated-resources/</outputDirectory>
<!--Possible schemaExportAction: CREATE (default), DROP, BOTH -->
<schemaExportAction>CREATE</schemaExportAction>
<outputFileName>schema.ddl</outputFileName>
<delimiter>;</delimiter>
<haltOnError>true</haltOnError>
<format>true</format>
</configuration>
</execution>
</executions>
<configuration>
<revengFile>src/main/hibernate/hibernate.reveng.xml</revengFile>
<!-- Defaults: -->
<packageName></packageName>
<configFile>src/main/hibernate/hibernate.cfg.xml</configFile>
<detectManyToMany>true</detectManyToMany>
<detectOneToOne>true</detectOneToOne>
<detectOptimisticLock>true</detectOptimisticLock>
<createCollectionForForeignKey>true</createCollectionForForeignKey>
<createManyToOneForForeignKey>true</createManyToOneForForeignKey>
</configuration>
<dependencies>
<!-- databases -->
<dependency>
<!-- DB Driver of your choice -->
<groupId>com.oracle</groupId>
<artifactId>oracle-jdbc8</artifactId>
<version>18</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>5.4.1.Final</version>
</plugin>
<!--
<plugin>
<groupId>org.springframework.boot</groupId>
</plugin>
-->
</plugins>
</pluginManagement>
</build>
And my hibernate.reveng.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="DATE" hibernate-type="java.time.LocalDate"/>
<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.time.LocalDateTime"/>
</type-mapping>
</hibernate-reverse-engineering>
Additionally, although in the config I have specified to use "src/main/hibernate/hibernate.cfg.xml" it is reading "hibernate.properties"
I guess the example I got https://github.com/stadler/hibernate-tools-maven-plugin has the wrong configuration property name.
So:
1) The initial question
2) How do I configure this to use the specified configuration file?
3) Where is there a list of all the configuration problems and finally despite having
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>5.4.1.Final</version>
</plugin>
</plugins>
</pluginManagement>
I am getting "plugin execution not covered by lifecycle" in eclipse
So apparently I did not correctly follow this StackOverflow answer How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
The documentation says add a revengStrategy configuration to the plugin with the full name of the class that extends DefaultReverseEngineeringStrategy. However when you try this, it throws class not instanced error. I have raised an issue with hibernate tools.
However, I have seen solutions where this is working if you have multi module project. The custom class should be part of a different module and that module should be added as a plugin dependency.
If I hear back from hibernate tools, you can find it here later
https://jonamlabs.com/how-to-use-hibernate-tools-maven-plugin-to-generate-jpa-entities-from-an-existing-database/

maven tomcat7:run configure datasource

I have a multimodule maven project, and I want to use it with tomcat7 maven plugin and start it with:
mvn tomcat7:run
But I can't figure out how to configure a jndi datasource.
I've tried to put in my pom.xml:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<contextFile>tomcat/context.xml</contextFile>
</configuration>
</plugin>
and in the context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/AppealDS" url="jdbc:hsqldb:file:database/appeal"
driverClassName="org.hsqldb.jdbcDriver" username="appeal"
password="appeal" auth="Container" type="javax.sql.DataSource"
maxActive="3" maxIdle="2" maxWait="10000" />
</Context>
But it doesn't work...How can I register the jndi datasource?
What is the error message?
Use:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextFile>tomcat/context.xml</contextFile>
</configuration>
</plugin>
Maybe your jdbc driver is not available in the classpath?
Try adding him in the plugin dependency
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<contextFile>tomcat/context.xml</contextFile>
</configuration>
<dependencies>
<dependency>
here your hsql version
</dependency>
</dependencies>
</plugin>

How do you Configure Selenium Server using selenese command from Maven-Selenium plugin?

I am trying to configure the selenium server that is used by the selenese command by the Maven-Selenium plugin from codehaus. I have tried to create multiple executions within the plugin start the server in the pre-integration-test phase, which didn't work. The selenium-server simply went into an infinite loop, listening on a port.
I want to know if there is a way to override/configure the selenium-server that the selenese command uses in the plugin. Please let me know.
Please see the POM snippet below.
....
<properties>
<selenium.version>2.0b3</selenium.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>1.1</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>${selenium.version}</version>
<type>pom</type>
<exclusions>
<!-- prevent ant:ant versus org.apache.ant:ant collision -->
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<executions>
<execution>
<id>Run-Script</id>
<phase>integration-test</phase>
<goals>
<goal>selenese</goal>
</goals>
<configuration>
<browser>*firefox</browser>
<suite>src/test/selenium/html/TestSuite.html</suite>
<startURL>http://localhost:4444/</startURL>
<results>${project.build.directory}/results/${browser.type}-${test.type}-results.html</results>
<port>4444</port>
<timeoutInSeconds>${selenium.server.timeout.seconds}</timeoutInSeconds>
<multiWindow>${multiple.windows}</multiWindow>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
....
Thanks,
Juan
Try setting startURL to the url of the application under test instead of pointing to the selenium rc server url. For example, if your selenium test case is clicking a link on google, set startURL to http://www.google.com
Here's a snippet from my pom that's working**
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<configuration>
<browser>*firefox</browser>
<startURL>http://my-site.com</startURL>
<suite>test-suite</suite>
<!-- <logOutput>true</logOutput> -->
<!-- <timeoutInSeconds>30</timeoutInSeconds> -->
</configuration>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>selenese</goal>
</goals>
</execution>
</executions>
</plugin>
** It works great except that on Mac OS, firefox just stays open and doesn't close?! But, hope that helps.

Compile Jasper reports from Maven with ant task?

How can I compile jrxml jasper files using Maven and JRAntCompileTask ant task? I tried using a maven plugin for compiling jasper reports files but it's still in beta, and it caused me many problems. I'd like to see the configuration in pom.xml.
How can I compile jrxml jasper files using Maven and JRAntCompileTask ant task?
You can use the custom Ant Tasks with the Maven AntRun Plugin. See the example provided in Using tasks not included in Ant's default jar.
You can try jasperreports-maven-plugin, that way you don't have to use ant, Here is an example.
Here's a complete example that solves problems with Eclipse m2e reporting errors with maven configuration, has reports neatly set in a separate folder and has classpath configured.
Just be sure to put your .jrxml files in src/main/jasperreports folder and you're set - every time you change the report, .jasper files will be regenerated.
pom.xml:
<properties>
<jasperreports.version>5.0.0</jasperreports.version>
</properties>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<versionRange>[1.0-beta-2,)</versionRange>
<goals>
<goal>compile-reports</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<!-- Include the generated reports in classpath -->
<directory>target/jasper</directory>
</resource>
<resource>
<!--Folder with .jrxml report files -->
<directory>src/main/jasperreports</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<configuration>
<!-- Folder where compiled reports will be generated -->
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<exclusions>
<exclusion>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>4.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...

Problems with maven output directory

I'm using almost same POM for both my projects, they are on the same workspace but they are not related at all, they are related however because in both I use spring and jboss. Here is the pom :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springinaction.hello</groupId>
<artifactId>spring-in-action</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>spring-in-action</name>
<url>http://maven.apache.org</url>
<properties>
<jboss.ome>C:\jboss-5.1.0.GA\server\default\deploy</jboss.ome>
<springversion>2.5.3</springversion>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>${springversion}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<warName>spring-book</warName>
<outputDirectory>${jboss.ome}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
What I want to achieve with this POM is that I want to name my war when built spring-book.war and copy it to Jboss location I specified. Now in my first project this works it does exactly what I requested but in other it does not. I changed springversion and jboss home properties variable but everything remains the same, what can I do ? The project builds and all, everything is working perfectly just I don't want to copy everytime in my jboss dir and previously remove the old war, it takes about 20sec on each source code change its a lot
Problem spotted at this line:
<packaging>jar</packaging>
You're not using the right packaging, it should be:
<packaging>war</packaging>
After this change the war plugin should get called and things should work like in the other project :)
You could leave the output directory at its default, and use a profile instead with the maven jboss plugin. It has a hard-deploy target which copies your artifact to the deploy directory. If it's in a profile, you can activate it when (and only when) you want.
Moreover, with the antrun plugin, you can also delete the old war file before copying over the new one (this is useful when the war filename includes the version, but in your case may not be needed).
<profiles>
<profile>
<id>deploy</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>remove-old-war</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete>
<fileset dir="${jboss.ome}"
includes="*.war"/>
</delete>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<executions>
<execution>
<id>redeploy-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>hard-deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can then activate the profile with
mvn -Pdeploy install