tags:

views:

19

answers:

3

I work with Maven and I want to do a build with packaging ear, i want to add a dependency with scope system and also with specifing the systemPath of the jar like follow:

<dependency> 
  <groupId>group1</groupId> 
  <artifactId>group1</artifactId> 
  <version>1</version> 
  <scope>system</scope> 
  <systemPath>D:\Buildear\Jars\file.jar</systemPath> 
</dependency> 

But I don't found the jar in my generater ear!!!

Help please.

A: 
<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"&gt;
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>aaa</artifactId>
    <groupId>aaa</groupId>
    <version>1.0</version>
</parent>

<groupId>aaa</groupId>
<artifactId>aaa</artifactId>
<version></version>

<packaging>ear</packaging>
<name>aaa - Ear</name>
<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>aaa-ejb</artifactId>
        <version>${project.version}</version>
        <type>ejb</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>aaa-webapp</artifactId>
        <version>${project.version}</version>
        <type>war</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>jboss</groupId>
        <artifactId>jboss-common</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jboss</groupId>
        <artifactId>jbosssx</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <finalName>${aaa.name}-${project.version}</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <generateApplicationXml>false</generateApplicationXml>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <ejbModule>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>aaa-ejb</artifactId>
                    </ejbModule>
                    <jarModule>
                        <groupId>xml-apis</groupId>
                        <artifactId>xml-apis</artifactId>
                        <excluded>true</excluded>
                    </jarModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>
<properties>
    <aaa.name>aaa-batch</aaa.name>
</properties>

This creates an ear and copies the libraries into the lib folder in the ear.

virgium03
Yes, but i want to add a dependency and specify the path of the jar and i found that for specifing the path of the jar the scope should be system!! and i want that the jar with the scope system will be copied in my generated ear!
Rayouma
Also please, there is a way to hide the version of the jar after the build with packaging type "ear" for example if i use junit with version 5 i want to get it in my ear with the name junit and without the version in the name!
Rayouma
A: 

I work with Maven and I want to do a build with packaging ear, I want to add a dependency with scope system (...). But I don't found the jar in my generater ear!!!

Yes, that's just what you get when (ab)using a system scoped dependency which is supposed to be always available by definition. I wrote many times about this, for example in this previous answer that I'm quoting below:

I already wrote many, many, really many times about this here on SO and in 99% of the cases, system scoped dependencies should be avoided. And I'll repeat what the Dependency Scopes mini guide says one more time:

  • system: This dependency is required in some phase of your project's lifecycle, but is system-specific. Use of this scope is discouraged: This is considered an "advanced" kind of feature and should only be used when you truly understand all the ramifications of its use, which can be extremely hard if not actually impossible to quantify. This scope by definition renders your build non-portable. It may be necessary in certain edge cases. The system scope includes the <systemPath> element which points to the physical location of this dependency on the local machine. It is thus used to refer to some artifact expected to be present on the given local machine an not in a repository; and whose path may vary machine-to-machine. The systemPath element can refer to environment variables in its path: ${JAVA_HOME} for instance.

So, instead of using the system scope, either:

  • Add your libraries to your local repository via install:install-file. This is a quick and dirty way to get things working, it might be an option if you're alone but it makes your build non portable.
  • Install and run an "enterprise repository" like Nexus, Archiva, or Artifactory and add your libraries via deploy:deploy-file. This is the ideal scenario.
  • Setup a file based repository as described in this previous answer and put your libraries in there. This is the best compromise if you don't have a corporate repository but need to work as a team and don't want to sacrifice portability.

Please, stop using the system scope.

Pascal Thivent
A: 

@Pascal Thivent

Okay i see, so i'll use install:install-file, my problem is that i have many dependencies that will take many time to install and then to add as dependency in the pom!

Thank you.

Rayouma