代码之家  ›  专栏  ›  技术社区  ›  novafluff

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

  •  0
  • novafluff  · 技术社区  · 7 年前

    所以我需要依赖于打包为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>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   SilverNak jach    7 年前

    如果要将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