zoukankan      html  css  js  c++  java
  • 在maven项目中如何引入另外一个项目(转)

     

    原文链接:https://blog.csdn.net/jianfpeng241241/article/details/52654352

    1  在Myeclipse中准备两个maven demo. , 在 maven02中引入maven01

    2 maven01 情况

    Factory.java

    1.  
      package learning;
    2.  
       
    3.  
      public class Factory {
    4.  
      public static String createMessage(){
    5.  
      String message = "hello maven1";
    6.  
      return message;
    7.  
      }
    8.  
      }

    pom.xml
    1.  
      <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">
    2.  
      <modelVersion>4.0.0</modelVersion>
    3.  
      <groupId>myCompanyName</groupId>
    4.  
      <artifactId>maven01</artifactId>
    5.  
      <version>0.0.1-SNAPSHOT</version>
    6.  
      <packaging>war</packaging>
    7.  
      <name/>
    8.  
      <description/>
    9.  
      <properties>
    10.  
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    11.  
      </properties>
    12.  
      <dependencies>
    13.  
      <dependency>
    14.  
      <groupId>org.apache.geronimo.ext.openejb</groupId>
    15.  
      <artifactId>javaee-api</artifactId>
    16.  
      <version>5.0.3</version>
    17.  
      </dependency>
    18.  
      <dependency>
    19.  
      <groupId>javax.servlet</groupId>
    20.  
      <artifactId>jstl</artifactId>
    21.  
      <version>1.2</version>
    22.  
      <scope>provided</scope>
    23.  
      </dependency>
    24.  
      <dependency>
    25.  
      <groupId>javax.servlet.jsp</groupId>
    26.  
      <artifactId>jsp-api</artifactId>
    27.  
      <version>2.1</version>
    28.  
      <scope>provided</scope>
    29.  
      </dependency>
    30.  
      </dependencies>
    31.  
      <build>
    32.  
      <plugins>
    33.  
      <plugin>
    34.  
      <artifactId>maven-war-plugin</artifactId>
    35.  
      </plugin>
    36.  
      <plugin>
    37.  
      <artifactId>maven-compiler-plugin</artifactId>
    38.  
      <configuration>
    39.  
      <source>1.5</source>
    40.  
      <target>1.5</target>
    41.  
      </configuration>
    42.  
      </plugin>
    43.  
      </plugins>
    44.  
      </build>
    45.  
      </project>

    3  maven02 demo

    maven02要引入maven01要引入,只要将maven01中pom.xml的groupId,artifactId,version放在maven02的pom.xml,

    关键代码截图

    Test.java做测试,直接调用Factory.createMessage

    1.  
      package learning;
    2.  
       
    3.  
      public class Test {
    4.  
       
    5.  
       
    6.  
      public static void main(String[] args) {
    7.  
      String message = Factory.createMessage();
    8.  
      System.out.println(message);
    9.  
      }
    10.  
       
    11.  
      }

    输出结果如下,说明maven2已经可以调用maven1中的代码.

  • 相关阅读:
    Mysql权限控制
    Linux查看端口
    linus 下redis守护进程启动
    pymongo创建索引
    mongo批量操作存在更新否则插入
    梯度下降推导过程资料整理
    [转]mitmproxy套件使用攻略及定制化开发
    终极利器!利用appium和mitmproxy登录获取cookies
    how-to-pass-a-class-variable-to-a-decorator-inside-class-definition
    python进阶之魔法函数
  • 原文地址:https://www.cnblogs.com/muxi0407/p/11582458.html
Copyright © 2011-2022 走看看