How do I decide the dependencies for my maven project? - java

As part of learning, this is my first "spring nature" maven project,
In specific, I would like to understand the approach to know the list of dependencies that are required for any "spring nature" maven project, that I work in future.
For this project, here are the list of 21 dependencies that were just dumped into pom.xml without being told about, which dependency to use when, in this training video at 20:50?
<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.j2eeapp</groupId>
<artifactId>j2eeapplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>J2EE Applications Example</name>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-faces</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.10</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.10</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.02</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version>
</dependency>
</dependencies>
</project>
So,
As of now, I do not have knowledge about bean/spring-webflow/hibernate etc...
What is the approach to know the dependencies required for my "spring nature" project?

Maven projects need dependencies instead of including jar files by build path.when you create a maven project, it requires the library files for the methods you use.you add the dependencies in pom.xml file and when you execute the maven build command the files are automatically downloaded from the internet and included in the project.
You can control the files to download.
you can just add dependencies of the library files you need in your source code.
you decide your dependencies by the methods you use in your source code.
for example.you are using sql database in your project you must need a jar file for the sql driver.
if you have a maven project you just have to add the dependency of the sql in pom.xml

Dependencies list depends on your project nature and usage of .jar relative files.
Simple if you want to use sql in your project then you only need to add sql dependencies in your pom.xml and in the same way if you use junit in your project then you will add junit dependencies in pom.xml in this way after tag
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
no need of extra dependencies that are not being used in project.
Note that in maven dependencies repository you will see some extra dependencies. These are ones which maven used for itself or for other dependencies.

The "Spring nature" is related to how your IDE works with Spring plug-in. In eclipse, a "project nature" creates an association between the a project and a tool, plug-in, or feature set. By adding a nature to an eclipse project, you tell an eclipse plug-in that it is configured to use that project. By adding the "Spring Project Nature" to your project, you are enabling eclipse's spring plugin to work with your project.
Add dependencies on need basis. if you don't need hibernate or web-flow don't add it.Its like adding required toppings to your pizza. If you dont want mushroom, dont add it :)

Related

Spring boot 2.2 activemq jetty conflict

I am trying to upgrade Spring boot to the version 2.2 together with jetty starter.
I get these errors due to jetty version conflict
The following method did not exist:
'org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration org.eclipse.jetty.websocket.server.NativeWebSocketServletContainerInitializer.initialize(org.eclipse.jetty.servlet.ServletContextHandler)'
The method's class, org.eclipse.jetty.websocket.server.NativeWebSocketServletContainerInitializer, is available from the following locations:
jar:file:/some-dir/target/p3.0.166-SNAPSHOT.war!/WEB-INF/lib/jetty-all-9.4.19.v20190610-uber.jar!/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.class
jar:file:/some-dir/target/p3.0.166-SNAPSHOT.war!/WEB-INF/lib/websocket-server-9.4.20.v20190813.jar!/org/eclipse/jetty/websocket/server/NativeWebSocketServletContainerInitializer.class
I have activemq dependency which brings in it's own jetty-all versioned 9.4.19 dependency which is in conflict with spring-boot 2.2 jetty (9.4.20)
And part of my pom.xml is:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--
Jsp-api isn't standard in spring boot
-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>${jsp.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- artefacts enable JSP running in spring-boot -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jstl</artifactId>
</dependency>
<!--
Used to be a single artifact.
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
Newer versions splits the interface and implementation.
This suggests to use a Glassfish implementation.
https://www.andygibson.net/blog/quickbyte/jstl-missing-from-maven-repositories/
The one we used had an Apache implementation, so going with that.
https://stackoverflow.com/a/24444342
-->
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-spec</artifactId>
<version>${taglibs.version}</version>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
<version>${taglibs.version}</version>
</dependency>
<!-- Unit test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<!-- html compressing is used by hrmanager in the JSP -->
<dependency>
<groupId>com.googlecode.htmlcompressor</groupId>
<artifactId>htmlcompressor</artifactId>
<version>1.5.2</version>
</dependency>
<!-- ApacheMQ HTTP jarfile set -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-http</artifactId>
</dependency>
</dependencies>
Any idea how I can fix this?
ActiveMQ is wrong here.
jetty-all is not meant to be used as a dependency in a project.
See https://www.eclipse.org/lists/jetty-users/msg06030.html
It only exists as a command line tool for the documentation to educate folks about basic featureset of Jetty.
It does not, and cannot, contain all of Jetty.
A single artifact with everything that Jetty produces is impossible.
As #Shilan pointed out, excluding jetty-all is the correct solution.
The use of the other appropriate dependencies (by spring-boot-starter-jetty it seems) will already pull in the correct Jetty transitive dependencies that you need.
You can use $ mvn dependency:tree from the command line to see this (before and after excluding jetty-all)
You might want to run one of the duplicate class finder maven plugins to see what other duplicate classes you have going on and correct for those as well.
https://github.com/ning/maven-duplicate-finder-plugin
https://github.com/basepom/duplicate-finder-maven-plugin

Could not initialize com.ibm.mq.MQEnvironment

I've upgraded my maven dependencies for IBM MQ from these(version: 6.0.2.5):
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>${ibm-mq-version}</version>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mqjms</artifactId>
<version>${ibm-mq-version}</version>
</dependency>
<dependency>
<groupId>com.ibm.disthub2</groupId>
<artifactId>dhbcore</artifactId>
<version>DH610-Gold</version>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mqetclient</artifactId>
<version>${ibm-mq-version}</version>
</dependency>
To that(version: 7.5.0.5):
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq-jms-all</artifactId>
<version>${ibm-mq-version}</version>
</dependency>
Now, everytime I try to run my project, I get the following error:
nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.ibm.mq.MQEnvironment
The maven-dependency is imported correctly and is also visible in Eclipse in the maven-dependencies-tab. Also i see the com.ibm.mq.jar in the classpath.
I've googled a lot and the only real solution, which worked for some people was, to add the connector.jar. But I'm already using the jar:
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
<version>${connector-version}</version>
</dependency>
Am I missing something?
IBM MQ from these(version: 6.0.2.5):
To that(version: 7.5.0.5):
IBM moved the MQException to the 'com.ibm.mq.jmqi.jar' file.
As per the the MQ Knowledge Center, you need the following jar files for MQ JMS programming:
com.ibm.mq.commonservices.jar
com.ibm.mq.headers.jar
com.ibm.mq.pcf.jar
com.ibm.mq.jmqi.jar
connector.jar
jms.jar
dhbcore.jar
rmm.jar
jndi.jar
ldap.jar
fscontext.jar
providerutil.jar
CL3Export.jar
CL3Nonexport.jar
Exactly the same problem and this fixed it
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
<version>${connector-version}</version>
</dependency>
These are my dependencies.
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.commonservices</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.headers</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.jmqi</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.jms.Nojndi</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mqjms</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.soap</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.headers</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.pcf</artifactId>
<version>7.0.1.4</version>
</dependency>
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.dhbcore</artifactId>
<version>7.0.1</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>CL3Nonexport</artifactId>
<version>${webspheremq.version}</version>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mqetclient</artifactId>
<version>7.0.1</version>
</dependency>
For Eclipse (Dynamic Web Project (Servlet)) you need copy files:
com.ibm.mq.commomservices.jar
com.ibm.mq.defaultconfig.jar
com.ibm.mq.headers.jar
com.ibm.mq.jar
com.ibm.mq.jmqi.jar
com.ibm.mq.jms.Nojndi.jar
com.ibm.mq.pcf.jar
com.ibm.mqetclient.jar
com.ibm.mqjms.jar
connector.jar
dhbcode.jar
fscontext.jar
jms.jar
to /WebContext/WEB-INF/lib, then add them into Project (Project -> Properties -> Java Build Path -> Add External JARs).
After all, go through these steps:
close project
close Eclipse
open Eclipse
open project.
Good Luck!

Maven doesn't install everything from the pom file resulting in "Missing Required Library" x 124

My pom.xml looks as follows:
<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>
<parent>
<groupId>be.ugent.sop.p404</groupId>
<artifactId>P404</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>P404EJB</artifactId>
<name>P404EJB</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.40.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.29</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.5.2-M1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-deployment_1.1_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<packaging>ejb</packaging>
As one of the examples of the problems I am receiving:
Description Resource Path Location Type
Project 'P404EJB' is missing required library: '/home/zeesteen/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar' P404EJB Build path Build Path Problem
I assumed that after using the following command:
mvn clean install eclipse:eclipse
Maven was supposed to fetch libraries that are in the pom and not present on my machine yet? (The folders, for example "com" don't exist in the .m2/repository folder)
I have tried multiple solutions myself such as
- Removing the Maven nature, clean installing again, converting to a maven project
- Doing variations on the clean command
- Right clicking on the project and doing Maven > update Project
- Cleaning the project through eclipse
I got 124 Java Build Path Problems like the one mentioned above.
I found the mistake..
Maven didn't give errors because there was nothing wrong with my maven repo apparently. Eclipse had changed the location of my settings.xml maven file to a "nonexistent" location.. Resulting in all the problems. I manually changed it back and all problems are solved.
In Eclipse I did:
Window > Preferences > Maven > User Settings: Field User Settings was wrong
(eclipse changed it..) put it back to where I first made the settings, applied, cleaned the project and everything was fixed!
Please make sure that you have added Maven Dependencies under Libraries in Java Build Path.
Note : You can check the properties by Right-clicking the project and click Properties. If it is NOT added, you can click Add Library and select Maven Managed dependencies and finish

Exclude Test Classes in dependend Maven JAR

We have an EAR Project which assembles a WAR File and has some JAR Files as dependency. POM.xml of the EAR looks like this:
<dependencies>
<dependency>
<groupId>our.package</groupId>
<artifactId>package-impl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${maven.ear.plugin.version}</version>
<configuration>
<version>5</version>
<generateApplicationXml>false</generateApplicationXml>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>de.project</groupId>
<artifactId>project.war</artifactId>
<bundleDir>/</bundleDir>
<bundleFileName>project.war</bundleFileName>
<contextRoot>project</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
The package-impl, which is included in the EAR as JAR, has some Test Classes in it. Unfortunatly these Test Classes are bundled whith the JAR, when the EAR is assembled. Besides the facet, that Maven should inlucde the test classe, how can I exclude these Test classes in the JAR, when the EAR is assembled?
All Test Classes in package-impl are in src/test/java Source Folder.
Regards
Sven
UPDATE:
When I build the package-impl indepent from tha EAR manually the test classes are not included (as expected).
UPDATE2
Here is the complete package-impl 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>
<artifactId>project-impl</artifactId>
<parent>
<groupId>de.company</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../project</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>${jee6.version}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>${hibernate.jpa-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
<version>${jboss-vfs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf-api.version}</version>
<scope>provided</scope>
</dependency>
<!-- depenencies on third party modules -->
<dependency>
<groupId>org.jboss.solder</groupId>
<artifactId>solder-impl</artifactId>
<version>${jboss.solder.solder-impl.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.seam.persistence</groupId>
<artifactId>seam-persistence</artifactId>
<version>${org.jboss.seam-persistence.version}</version>
<exclusions>
<!-- already provided by jboss as -->
<exclusion>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>${jboss.richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>${jboss.richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${org.reflections.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.0.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>1.1.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
UPDATE3
This ended up to be an eclipse setting. The EAR-Project had a list of folders which contained the test folder.
The problem has to be in the module for the dependent JAR file. A perhaps someone has configured the build to include the test classes in the JAR. If so, you should fix the module (i.e. its POM file) to not do this, rather than trying to deal with it in your EAR module.
In the past I have accidentally put Test classes in src/main/java instead of src/test/java, and this works(compiles, runs) in eclipse but fails my build because JUnit is not in the class path for the build.
May or may not be true in your case but worth checking.

What maven artifacts do I need for spring hibernate and mysql support?

I have a IDEA project using maven2.
I want to use hibernate + mysql, what dependancies do I need?
first of all, I separate the versions from the artifacts:
<properties>
<spring.version>3.0.3.RELEASE</spring.version>
<hibernate.version>3.5.3-Final</hibernate.version>
<mysql.version>5.1.13</mysql.version>
<junit.version>4.7</junit.version>
</properties>
then I reference them like this:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<!-- perhaps using scope = provided, as this will often
be present on the app server -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<!-- or hibernate-entitymanager if you use jpa -->
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
That way you keep the versions all in one place and can easily update them, especially if you reference e.g. multiple spring artifacts.
BTW: these should be the current versions, but you can always look up current versions using MvnRepository.com
Pasting these dependencies into pom.xml after <depdendencies> should work:
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>3.2.3.GA</version>
</dependency>
<!-- Hibernate library dependecy start -->
<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>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!-- Hibernate library dependecy end -->
Shamelessly cloned from http://www.mkyong.com/hibernate/quick-start-maven-hibernate-mysql-example/ (with the addition of jta as recommended by a commenter)
You may want to tweak the version numbers on the dependencies.
IntelliJ IDEA 9 can find Maven dependencies based on class name. If you start using a class which isn't available in the current dependencies you can get IntelliJ to help find it by using Alt-Enter.
I used this to great effect with a Java-base Subversion hook implementation I am building at work. I was able to get SVNKit and Google Guice dependencies into my project fairly easily this way.
MySQL in your case may be trickier since it is more of a runtime dependency when using Hibernate.

Categories