当前位置: 首页 > 知识库问答 >
问题:

未找到Maven包,但jar中存在类

邹开畅
2023-03-14

我有一个与package2有依赖关系的package1。

下面是包2的pom.xml

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.company</groupId>
    <artifactId>data</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>data</name>

    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>Hoxton.SR4</spring-cloud.version>
        <checkstyle-maven-plugin.version>3.1.1</checkstyle-maven-plugin.version>
        <maven.compiler.release>11</maven.compiler.release>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--    POJO dependencies   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>6.13.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-data-firestore</artifactId>
        </dependency>

        <!--    Others  -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!--    Testing     -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <!--     Check Style      -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${checkstyle-maven-plugin.version}</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <!--     Check Style      -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${checkstyle-maven-plugin.version}</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

    <distributionManagement>
        <repository>
            <id>github</id>
            <name>Package 2</name>
            <url>https://maven.pkg.github.com/company/package2</url>
        </repository>
    </distributionManagement>

</project>

在pom.xml包1中

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.company</groupId>
    <artifactId>api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>api</name>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR4</spring-cloud.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.company</groupId>
            <artifactId>data</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- Google Cloud -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>6.13.0</version>
        </dependency>

        <!--    Lombok  -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>GCLOUD_CONFIG</projectId>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

运行mvn pacakgemvn install后,包2的jar文件存在于~/。m2/存储库和包1能够找到它。但是,在包1中,当我尝试导入时

import com.company.data.A;

没有找到包data,但令人惊讶的是IntelliJ能够在com下找到类。公司数据

例如,IntelliJ发现了com。公司数据A和com。公司数据B,但不是com。公司数据,我很困惑。

共有1个答案

敖淮晨
2023-03-14

找到了解决方案,因为默认情况下spring启动包不能用于依赖项。

 类似资料:
  • 我试图在命令行中使用依赖项运行我的java类。我使用IntelliJ IDEA13从我的项目中构建工件。我有一个名为“main.java”的主类,在构建之后,我得到了一个类似MyTest.jar的jar文件。java的全限定名类似于“test.main” 但是当我试图使用“java mytest.jar”运行它时,它抱怨找不到主类mytest.jar。 ----Main.class --META-

  • org . vertx . Java . platform . platform manager exception:模块io . vertx ~ lang-groovy ~ 2 . 0 . 0-final在org . vertx . Java . platform . impl . defaultplatformmanager . get Module(defaultplatformmanage

  • 由于某种原因,即使目标控制器类已经存在于正确的路径中,也找不到它。 路线 我的控制器路径是App- 这是我的控制器: 我已经尝试了作曲家转储-自动加载。我使用laravel框架8.0,所以我也试图恢复和使用7.24。仍然没有找到目标类。

  • 我有一个结构如下的maven项目: 我希望maven jar插件在构建jar文件时打包到数据库文件夹中。我尝试过包含这里概述的内容:https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html,但它找不到目录“../database”(或../../database或../../../database

  • 问题内容: 我有一些可怕的行为。我有以下Maven配置: 这将创建包含所有类的JAR文件,但我在类路径中有一些资源也应包括在内。如果我将参数放在阶段的前面,那么我的所有资源都会包括在内。如果我使用运行Maven ,则不包含任何资源。我的资源位于(不是通常的目录)下。 问题答案: 目标配置中未正确定义资源的源目录。同样,outputDirectory元素将资源放置在dir中,默认情况下将其打包。试试