我想使用maven-dependency-plugin将我的多模块项目的所有子模块中的EAR文件复制到相对于整个项目的根目录的目录.
也就是说,我的布局看起来与此类似,名称已更改:
to-deploy/
my-project/
ear-module-a/
ear-module-b/
more-modules-1/
ear-module-c/
ear-module-d/
more-modules-2/
ear-module-e/
ear-module-f/
...
Run Code Online (Sandbox Code Playgroud)
我希望所有的EAR文件都从它们各自模块的目标目录中复制到my-project/../to-deploy最后
to-deploy/
ear-module-a.ear
ear-module-b.ear
ear-module-c.ear
ear-module-d.ear
ear-module-e.ear
ear-module-f.ear
my-project/
...
Run Code Online (Sandbox Code Playgroud)
我可以在每个耳模块中使用相对路径来完成它,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>ear</type>
<outputDirectory>../../to-deploy</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但我宁愿不在<outputDirectory>元素中指定相对路径.我更喜欢类似的东西${reactor.root.directory}/../to-deploy,但我找不到这样的东西.
此外,我更喜欢有一些方法来继承这个maven-dependency-plugin配置,所以我不必为每个EAR模块指定它.
我还尝试从根pom继承自定义属性:
<properties>
<myproject.root>${basedir}</myproject.root>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是当我试图${myproject.root}在耳模块POM中使用时,${basedir}它将解析为耳模块的基础.
另外,我找到了http://labs.consol.de/lang/de/blog/maven/project-root-path-in-a-maven-multi-module-project/,其中建议每个开发人员,大概是连续的集成服务器应该在profiles.xml文件中配置根目录,但我不认为它是一个解决方案.
那么有一种简单的方法可以找到多模块项目的根目录吗?
我有几个由maven构建的项目,我想在它们之间共享一些常见的属性 - spring版本,mysql驱动程序版本,svn base url等等 - 所以我可以更新它们一次,它将反映在所有项目中.
我想过有一个带有所有属性的超级pom,但如果我改变其中一个问题,我需要增加它的版本(并更新所有poms继承它)或从所有开发人员的机器中删除它我不想这样做.
可以在pom外部指定这些参数吗?我仍然希望在父pom中具有外部位置定义.
在多模块maven项目中,是否有一个指向根项目文件夹的变量?
${project.basedir} 指向当前项目的目录,${project.parent.basedir} 指向父项目的目录, 但是有一个变量总是指向根目录(执行maven命令的目录),无论反应堆内的哪个项目?
我意识到我想要解决的问题几乎无法解决.我想要一个指向project.basedir,project.parent.basedir,project.parent.parent.basedir等的变量,以较高者为准.但是由于项目的父pom不一定是文件系统中的父项,我的整个方法都无济于事.所以我接受Pascal的答案,因为它回答了我的问题(即使我的问题没有解决我的问题).
我正在使用Maven中描述的本地存储库:通过相对路径向jar添加依赖项.
repository-url在最顶层定义pom.xml为
<url>file:${basedir}/../3rdParty/maven-repository</url>
Run Code Online (Sandbox Code Playgroud)
此外,最顶层pom.xml定义了2个模块
<modules>
<module>sub1</module>
<module>sub2</module>
</modules>
Run Code Online (Sandbox Code Playgroud)
问题是,如果一个模块(比如说sub1)定义了一个应该从存储库下载的依赖项,并且maven是从最顶层的目录调用的,那么${basedir}它不会设置到这个目录,而是设置为sub1,导致错误的存储库URL.
所以,说最顶层的项目就pom.xml在
/Development/myproject/pom.xml
Run Code Online (Sandbox Code Playgroud)
存储库在
/Development/3rdParty/maven-repository
Run Code Online (Sandbox Code Playgroud)
然后应将存储库URL设置为
/Development/myproject/../3rdParty/maven-repository
Run Code Online (Sandbox Code Playgroud)
但事实证明它被设定为
/Development/myproject/sub1/../3rdParty/maven-repository
Run Code Online (Sandbox Code Playgroud)
这当然不存在.
知道为什么会这样吗?
我有一个这样的多模块项目:
parent
|
+-- childA
| +-- src/main/resources/application.properties
|
+-- childB
+-- src/main/resources/application.properties
+-- src/main/filters/filter.properties
Run Code Online (Sandbox Code Playgroud)
我application.properties使用filter.propertiesin childB 过滤了childA和childB.
我遵循这个策略将过滤器文件附加到childB的工件,然后将其解压缩到childA的目标上:
childA/target/filters/filter.properties
Run Code Online (Sandbox Code Playgroud)
childA有这样的资源过滤:
<build>
<filters>
<filter>target/filters/filter.properties</filter>
</filters>
</build>
Run Code Online (Sandbox Code Playgroud)
Eclipse正在标记错误childA/pom.xml:
加载属性文件'parent\childA\target\filters\filter.properties'时出错(org.apache.maven.plugins:maven-resources-plugin:3.0.2:copy-resources:default-resources:process-resources)
我构建应用程序时可以使用过滤器文件,因此我并不担心.
如何更新childA的pom.xml以永久忽略此错误?
我有一个名为Parent的项目.它的类型是POM.有一个库(ojdbc6.jar)在公共存储库中不可用,所以我正在访问它<SystemPath>,如下所示pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.Parent</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>childModule</module>
</modules>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
</dependencies>
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
现在子项目名称是Child-Module1,Child-Module2使用this(ojdbc6.jar)库它的POM如下所述:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>testApp</artifactId>
<version>1.14.5.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>APP1</name>
<description>Application</description>
<parent>
<groupId>com.Parent</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
</project>
Run Code Online (Sandbox Code Playgroud)
当我使用Maven构建时,它给了我错误:
Description Resource Path Location Type
The container 'Maven Dependencies' references non existing library
'C:\Users\ABCCOMPUTER_NAME\.m2\repository\com\oracle\ojdbc\6\ojdbc-6.jar'
testApp Build path Problem.
Run Code Online (Sandbox Code Playgroud)
为什么它在本地存储库中查找?仅当父项目包含jar包含系统路径的库()时才会发生.当访问系统路径库(jar)在同一个项目中时,它不会发生,就像父引用一样 …
我正在寻找一种方法来创建只在Maven中激活子配置文件的元配置文件.我们来看一个非常具体的例子.我有以下个人资料:
要构建项目,您必须为服务器选择一个配置文件,为数据库选择一个配置文件.我想创建两个"元配置文件":
第一个想法是通过属性激活子配置文件:
<profile>
<id>database-oracle</id>
<activation>
<property>
<name>prod</name>
</property>
</activation>
</profile>
Run Code Online (Sandbox Code Playgroud)
但是这样,我无法在元配置文件之间共享子配置文件.例如,我希望我的配置文件"database-oracle"由"pre-prod"和"prod"元配置文件激活.
注意:我的子配置文件只包含属性.它们用于过滤资源和子poms.这就是为什么我认为可以解决这种特殊情况的原因.
对我来说理想的情况是将它们外部化在外部属性文件中,但一次只有一个问题;)