java - 依赖于打包为 war 的模块,需要类

标签 java maven dependencies war

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

我尝试将其添加到我的 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>

最佳答案

当您想使用 war 作为依赖项时,您需要为依赖项指定正确的类型

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

有关更多信息,请参阅Introduction to the Dependency Mechanism .

关于java - 依赖于打包为 war 的模块,需要类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49490801/

相关文章:

java - onActivityResult 返回数据 = null

java - IncationTargetExceptionMessage 是 : It is impossible to create a new session because 'createSession' error

android - Gradle 和 Google Cast 的 transient 依赖

java - Weblogic 8.1.6常见的依赖有哪些

java - 直接从Array中删除元素

java - 背景图片内存泄漏

java - BufferedReader 和 InputStreamReader 是否应该显式关闭?

eclipse - 无法在 Eclipse 中正确链接外部 Java 库

eclipse - 更改 pom.xml 不会更新 Eclipse 中的库

android - 生成签名的APK时如何解决依赖关系