1

So I was trying to go ahead and create a .ear file for an existing maven project and further deploy it on WebLogic server. For the same, I went ahead to create the WAR,JAR and the EAR module and followed these steps for it -

Right click on parent project, select new, select maven module, Named it as projectnameJARModule and then finished the wizard.

Did the same process for creating a projectnameWARModule and a projectnameEARModule module. Once they were made, I added the WAR and the JAR modules as dependencies to the EAR module.Further, I went ahead to install the maven modules by Right Clicking on the projectnameWARModule folder and chose Run As - Maven Install. Upon this, I get the following error in the console (Full console log below) -


T E S T S
-------------------------------------------------------
Running org.CADJARModule.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ CADJARModule ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] projectname ............................................... SUCCESS [  0.957 s]
[INFO] projectnameJARModule ...................................... FAILURE [ 33.425 s]
[INFO] projectnameWARModule Maven Webapp ......................... SKIPPED
[INFO] projectnameEARModule ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.806 s
[INFO] Finished at: 2015-12-01T18:16:20+05:30
[INFO] Final Memory: 9M/126M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project projectnameJARModule: Error assembling JAR: For artifact {org.glassfish.jersey.containers:jersey-container-servlet-core:null:jar}: The version cannot be empty. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :projectnameJARModule

Any idea how do I get rid of this? Many Thanks

Following is the pom.xml for the Parent Module -

<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>Project_name</groupId>
<artifactId>Project_name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Project_name</name>
<build>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
        <warSourceDirectory>WebContent</warSourceDirectory>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
    </plugin>
    </plugins>
</build>
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-json-provider</artifactId>
                <version>2.6.0</version>
        </dependency>
        <dependency>
                    <groupId>javax</groupId>
                    <artifactId>javaee-web-api</artifactId>
                    <version>7.0</version> <!-- Put here the version of your Java EE app, in my case 7.0 -->
                    <scope>provided</scope>
            </dependency>

          <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                    <version>3.1.0</version>
                    <scope>provided</scope>
            </dependency>

            <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>jstl</artifactId>
                    <version>1.2</version>
            </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
            <!-- artifactId>jersey-container-servlet</artifactId -->
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>
        </dependencies>
    </dependencyManagement>


    <properties>
        <jersey.version>2.16</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <modules>
        <module>Project_nameJARModule</module>
        <module>Project_nameWARModule</module>
        <module>Project_nameEARModule</module>
    </modules>
</project>

Following is the pom.xml for the WAR Module-

    <?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>Projectname</groupId>
    <artifactId>Projectname</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>ProjectnameWARModule</groupId>
<artifactId>ProjectnameWARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ProjectnameWARModule Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <finalName>ProjectnameWARModule</finalName>
</build>
</project>

Following is the pom.xml for my JAR module -

    <?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>Project_Name</groupId>
    <artifactId>Project_Name</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>CADJARModule</groupId>
<artifactId>CADJARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CADJARModule</name>
<url>http://maven.apache.org</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>
</dependencies>
</project>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
TheLuminor
  • 1,411
  • 3
  • 19
  • 34
  • Do you have a dependencyManagement section on your parent or module POM? Is the jersey-container-servlet-core dependency declared in both of them? If yes, which one has a version also declared? – A_Di-Matteo Dec 01 '15 at 13:35
  • try mvn clean install -X and see if it gives you more details about the error. Also share you pom. – StackFlowed Dec 01 '15 at 13:36
  • jersey-container-servlet-core:null:jar in your pom.xml (parent or one of the module) this dependency doesnt have version tag. Add related version tag or define as managed dependency – HRgiger Dec 01 '15 at 13:37
  • @A.DiMatteo eys I do have the section. I have posted the `pom.xml` file please take a look – TheLuminor Dec 01 '15 at 13:52
  • StackFlowed I am using `Eclipse` so I haven't tried that as yet. Will try and post an update. – TheLuminor Dec 01 '15 at 13:53
  • @HRgiger, youre right, it does not have a version tag. What version should I add in the `tag` though`? – TheLuminor Dec 01 '15 at 13:54
  • @HRgiger I tried adding the version tag with version 2.22.1, but I still get the same error? – TheLuminor Dec 01 '15 at 13:58
  • Are you also defining yet another dependenciesManagement section in the jar module? Are you defining the concerned dependency in the dependencies section of the jar module? – A_Di-Matteo Dec 01 '15 at 14:03
  • No I am not defining yet another `dependenciesManagement` in the jar module. I am pasting the `pom.xml` for both, the `jar` and the `war` modules in the question for your reference. – TheLuminor Dec 01 '15 at 14:36
  • So you are not using any dependency of the dependenciesManagement section in your modules. Also note that the JAR module should have a dependency to the JAR module in order to properly include it. Furthermore, is it on purpose that the JAR module has a different parent than the WAR module? As such, the information you posted is not complete. – A_Di-Matteo Dec 01 '15 at 14:44
  • @TheLuminor A.Di Matteo gives a good answer. To pick a version you can consult: http://search.maven.org/#search|gav|1|g%3A%22org.glassfish.jersey.containers%22%20AND%20a%3A%22jersey-container-servlet-core%22 , if you are working as a team I would not choose myself and ask the person who used this module if the version is important – HRgiger Dec 01 '15 at 15:11
  • No, the parent is the same in both the cases. It's just something that I forgot to change before I posted it on the site. Apologies, my bad. :) @A.DiMatteo – TheLuminor Dec 01 '15 at 16:54
  • Can you run a mvn dependency:tree -Dincludes=org.glassfish.jersey.containers from the Jar module and see from where it comes from? Can you also run the normal build using the -e -X flags? You should get some further details then. – A_Di-Matteo Dec 01 '15 at 17:09

1 Answers1

1

Let me clarify: the dependencyManagement section provide dependencies governance to the same POM where it is defined and to children/modules Maven projects. However, declaring a dependency in the dependencyManagement section doesn't mean Maven will use it, it's just an hint in case Maven will use it so that if a certain version is missing in the dependencies section, Maven will look it up in the dependencyManagement section. If none is found then, an error will be generated (Maven couldn't know which version to resolve for a certain dependency).

Hence, good to have the dependencyManagement section for governance, but it should always define versions of each dependency, otherwise it would be a missed opportunity and make your build more error-prone.

If you need all of the declared dependencies and only in the scope of the same declaring POM, then you can actually avoid to have a dependenciesManagement section at all and just have your dependencies section providing versions for each declared dependency.

In this case, you are using a dependenciesManagement section in your parent POM (I see it has modules), you should then check if in the jar module the same dependency is declared (if required), otherwise it will not be used during its build. Moreover, you should also check whether another dependenciesManagement section is declared in the concerned module and re-declaring the same dependency again without version.

Some additional helps can be provided by:

  • Running your Maven build using the -e -X flags
  • Running mvn dependency:tree -Dincludes=<concerned_group_id_here>
  • Last change option, run your build as mvn dependency:purge-local-repository clean install, which can work in case of corrupted cache (error should be different though)
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • the `JAR` module does not have any dependency again. And I don't require one to be there either. Another `DependenciesManagement` section isn't there as well. I am using eclipse and trying to run. Any way I could get the dependency tree output through eclipse? What are my options now? @A. Di Matteo – TheLuminor Dec 02 '15 at 11:30
  • Well I still havent been able to get the issue resolved, but just out of curiosity, once I create the modules successfully and they are installed, how I go ahead with my development process? Where do I add all my `.jsp's` and `javascript's`? In the `.war` module? And then I keep doing a clean install of the `parent project`? Is that how it is to be? – TheLuminor Dec 02 '15 at 13:02