idea maven 多module工程怎么关联源码而不是关联本地仓库的jar

空无 发布于 2016/09/27 16:33
阅读 4K+
收藏 0

如图所示,新建了一个简单的工程,结构为:

wrap

-main 依赖mod工程

-mod

配置没问题,但在main工程里配置了jetty插件运行就会 报错,找不到mod这个依赖的jar

[ERROR] Failed to execute goal on project main: Could not resolve dependencies for project com.kongwu:main:war:1.0: Failure to find com.kongwu:mod🏺1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]


,怎么 让他依赖于module里的文件呢,而不是依赖本地jar?
加载中
0
szwx855
szwx855

其实没父目录的maven工程是有问题的。这边公司是这样的。

正确的做法是

root

|-web

|-service

|-dao

这些模块中都有pom。然后root中配置好pom后。在各个子系统中加点依赖就行了。

你可以新建project,选maven,然后一路下去。

建设好的工程中,在添加module,选择父节点为root,然后添加好子工程。

最后一个编译就OK了

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] TestMaven
[INFO] dao
[INFO] service
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestMaven ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ TestMaven ---
[INFO] Installing D:\workspace\testMaven\pom.xml to D:\mvn_repo\TestMaven\TestMaven\1.0-SNAPSHOT\TestMaven-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building dao 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dao ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\dao\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dao ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dao ---
[INFO] Building jar: D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\dao\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dao ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dao ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ dao ---
[INFO] Installing D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar to D:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.jar
[INFO] Installing D:\workspace\testMaven\dao\pom.xml to D:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building service 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ service ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\service\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ service ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
[INFO] Building jar: D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\service\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ service ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ service ---
[INFO] Installing D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar to D:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
[INFO] Installing D:\workspace\testMaven\service\pom.xml to D:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] TestMaven .......................................... SUCCESS [  0.709 s]
[INFO] dao ................................................ SUCCESS [  0.949 s]
[INFO] service ............................................ SUCCESS [  0.088 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.848 s
[INFO] Finished at: 2016-09-27T17:35:34+08:00
[INFO] Final Memory: 11M/150M
[INFO] ------------------------------------------------------------------------


Process finished with exit code 0


空无
空无
是我哪里弄错了么,还是 idea就这么设计的
空无
空无
嗯 。我也是这么做的,但是jetty:run之后他就报错找不到依赖module的jar。。应该会找依赖项目的文件才对吧?
0
skhuhu
skhuhu
pom .xml 里面配置啊···依赖这个子模块
空无
空无
我已经配置好了,但运行的时候他还是去本地仓库找mod这个jar,而不找模块的源码
0
szwx855
szwx855


添加项目依赖。(这个只是保证编译时不报错)

另外还要在子POM MOD中,加入一句这个

<parent> <groupId>父GROUPID</groupId> <artifactId>父ARTIFACTID</artifactId> <version>父版本</version> <relativePath>../mod/pom.xml</relativePath> </parent>
把mod移动和wap同级,然后修改mod中的pom代码如上。

工程如下这样:


空无
空无
怎么做到没有父目录,把这个移动到上层目录的。。。还有这一步有什么用呢
0
szwx855
szwx855

引用来自“szwx855”的评论

其实没父目录的maven工程是有问题的。这边公司是这样的。

正确的做法是

root

|-web

|-service

|-dao

这些模块中都有pom。然后root中配置好pom后。在各个子系统中加点依赖就行了。

你可以新建project,选maven,然后一路下去。

建设好的工程中,在添加module,选择父节点为root,然后添加好子工程。

最后一个编译就OK了

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] TestMaven
[INFO] dao
[INFO] service
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TestMaven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestMaven ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ TestMaven ---
[INFO] Installing D:\workspace\testMaven\pom.xml to D:\mvn_repo\TestMaven\TestMaven\1.0-SNAPSHOT\TestMaven-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building dao 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dao ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\dao\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dao ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dao ---
[INFO] Building jar: D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dao ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\dao\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ dao ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dao ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dao ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ dao ---
[INFO] Installing D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar to D:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.jar
[INFO] Installing D:\workspace\testMaven\dao\pom.xml to D:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building service 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ service ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\service\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ service ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
[INFO] Building jar: D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ service ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\testMaven\service\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ service ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ service ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ service ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ service ---
[INFO] Installing D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar to D:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
[INFO] Installing D:\workspace\testMaven\service\pom.xml to D:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] TestMaven .......................................... SUCCESS [  0.709 s]
[INFO] dao ................................................ SUCCESS [  0.949 s]
[INFO] service ............................................ SUCCESS [  0.088 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.848 s
[INFO] Finished at: 2016-09-27T17:35:34+08:00
[INFO] Final Memory: 11M/150M
[INFO] ------------------------------------------------------------------------


Process finished with exit code 0


这个加了么。

<plugin>
					  <groupId>org.mortbay.jetty</groupId>
			          <artifactId>jetty-maven-plugin</artifactId>
			          <executions>
			            <execution>
			              <id>start-jetty</id>
			              <phase>pre-integration-test</phase>
			              <goals>
			                <goal>start</goal>
			              </goals>
			              <configuration>
			                <scanIntervalSeconds>0</scanIntervalSeconds>
			                <daemon>true</daemon>
			                <webAppConfig>
			                  <contextPath>/fabdms</contextPath>
			                  <jettyEnvXml>../${project.parent.artifactId}/Servers/jetty7/jetty-env.xml</jettyEnvXml>
			                  <defaultsDescriptor>false</defaultsDescriptor>
			                </webAppConfig>
			                <loginServices>
			                  <loginService implementation="org.eclipse.jetty.security.HashLoginService">
			                    <name>Suning Application SSO Login</name>
			                    <config>../${project.parent.artifactId}/Servers/jetty7/realm.properties</config>
			                  </loginService>
			                </loginServices>
			                <stopKey>foo</stopKey>
			                <stopPort>9999</stopPort>
			              </configuration>
			            </execution>
			            <execution>
			              <id>stop-jetty</id>
			              <phase>post-integration-test</phase>
			              <goals>
			                <goal>stop</goal>
			              </goals>
			              <configuration>
			                <webAppConfig>
			                  <contextPath>/fabdms</contextPath>
			                  <jettyEnvXml>../${project.parent.artifactId}/Servers/jetty7/jetty-env.xml</jettyEnvXml>
			                </webAppConfig>
			                <loginServices>
			                  <loginService implementation="org.eclipse.jetty.security.HashLoginService">
			                    <name>Suning Application SSO Login</name>
			                    <config>../${project.parent.artifactId}/Servers/jetty7/realm.properties</config>
			                  </loginService>
			                </loginServices>
			                <scanIntervalSeconds>10</scanIntervalSeconds>
			                <stopKey>foo</stopKey>
			                <stopPort>9999</stopPort>
			              </configuration>
			            </execution>
			          </executions>
			          <configuration>
			            <webAppConfig>
			              <contextPath>/fabdms</contextPath>
			              <jettyEnvXml>../${project.parent.artifactId}/Servers/jetty7/jetty-env.xml</jettyEnvXml>
			            </webAppConfig>
			            <loginServices>
			              <loginService implementation="org.eclipse.jetty.security.HashLoginService">
			                <name>Suning Application SSO Login</name>
			                <config>../${project.parent.artifactId}/Servers/jetty7/realm.properties</config>
			              </loginService>
			            </loginServices>
			            <scanIntervalSeconds>10</scanIntervalSeconds>
			            <stopKey>foo</stopKey>
			            <stopPort>9999</stopPort>
			            <connectors>  
	                        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">  
	                            <port>80</port>  
	                            <maxIdleTime>60000</maxIdleTime>  
	                        </connector>  
                    	</connectors>  
			          </configuration>
			        </plugin>



 
szwx855
szwx855
回复 @空无 : jetty是必须打包的。这个木有办法。所以我都用resin或者tomcat.这个jetty,在本地开必debug很蛋疼。
空无
空无
回复 @szwx855 : 我换了几个环境换了电脑都是同样的结果,经测试,直接配置个本地tomcat是可以正常依赖module的,junit/main方法运行也是可以依赖的,但maven jetty/tomcat 插件跑的话就必须先把module打包到本地仓库 ,还是很感谢你!
szwx855
szwx855
回复 @空无 : 一般是加载本地仓库的jar,在idea中看代码跟踪到jar的时候,因为它会自动反编译,所以这个时候,你点下这个class右上上角的 download source,然后在选择chooseSource,就定位到源码了。
空无
空无
都有的,你的可以正常加载代码而不是本地仓库的jar吗?你看本地仓库有没有对应的jar,你删掉在看看
返回顶部
顶部