Ivy not ignored jars marked as exclusion in pom - pom.xml

This is my ivy.xml:
<dependencies defaultconf="default">
<dependency org="com.mycompany" name="custom" rev="1.0"/>
</dependencies>
ivysettings.xml:
<ivysettings>
<settings defaultResolver="repo.mycompany.com" />
<resolvers>
<ibiblio name="repo.mycompany.com" root="http://repo.mycompany.com/maven/" m2compatible="true" usepoms="true" />
</resolvers>
</ivysettings>
Artifact com.mycompany:custom:1.0 created as maven pom and published to repo.mycompany.com:
<?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>com.mycompany</groupId>
<artifactId>custom</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>logkit</groupId>
<artifactId>logkit</artifactId>
</exclusion>
<exclusion>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Wheh I download ivy libs with such code:
<target name="ivy-init">
<mkdir dir="${internal-libs}"/>
<ivy:settings file="${ivy.settings.dir}/ivysettings.xml"/>
<ivy:retrieve pattern="${internal-libs}/[artifact]-[revision].[ext]" sync="true" />
</target>
ivy download excluded deps avalon-framework:avalon-framework:4.1.3 and logkit:logkit:1.0.1
Why? I exluded it in pom!
How to exclude it with ivy, keeping the same simple ivy.xml?

Resolve this in next steps:
review my pom.xml and add exclusion to other artifact depends on
commons-logging:commons-logging
update to latest ivy
clean local ivy cache

Related

adding a "outdated " maven dependency from different url (repository)

let say we would like to add this maven dependency in our POM.xml file from http://maven.jahia.org/maven2/ to a exiting POM file. What are some good(industry) practices of adding com.sun(or tools) dependency super pom ? new to maven, example or short reasonings are appreciated.
<!-- https://mvnrepository.com/artifact/com.sun/tools -->
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
</dependency>
<!-- Note: (http://maven.jahia.org/maven2/) -->
The existing POM file like this:
<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>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>example-common</artifactId>
<packaging>jar</packaging>
<description>example</description>
<properties>
<example-version>7.2.0</example-version>
</properties>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-sdk</artifactId>
<version>${example-version}</version>
</dependency>
<dependencies>
</project>
This is a bit of an old question, but I had the same issue, and this worked.
Add into your project pom (also possible in maven settings if you need it for several projects), the Jahia repo.
<project>
...
<repositories>
<repository>
<id>jahia</id>
<name>jahia</name>
<url>http://maven.jahia.org/maven2/</url>
</repository>
</repositories>
...
</project>
If it's in the maven settings, then you put it inside of a profile but need to activate the profile when running maven (-Pprofilename) or via activation by default in settings.xml:
<profile>
...
<activation>
<activeByDefault>true
...
</profile>

referencing modules in pom packaging

How do I reference a module that is included in a pom.xml?
In the pom.xml referenced below how would I include the modules on the this pom so that it can be referenced in other projects as so:
<dependency>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
pom.xml
<?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>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<dependencies>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
</project>
I think the best you can do is to put your sub-modules in the dependencyManagement section of your parent POM like so:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>module1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>module2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>module3</artifactId>
<version>${project.version}</version>
</dependency>
<dependencies>
</dependencyManagement>
Then you can configure each of your sub-modules with whatever dependencies they need, without having to worry about the correct version number.
<!-- module2's dependencies -->
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>module1</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>module3</artifactId>
</dependency>
<dependencies>
If you declared all the sub-modules as dependencies of the parent POM, then you'd end up with cyclic dependencies. For example:
[parent] -> [module1] -> [parent]
Maven doesn't like that.

Webapp runs correctly with jetty 9 maven plugin, but not with jetty runner

Being new to Maven, I'm trying to make an executable jar of my webapp with an embedded jetty. Unfortunately, I'm having many difficulties achieving this, and decided to follow a step-by-step progression: first using jetty-maven-plugin (OK, with a lot of pain), then using jetty-runner (KO, the matter of this SO question), and finally using embedded jetty (KO).
I've spent so much time doing this, having different exceptions depending on the jetty version and pulled so much hair out, that I finally decided to ask the community for some help.
I hope this question won't be marked as a duplicate of SO #12241989 (or any other similar), because I have the same kind of problem, but clearly not the same root cause since I'm using the same version of jetty-maven-plugin and jetty-runner.
Context
webapp uses JSF2 (mojarra 2.2.8) + CDI (weld) + Primefaces + Websockets
Configuration
1. Jetty plugin
excerpt from pom.xml
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<jetty.groupId>org.eclipse.jetty</jetty.groupId>
<jetty.version>9.0.4.v20130625</jetty.version>
<jetty.descriptor>${project.basedir}/src/main/webapp/WEB-INF/web.xml</jetty.descriptor>
<jetty.env>${project.basedir}/src/main/webapp/WEB-INF/jetty-env.xml</jetty.env>
<jetty.contextPath>/</jetty.contextPath>
<jetty.overrideDescriptor>${project.basedir}/src/main/webapp/WEB-INF/jetty-web-override.xml</jetty.overrideDescriptor>
<myfaces.version>2.2.5</myfaces.version>
<mojarra.version>2.2.8</mojarra.version>
</properties>
...
<plugin>
<groupId>${jetty.groupId}</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<webApp>
<contextPath>${jetty.contextPath}</contextPath>
<descriptor>${jetty.descriptor}</descriptor>
<jettyEnvXml>${jetty.env}</jettyEnvXml>
<overrideDescriptor>${jetty.overrideDescriptor}</overrideDescriptor>
</webApp>
<contextXml>
${project.basedir}/src/main/webapp/WEB-INF/jetty-context.xml
</contextXml>
</configuration>
</plugin>
jetty-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="serverClasses">
<Array type="java.lang.String">
<Item>
-org.eclipse.jetty.servlet.ServletContextHandler.Decorator
</Item>
</Array>
</Set>
</Configure>
jetty-env.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="appManager" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>
<Ref id="webAppCtx" />
</Arg>
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
<Arg />
</New>
</Arg>
</New>
</Configure>
jetty-web-override.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- CDI-->
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<!-- mojarra -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
With this configuration, the application runs correctly. sigh of relief
2. Jetty runner
I believe the easiest way to reproduce the above configuration with jetty runner is using a jetty context xml file that describes my webapp. So I ended up with the following context file :
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">target/myapp.war</Set>
<Set name="descriptor">src/main/webapp/WEB-INF/web.xml</Set>
<Set name="overrideDescriptor">src/main/webapp/WEB-INF/jetty-web-override.xml</Set>
<Set name="serverClasses">
<Array type="java.lang.String">
<Item>
-org.eclipse.jetty.servlet.ServletContextHandler.Decorator
</Item>
</Array>
</Set>
<New id="appManager" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>BeanManager</Arg>
<Arg>
<New class="javax.naming.Reference">
<Arg>javax.enterprise.inject.spi.BeanManager</Arg>
<Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
<Arg />
</New>
</Arg>
</New>
</Configure>
Then when I run the jetty runner (with the same version):
java -jar jetty-runner-9.0.4.v20130625.jar context.xml
...everything seems OK, except the (annoying) fact that the startup listener of my app (annotated with Servlet 3.0 #WebListener) does not start.
And if I try to navigate to http://localhost:8080/, I get the following stack trace:
HTTP ERROR 500
Problem accessing /. Reason:
Server Error
Caused by:
javax.faces.view.facelets.TagAttributeException: /index.xhtml #119,66 src="/WEB-INF/include/#{applicationManager.layout}.xhtml" /index.xhtml #119,66 src="/WEB-INF/include/#{appli
cationManager.layout}.xhtml": java.lang.NullPointerException
at com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:358)
at com.sun.faces.facelets.tag.TagAttributeImpl.getValue(TagAttributeImpl.java:322)
at com.sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.java:112)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:203)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:990)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
...
Caused by: javax.el.ELException: /index.xhtml #119,66 src="/WEB-INF/include/#{applicationManager.layout}.xhtml": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at com.sun.faces.facelets.tag.TagAttributeImpl.getObject(TagAttributeImpl.java:356)
... 60 more
Caused by: javax.el.ELException: java.lang.NullPointerException
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
If I try to enforce the listening of my StartupListener class by specifying in web.xml:
<listener>
<listener-class>fr.mygroup.myapp.listeners.StartupListener</listener-class>
</listener>
...I get the same error.
Anyway, the fact that my StartupListener is not listened is clearly not the cause of the error but a consequence. But I can't figure out what's wrong with my jetty-runner configuration.
I desperately feel like it's a long way to go to an executable überjar of my webapp :(
Appendix
pom.xml
<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>fr.mygroupid</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<jetty.groupId>org.eclipse.jetty</jetty.groupId>
<jetty.version>9.0.4.v20130625</jetty.version>
<jetty.descriptor>${project.basedir}/src/main/webapp/WEB-INF/web.xml</jetty.descriptor>
<jetty.env>${project.basedir}/src/main/webapp/WEB-INF/jetty-env.xml</jetty.env>
<jetty.contextPath>/</jetty.contextPath>
<jetty.overrideDescriptor>${project.basedir}/src/main/webapp/WEB-INF/jetty-web-override.xml</jetty.overrideDescriptor>
<myfaces.version>2.2.5</myfaces.version>
<mojarra.version>2.2.8</mojarra.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>${jetty.groupId}</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<webApp>
<contextPath>${jetty.contextPath}</contextPath>
<descriptor>${jetty.descriptor}</descriptor>
<jettyEnvXml>${jetty.env}</jettyEnvXml>
<overrideDescriptor>${jetty.overrideDescriptor}</overrideDescriptor>
</webApp>
<contextXml>
${project.basedir}/src/main/webapp/WEB-INF/jetty-context.xml
</contextXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
<repositories>
<repository>
<id>ebi-repo</id>
<name>The EBI internal repository</name>
<url>http://www.ebi.ac.uk/~maven/m2repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${mojarra.version}</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${mojarra.version}</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.1.2.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- Primefaces 5.1 -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<!-- Primefaces Themes -->
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<!-- Biomodels API -->
<dependency>
<groupId>uk.ac.ebi.biomodels</groupId>
<artifactId>biomodels-wslib</artifactId>
<version>1.21</version>
</dependency>
<!-- Ganymed SSH -->
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>262</version>
</dependency>
<!-- Atmosphere -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.2.3</version>
</dependency>
<!-- Logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<!-- slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<!-- GSON -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<!-- Apache commons -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
</project>

Tomcat + CDI + Arquillian

I use Tomcat 7 together with CDI and for that I used the jee6-servlet-minimal-archetype from the Knappsack Maven Archetypes as a starting point.
Now I'd like to use Arquillian for testing the CDI beans, but even after searching for quite some time, I only found a number of problems related to the topic.
Can someone point me to a working setup (especially the right pom.xml to use) using Arquillian for CDI tests on Tomcat 7?
Edited 2012/09/11:
As pointed out in a comment below, I think to get my problem solved, I need someone to help me understanding the whole setup, rather than trying to solve a specific exception at some point.
So, how must the pom.xml and the test class look like, for having a CDI bean in a tomcat 7 and being able to test it with all the injection mechanisms in both an embedded and managed container? (By the way, why is there no remote container adapter for tomcat 7 anymore as it has been for 6?)
I already tried to adapt the tomcat 6 example, but couldn't make it work on tomcat 7.
Unfortunately, I haven't yet found or being told about a working example for my problem, but was able to come up with something that worked for me, which I want to show here - maybe it helps someone, since I assumed that the problem is not an exotic one and maybe someone can look over it and give me a hint in case something should be different.
/pom.xml (usable in eclipse [3.7] with a tomcat 7 [7.0.30], make sure that Project Properties/Deployment Assembly does not contain test classes/resources):
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>cditomcat</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cditomcat</name>
<description>This pom is the base for a project using JSF2+CDI on a tomcat 7 and Arquillian for tests.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Java EE Dependencies -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2-b10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.1.4.Final</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.CR5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.container</groupId>
<artifactId>shrinkwrap-container-tomcat-60</artifactId>
<version>1.0.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-api</artifactId>
<version>1.0.0-cr-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-spi</artifactId>
<version>1.0.0-cr-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-api</artifactId>
<version>1.1.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-impl</artifactId>
<version>1.1.0-beta-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>cditomcat</finalName>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<!-- Facilitates downloading source and javadoc in Eclipse -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<!-- Ensures we are compiling at 1.6 level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Tomcat plugin for embedded tomcat -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>tc7-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/resources/embedded</directory>
</testResource>
</testResources>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>7.0.19</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.19</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>3.7</version>
<scope>test</scope>
</dependency>
<!-- Provided scoped dependencies for embedded container -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<version>1.0.0.CR5</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>tc7-managed</id>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/resources/managed</directory>
</testResource>
</testResources>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-managed-7</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<!-- Provided scoped dependencies for embedded container -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<version>1.0.0.CR5</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
/src/main/webapp/WEB-INF/web.xml (I still used version 2.5):
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>
/src/main/webapp/META-INF/context.xml (injection in Servlets, Listeners, Filters not used):
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- disable storage of sessions across restarts -->
<Manager pathname=""/>
<Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory"/>
</Context>
/src/main/resources/META-INF/beans.xml
/src/test/resources/in-container-beans.xml
(empty marker files are identically for application and test):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
/src/test/resources/in-container-web.xml (same for embedded and managed):
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<env-entry>
<env-entry-name>name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Tomcat</env-entry-value>
</env-entry>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
</web-app>
/src/test/resources/in-container-context.xml (same for embedded and managed):
<Context>
<Resource name="BeanManager" auth="Container"
type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
/src/test/resources/embedded/arquillian.xml (this file is for embedded only):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<engine>
<property name="deploymentExportPath">target</property>
</engine>
<container qualifier="tomcat" default="true">
<configuration>
<property name="tomcatHome">target/tomcat-embedded-7</property>
<property name="workDir">work</property>
<property name="appBase">webapps</property>
<property name="bindHttpPort">8889</property>
<property name="unpackArchive">true</property>
</configuration>
</container>
</arquillian>
/src/test/resources/managed/arquillian.xml (this file is for managed only):
<?xml version="1.0"?>
<arquillian
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat" default="true">
<configuration>
<property name="jmxPort">8099</property>
<property name="host">localhost</property>
<property name="port">8080</property>
<property name="user">tomcat</property>
<property name="pass">manager</property>
</configuration>
</container>
</arquillian>
For managed container deployment to work, tomcat's tomcat-users.xml file has to be extended to enable the manager, e.g.:
...
<role rolename="manager-gui" />
<role rolename="manager-jmx" />
<role rolename="manager-script" />
<user username="tomcat" password="manager"
roles="manager-gui,manager-jmx, manager-script" />
...
Finally, each arquillian test class has to have a deployment method as follows (I used Servlet 2.5):
...
#Deployment
#OverProtocol("Servlet 2.5")
public static WebArchive createDeployment() {
return ShrinkWrap
.create(WebArchive.class, "test.war")
.addClass(MyTest.class)
.addAsLibrary(
MavenArtifactResolver
.resolve("org.jboss.weld.servlet:weld-servlet:1.1.4.Final"))
.addAsWebInfResource("in-container-beans.xml", "beans.xml")
.addAsManifestResource("in-container-context.xml",
"context.xml").setWebXML("in-container-web.xml");
}
...
Weld has to be packaged, which is taken from local maven repository in my case as done in the question's referenced example (edited section) by the following code:
public class MavenArtifactResolver {
private static final String LOCAL_MAVEN_REPO =
System.getProperty("user.home") + File.separatorChar +
".m2" + File.separatorChar + "repository";
public static File resolve(String groupId, String artifactId, String version) {
return new File(LOCAL_MAVEN_REPO + File.separatorChar +
groupId.replace(".", File.separator) + File.separatorChar +
artifactId + File.separatorChar +
version + File.separatorChar +
artifactId + "-" + version + ".jar");
}
public static File resolve(String qualifiedArtifactId) {
String[] segments = qualifiedArtifactId.split(":");
return resolve(segments[0], segments[1], segments[2]);
}
}
Here's a setup that works for the Java EE certified version of Tomcat 7 (TomEE). It includes CDI and there are a handful of working Arquillian adapters:
http://tomee.apache.org/arquillian.html
Note that page mentions using properties to get the right port to use for sending requests to Tomcat. Ignore that. The correct approach is a field like this in your testcase:
#ArquillianResource
private URL url;
That will be the base URL of your webapp, ports and all.
You could take a look at the POM for the Tomcat-7 managed container of Arquillian, which adds the Weld-Servlet as a test dependency.
The Weld JARs are loaded into the Arquillian #Deployment defined in the test classes through the ShrinkWrap Maven Dependency Resolver. You'll also need to include an empty beans.xml file in the deployment. Note - although there is no CDI bean injected into the test class, Weld is used to inject the #Resource.

hibernate3:hbm2ddl goal no jdbc connection

I am trying to create the ddl script for my application which uses hibernate-3.4.0.GA. Here is my pom.xml
<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.apprick.webservice</groupId>
<artifactId>apprickwebapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- Hibernate library dependecy end -->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<drop>true</drop>
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<finalName>webapp</finalName>
</build>
</project>
Since i am using hibernate 3.4.0-GA the whole project is annotation based so there are no persistence.xml in my project. The hibernate.cfg.xml file is like this
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">password</property>
<!-- <property name="hibernate.connection.url">jdbc:mysql://localhost/apprick_db</property> -->
<property name="hibernate.connection.username">rsingh</property>
<property name="hibernate.connection.password">welcome</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<!-- <property name="hbm2ddl.auto">create</property> -->
<mapping class="com.apprick.common.User"></mapping>
<mapping class="com.apprick.common.Customer"></mapping>
<mapping class="com.apprick.common.ApprickAdmin"></mapping>
</session-factory>
</hibernate-configuration>
Now when i run mvn hibernate3:hbm2ddl i get the following exception
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:52)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:252)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
at org.codehaus.mojo.hibernate3.exporter.Hbm2DDLExporterMojo.doExecute(Hbm2DDLExporterMojo.java:112)
at org.codehaus.mojo.hibernate3.HibernateExporterMojo.execute(HibernateExporterMojo.java:152)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Can anyone please suggest me a solution for it. I have been trying to get this done since last two days and its totally driving me crazy.
Thanks for reading the post and i appreciate your inputs.
I hope you figured it out by now. But in case you have not here is a hint:
the part
<componentProperties>
<drop>true</drop>
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
is wrong because you specify the full path
<configurationfile>hibernate.cfg.xml</configurationfile>
is enough, provided the file hibernate.cfg.xml is located in you root Classpath (i.e. WEB-INF/classes)

Resources