依赖于打包为战争的模块,需要这些类

时间:2018-03-26 11:51:14

标签: java maven dependencies war

所以我需要依赖于一个打包为战争的模块,因为它有一些我需要使用的类。但是当我尝试构建它或运行它时它会给我一个错误,因为它无法解析依赖关系而无法找到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>

1 个答案:

答案 0 :(得分:2)

如果要将war用作依赖项,则需要为依赖项指定正确的<dependency> <groupId>se.hrmsoftware.hrm</groupId> <artifactId>sleepy-oyster-restorer</artifactId> <version>${project.version}</version> <type>war</type> </dependency>

while(p!=NULL)

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