【问题标题】:Dependency to a module that packages as war, need the classes依赖于打包为war的模块,需要类
【发布时间】:2018-03-26 21:08:08
【问题描述】:

所以我需要依赖于一个打包为战争的模块,因为它有一些我需要使用的类。但是当我尝试构建或运行它时它给了我一个错误,因为它无法解决依赖关系并且找不到 jar。我该如何制作它,以便它可以使用打包为战争的模块。

我已经尝试将它添加到我的 pom.xml 中

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <attachClasses>true</attachClasses>
    </configuration>
</plugin>

还有这样的依赖

<dependency>
    <groupId>se.hrmsoftware.hrm</groupId>
    <artifactId>sleepy-oyster-restorer</artifactId>
    <version>${project.version}</version>
</dependency>

但它仍然不起作用。有人知道吗?

完整的pom

<?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/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>se.hrmsoftware.hrm</groupId>
        <artifactId>sleepy-oyster-projects</artifactId>
        <version>1.2-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>
    <artifactId>sleepy-common-ws</artifactId>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.17</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.17</version>
        </dependency>
        <dependency>
            <groupId>se.hrmsoftware.hrm</groupId>
            <artifactId>sleepy-commons</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>se.hrmsoftware.hrm</groupId>
            <artifactId>sleepy-oyster-restorer</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <jersey.version>2.17</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

【问题讨论】:

  • 请发布你所有的 pom.xml。
  • @AleksandrMukhalov 添加了模块的完整 pom.xml
  • 将 WAR 用作依赖项通常表示误用,因为无法在类路径上使用 WAR。问题是:您是否需要它作为依赖项,因为包含您需要的类或作为依赖项?
  • @khmarbaise 那里有我需要的课程
  • 比答案中给出的东西不起作用..

标签: java maven dependencies war


【解决方案1】:

当你想使用war作为依赖时,需要为依赖指定正确的type

<dependency>
    <groupId>se.hrmsoftware.hrm</groupId>
    <artifactId>sleepy-oyster-restorer</artifactId>
    <version>${project.version}</version>
    <type>war</type>
</dependency>

有关详细信息,请参阅Introduction to the Dependency Mechanism

【讨论】:

    猜你喜欢
    • 2015-08-28
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多