2

I am learning Maven and trying to set up a simple project. I would like this structure:

-myproject
  -myproject-ear
  -myproject-service
    -webservice
  -myproject-ejb

EDIT 1
Solved. New problem in edit 2 below.

EDIT 2
I can compile and deploy my EAR file when I don´t have support for JavaEE. But when I add support for JavaEE I get some errors. The root pom.xml (myproject) is as follows:

 <?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>myproject</groupId>
<artifactId>myproject</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>myproject</name>
<url>http://maven.apache.org</url>

<modules>
    <module>myproject-ejb</module>
    <module>myproject-service</module>
    <module>myproject-ear</module>
</modules>

<repositories>
    <repository>
        <id>jboss</id>
        <url>http://repository.jboss.org/maven2/</url>
    </repository>
</repositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>3.0.2.Final</version>
            <scope>provided</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.2.0.Final</version>
            <scope>provided</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.0.Final</version>
            <scope>provided</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>2.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.0</ejbVersion>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <remoteTagging>true</remoteTagging>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <remoteTagging>true</remoteTagging>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <remoteTagging>true</remoteTagging>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

And the pom.xml for the myproject-ejb looks like this:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>myproject</groupId>
        <artifactId>myproject</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>myproject</groupId>
    <artifactId>myproject-ejb</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>myproject-ejb</name>
    <packaging>ejb</packaging>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.0.Final</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

If I create an interface, like

package org.myproject.ejb.customer;

import javax.ejb.Remote;

@Remote
public interface TestBean {
    public void createSomethingOnDatabase();
}

then the javax.ejb.* package cannot be found and mvn clean install fails. Have I missed something in my pom.xml for myproject-ejb?

EDIT 3
This is what I get if I add the dependency for jboss-javaee-6.0 (including the version) in myproject-ejb:

[ERROR] Failed to execute goal on project myproject-ejb: Could not resolve dependencies for project myproject:myproject-ejb:ejb:1.0-SNAPSHOT: The following artifacts could not be resolved: org.jboss.spec:jboss-javaee-6.0:jar:3.0.2.Final, xalan:xalan:jar:2.7.1.jbossorg-2: Could not find artifact org.jboss.spec:jboss-javaee-6.0:jar:3.0.2.Final in central (http://repo.maven.apache.org/maven2) -> [Help 1]
Rox
  • 2,647
  • 15
  • 50
  • 85

5 Answers5

3

Dependencies are matched against those in dependency management using groupId, artifactId, type and classifier. Default value for type is jar and for classifier it's null.

The dependency in myproject-ejb should therefore be:

<dependency>
  <groupId>org.jboss.spec</groupId>
  <artifactId>jboss-javaee-6.0</artifactId>
  <type>pom</type>
</dependency>

(regarding EDIT 3)

Franta Mejta
  • 309
  • 1
  • 5
  • 10
2

Based on what i can see in the output you didn't defined a dependency on the webservice in your ear module, cause the webservice must be build before the ear module.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks for you answer! I reordered the modules so that the EAR is built after the webservice. Look at my changes above. Any suggestions on what I have done wrong? – Rox Apr 26 '13 at 20:27
  • The reordering is not enough, cause the order will be calculated by the reactor in Maven which will do that based on the dependency tree between the modules. And it looks that your tree is not ok. Can you make a sample project which contains all modules an put that on github etc. to get a better view on the project? Or can you post the full pom files and the exact folder strcuture? – khmarbaise Apr 27 '13 at 11:11
  • Hello again! I updated my previous post with two of the pom´s. Now I can build the project, but if I create a simple java class in `myproject-ejb` and import `java.ejb` package, the package cannot be found. Why? – Rox Apr 29 '13 at 19:57
1

It looks like you are trying to depend on <artifactId>myproject-webservice</artifactId>but your module is myproject-service

Also, should myproject-service be packaged as a jar rather than a war? Typically if a project is used as a dependency by another project, it will be packaged as a jar. See this question for some notes.

Community
  • 1
  • 1
sbridges
  • 24,960
  • 4
  • 64
  • 71
  • Hello! `myproject-service` is the parent of `myproject-service-webservice`. I just succeeded with the compilation but now I cannot make use of `java.ejb` package in my `myproject-ejb` module since the package cannot be found in java code. Look at my previous post for further details. – Rox Apr 29 '13 at 19:59
1

You can add the JavaEE dependency in the myproject-ejb.

    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>3.0.2.Final</version>
    </dependency>

Regarding your third update to the question:

Here is the dependency I use for javax.ejb.Remote :

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

You may use it instead of org.jboss.spec.

Diana Ionita
  • 3,251
  • 3
  • 27
  • 42
  • I tried that but then it says: `The project myproject:myproject-ejb:1.0-SNAPSHOT (/Users/myuser/Documents/myproject/myprojects-ejb/pom.xml) has 1 error 'dependencies.dependency.version' for org.jboss.spec:jboss-javaee-6.0:jar is missing. @ line 25, column 14` – Rox Apr 30 '13 at 14:08
  • Ok then, you can add the version as well. I updated the answer to reflect that. – Diana Ionita Apr 30 '13 at 14:22
  • I don´t know if something in the maven repository is broken. I have also tested to include the version number but that generates another error. Look at my `EDIT 3` in my original post. – Rox Apr 30 '13 at 14:31
  • That made the compilation but the deployment on my JBoss 7.1.1 doesn´t seem to work without the org.jboss.spec javaee-6.0 package. Why use jboss-javaee-6.0 and not javax javaee-api? What´s the difference? – Rox Apr 30 '13 at 15:09
  • Regarding the difference between modules: http://stackoverflow.com/questions/15518148/maven-javaee-api-vs-jboss-javaee-6-0 . But I think Franta may have a better answer for your original problem. – Diana Ionita Apr 30 '13 at 15:15
0

For your EDIT 3 problem: you need to include repository into your parent pom or pom:

<repositories>
    <repository>
        <id>jboss-repo</id>
        <name>jboss-repo</name>
        <url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases</url>
    </repository>
</repositories>

Then force to update your maven dependencies.

mvn clean install -U
Ariel Carrera
  • 5,113
  • 25
  • 36