Maven环境下面多项目之间的引用

如图:git

https://github.com/sdl/odata-example  sdl OData例子包含了4个项目,下载到本地后编译。发现只有model项目是能够编译过去了。其余几个暂时编译不过。github

提示:Could not find artifact,tomcat

缘由以下:例如编译examble-datasource就会报以下错误,首先examble-datasource添加了对examble-model的引用,可是examble-model引用须要从maven的本地仓库中寻找。在咱们本地仓库中通常状况不会有刚编译项目的jar包的。正常状况咱们是编译成jar包,只会放在target目录里面了。maven

由于编译过程通常是ui

第一步,maven cleanspa

第二步, 作个目标为:clean tomcat:redeploy的maven build,而后执行maven build。.net

这样target目录就会有对应的jar包了。code

可是即便这样 examble-datasource编译的时候仍是会报错。即使是examble-model的jar已经生成了也没用。由于examble-datasource调用的时候是调用Maven本地仓库里面的examble-model引用。blog

maven本地仓库的目录通常在下面 用户名\.m2\repositoryget

因此 必须把example-model jar包添加到本地仓库。

参考

https://blog.csdn.net/chenbhhh/article/details/80737106?utm_source=blogkpcl5

https://blog.csdn.net/qq_15237993/article/details/72540928

新增一个maven build

其中goals以下:

install:install-file -Dfile=C:\Users\Thinkpad\Downloads\odata-example-master\example-model\target\example-model-1.0-SNAPSHOT.jar -DgroupId=com.sdl -DartifactId=example-model -Dversion=1.0-SNAPSHOT -Dpackaging=jar

其中的含义,若是example-datasource须要添加example-model的引用,则须要在POM文件中添加对model jar的引用

  <dependency>
          <groupId>com.sdl</groupId>
          <artifactId>example-model</artifactId>
          <version>1.0-SNAPSHOT</version>
   </dependency>

那么Maven 安装 JAR 包的命令是:
mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar

 这样把example-model的的jar包添加到本地仓库后,在编译example-datasource发现能够经过了。

 

最后,直接maven build OData-example成功!大功告成。

在IDEA下面好像会简单一些,

能够参考:https://blog.csdn.net/yueloveme/article/details/80104808

相关文章
相关标签/搜索