Maven dependency on web application - maven

My Eclipse project is structured as such:
my.core.webapp (libs, java classes, web.xml, etc)
my.extended.webapp (libs, java classes AND a dependency to
my.core.webapp)
my.core.webapp pom:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my.company</groupId>
<artifactId>my.core.webapp</artifactId>
<version>1</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
.
</dependencies>
</project>
my.extended.webapp pom:
<dependency>
<groupId>my.company</groupId>
<artifactId>my.core.webapp</artifactId>
<version>1</version>
<type>war</type>
</dependency>
when I compile with maven I get various package xyz does not exist exceptions.
Is there a way (without having a 3rd project or using modules) to achieve that?

You will have to do 2 things here.
The first thing will be to add <attachClasses>true</attachClasses> to your maven war plugin configuration in my.core.webapp pom.xml. So now it should look like
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<attachClasses>true</attachClasses>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
The second thing to do will be to add <classifier>classes</classifier> while you are specifying my.core.webpp as a dependency in your my.extendend.webapp pom.xml. So it should now look like
<dependency>
<groupId>my.company</groupId>
<artifactId>my.core.webapp</artifactId>
<version>1</version>
<type>war</type>
<classifier>classes</classifier>
</dependency>
That should be all.

I managed to solve the problem based on #ritz-xavi answer.
my.core.webapp pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<attachClasses>true</attachClasses>
<webXml>${basedir}/WebContent/WEB-INF/web.xml</webXml>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
my.extended.webapp pom:
<dependency>
<groupId>my.company</groupId>
<artifactId>my.core.webapp</artifactId>
<version>1</version>
<classifier>classes</classifier>
<type>jar</type>
</dependency>
<dependency>
<groupId>my.company</groupId>
<artifactId>my.core.webapp</artifactId>
<version>1</version>
<type>war</type>
</dependency>
Including both the war and the jar classes did the trick.

Related

how to associate a goal to a specific phase in maven

I know maven's deploy meaning is "send the artifact to the repository" but what I want to do is associate the tomcat7-maven-plugin's deploy goal to the deploy phase or another one like install. I'm not able to associate it with the following configuration:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>userpom</artifactId>
<groupId>com.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>userweb</artifactId>
<packaging>war</packaging>
<name>userweb</name>
<url>http://www.test.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>userservices</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>userweb</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<!--<plugin>-->
<!--<artifactId>maven-deploy-plugin</artifactId>-->
<!--<version>2.8.2</version>-->
<!--</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>
<path>/usertest</path>
<update>true</update>
</configuration>
<executions>
<execution>
<id>tomcat-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
while the parent pom is the following:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>userpom</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>userservices</module>
<module>userweb</module>
</modules>
<packaging>pom</packaging>
<name>userpom</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
</dependencies>
</project>
basically, it's not executed and I have to call it manually:
mvn tomcat7:deploy
within the userweb folder. Any hint?
You're actually defining your tomcat7-maven-plugin only in pluginManagement but do not refer it anywhere outside in the build.plugins section.
A slightly altered version of your pom.xml showing only the relevant parts could be:
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>userpom</artifactId>
<groupId>com.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
[…]
<build>
<finalName>userweb</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<!--<plugin>-->
<!--<artifactId>maven-deploy-plugin</artifactId>-->
<!--<version>2.8.2</version>-->
<!--</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>
<path>/usertest</path>
<update>true</update>
</configuration>
<executions>
<execution>
<id>tomcat-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
If all artifacts which inherit the parent pom.xml shall benefit from your pre-configured tomcat7-maven-plugin then pull the pluginManagement section out of your sub pom.xml and put it into the build section of your parent pom.xml.

Maven+ReportNG+Jenkins+Command Line

I would like to know how can I run a test built with maven to generate the report and then convert the report to ReportNG format using the command line.
To after that insert the report on Jenkins using the plugin HTML Reporter from Jenkins.
I want to do this because I am getting error when I put the listeners on test.
I am using this to execute the test by Jenkins:
mvn test (after using "mvn clean install" on first time)
I try use mvn install but I am getting the same error
Thanks
EDIT: So I finally manage to fix my POM file, the problem has some plugins that aren't specified like velocity, reportng and guice. Anyway I will left here my POM fixed so it can help someone else =)
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>selenium.simple</groupId>
<artifactId>selenium-simple</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>selenium-simple</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- specify UTF-8, ISO-8859-1 or any other file encoding -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<webdriver.ie.driver>src/main/resources/drivers/internetexplorer/iedriverserver_2.24.1_x64.exe</webdriver.ie.driver>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Based on the error message:
Some problems were encountered while building the effective model
forselenium.simple:selenium-simple:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. # line 43,
column 12
You should pin the version for maven-surefire-plugin like the following:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
...
</plugin>
</plugins>
..
</build>
If don't do this as you you will use an old version (maven-surefire-plugin:2.10) which might be too old. I assume that after you put the version into your pom the problems with the listener will be gone.
BTW: Why not using up-to-date versions of maven-resources-plugin (2.6) and testng (6.8.7)..

Including xvfb plugin in Maven Pom.xml, nod <execution> error

Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:selenium-maven-plugin:2.3:xvfb (execution: xvfb, phase: test-compile)
I tried this: Plugin execution not covered by lifecycle configuration maven error but it didnt help
Here is my pom.xml. The error message appears at < execution > nod
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- asd -->
<groupId>com.pragmaticqa.tests</groupId>
<artifactId>functionalTests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>functionalTests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<displayProps>target/selenium/display.properties</displayProps>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.32.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.32.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>2.5</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<includes>
<include>**/*Test*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<!-- execution code would go here if needed -->
<executions>
<execution>
<id>xvfb</id>
<phase>test-compile</phase>
<goals>
<goal>xvfb</goal>
</goals>
<configuration>
<!-- <displayPropertiesFile>${displayProps}</displayPropertiesFile> -->
<!-- try removing the plugin declaration, try 0 or :0 -->
<display>:0</display>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<build>
<pluginManagement>
<plugins>
<plugin> ... </plugin>
<plugin> ... </plugin>
....
</plugins>
</pluginManagement>
</build>
Once this structure is in place, the error goes away.

tomee mvn install don't pack META-INF

When trying to build war file maven doesn't pack any META-INF using pom:
<modelVersion>4.0.0</modelVersion>
<groupId>demo-test</groupId>
<artifactId>core-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<name>test</name>
<url>http://maven.apache.org</url>
<properties>
<test.core.version>1.0.0</test.core.version>
</properties>
<modules>
<module>testDataModule</module>
<module>testFramework</module>
<module>testManagerModule</module>
<module>CoreWar</module>
</modules>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<!-- scope provided means the container delivers it -->
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.apache.openejb.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>1.5.2</version>
<configuration>
<finalName>test</finalName>
<tomeeVersion>1.5.2</tomeeVersion>
<tomeeClassifier>plus</tomeeClassifier>
<path>C:\test\code\test.core\CoreWar\target\test.war</path>
<debug>true</debug>
<tomeeHost>localhost</tomeeHost>
<tomeeHttpPort>8080</tomeeHttpPort>
<libs>
<lib>mysql:mysql-connector-java:5.1.20</lib>
</libs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>..\testFramework\WebFramework\src\webapp\WEB-INF\web.xml</webXml>
<outputFileNameMapping>#{groupId}#-#{artifactId}##{dashClassifier?}#.#{extension}#</outputFileNameMapping>
</configuration>
</plugin>
</plugins>
</build>
and I tried puting META-INF everywhere.
and don't replace tomee.xml
I tried the following structure:
myApp->src->resources->meta-inf/persistence.xml
myApp->src->webapp->meta-inf/persistence.xml
did you try webapp/WEB-INF/persistence.xml?

axis2, Maven and IntelliJ

I am trying to generate Java classes for a Web Service client using axis2. I keep getting a Cannot resolve symbol 'wsname_ServiceStub' The java file is not being picked up. Meanwhile the 'wsname_ServiceCallbackHandler' the java file in the same directory is getting picked up and I can reference to it from the rest of my project.
The file is showing up as a "not a class file" for some reason
I'm using IntelliJ 11.1.2 and Maven 2.2.1
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>AnotherWS</groupId>
<artifactId>AnotherWS</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-idea-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.2</version>
<configuration>
<!--<generateTestcase>true</generateTestcase>-->
<!--<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>-->
<packageName>wsname</packageName>
<wsdlFile>src/main/resources/wsname.wsdl</wsdlFile>
<!--<generateAllClasses>true</generateAllClasses>-->
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Resources