【问题标题】:Add jar (dependency with scope system) in an Ear build在 Ear 构建中添加 jar(与范围系统的依赖关系)
【发布时间】:2011-04-24 05:53:05
【问题描述】:

我与 Maven 合作,我想使用包装 ear 进行构建,我想添加与 scope 系统的依赖关系,还指定 jar 的 systemPath,如下所示:

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

但我没有在我的发电机耳朵里找到罐子!!!

请帮忙。

【问题讨论】:

    标签: maven-2


    【解决方案1】:
    <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>
    <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>
    

    这会创建一个 ear 并将库复制到 ear 中的 lib 文件夹中。

    【讨论】:

    • 是的,但是我想添加一个依赖项并指定 jar 的路径,我发现要指定 jar 的路径,范围应该是系统!!我希望将带有示波器系统的 jar 复制到我生成的耳朵中!
    • 另外,有一种方法可以在构建后使用“ear”包装类型隐藏 jar 的版本,例如,如果我使用带有版本 5 的 junit,我想用命名 junit 并且名称中没有版本!
    【解决方案2】:

    我与 Maven 合作,我想使用打包 ear 进行构建,我想添加一个范围为 system (...) 的依赖项。但是我的发电机耳朵里没找到那个罐子!!!

    是的,这正是您在 (ab) 使用 system 范围依赖项时得到的结果,该依赖项应该根据定义始终可用。我写了很多次关于这个,例如在这个previous answer,我在下面引用:

    我已经写了manymanyreallymany次关于这个 在 SO 和 99% 的情况下, system 范围依赖项应该是 避免。我会重复 Dependency Scopes 迷你指南说 再来一次:

    • system:在你的某些阶段需要这个依赖 项目的生命周期,但 系统特定的。 使用此范围 不鼓励:这被认为是 “高级”类型的功能,应该 只有当你真正了解时才使用 它使用的所有后果, 如果不是,这可能会非常困难 实际上无法量化。 这个范围根据定义呈现您的 构建非便携式。它可能是 在某些边缘情况下是必要的。这 系统范围包括 &lt;systemPath&gt; 指向的元素 这个的物理位置 对本地机器的依赖。它是 因此用来指代一些神器 预计会出现在给定的 本地机器不在存储库中; 并且其路径可能会有所不同 机器对机器。系统路径 元素可以引用环境 路径中的变量:${JAVA_HOME} 例如。

    所以,不要使用system 范围,或者:

    • 通过install:install-file 将您的库添加到本地存储库。 这是一种快速而肮脏的获取方式 工作正常,这可能是一个选择 如果你一个人,但它会让你的 构建非便携式。
    • 安装并运行“企业存储库”,如 Nexus、Archiva 或 Artifactory 并通过添加您的库 deploy:deploy-file。这是 理想场景。
    • this previous answer 中所述设置基于文件的存储库 并把你的图书馆放在那里。这 是最好的妥协,如果你 没有公司存储库,但 需要作为一个团队工作,不想要 牺牲便携性。

    请停止使用system 范围。

    【讨论】:

    • 好的,我明白了,所以我将使用 install:install-file,我的问题是我有很多依赖项,需要很长时间才能安装,然后在 pom 中添加为依赖项!谢谢。
    猜你喜欢
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2012-06-11
    • 2021-08-18
    • 2012-07-04
    相关资源
    最近更新 更多