Spring Tool Suite-引用项目

时间:2018-11-13 13:52:56

标签: java spring maven

我来自C#\ Visual Studio背景,无法解决如何从项目A引用项目B的问题,因此当我执行Maven构建时,它实际上就可以构建。使用Spring Tool Suite:

  1. 在项目A,属性> Java构建路径>项目中,我添加了项目B。
  2. 项目B可以通过Maven打包生成。
  3. 可爱,智能的作品,我很高兴一起编码。
  4. 我将在项目A上进行Maven构建,并获得一大堆[ERROR]: ...package [project B] does not exist.

我知道我需要以某种方式使Maven知道项目B的罐子了……但是我不知道这是如何工作的。我不认为我想强行将jar放入我的本地Maven存储库中(如果这样做,那么当我使用公司的Maven存储库时会发生什么情况?),我真的只想让Maven从项目B的.class文件中拾取文件。建立并以我快乐的方式前进。我想念什么?

编辑:添加poms:

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.firm</groupId>
  <artifactId>projectA</artifactId>
  <packaging>jar</packaging>
  <version>0.0.2-SNAPSHOT</version>
   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                <executable>true</executable>
                </configuration>

            </plugin>
    </plugins>
  </build>
   <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
  <dependencies>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>
</project>

POM 2:

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.firm</groupId>
  <artifactId>projectB</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>

    </plugins>
  </build>
   <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
  <dependencies>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20090211</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
            </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>
</project>

1 个答案:

答案 0 :(得分:0)

通过maven构建项目后,它会自动添加到maven本地存储库,您可以从pom.xml内的任何maven项目中引用它。 请为两个项目附加pom文件。

编辑: 将此依赖项添加到projectA pom.xml文件:

<dependency>
                <groupId>com.firm</groupId>
                <artifactId>projectB</artifactId>
                <version>0.0.1-SNAPSHOT</version>
</dependency>