假设我有一组n个Java库,每个库都有一个conf和一个资源文件夹,然后我有一个Java项目X,它依赖于这些n个Java库中的一些,我该怎么做才能在构建X时所有依赖的conf和resources文件夹都复制并合并到dist文件夹中。不 - 我不希望它们嵌入罐子里。
显然,会出现重复文件名的问题,但我们假设所有文件都有不同的名称。
编辑:一个额外的相关问题:如何使项目X能够在所有相关项目的开发阶段检测到conf和资源,而无需将它们复制到项目X的文件夹中。例如,我希望Netbeans能够在X的main方法上单击“Run”时找到引用库所使用的这些资源。
Edit2:这是一个项目设置的假设示例:
**Library 1:** Image Processing
conf: Processing configurations, log4j
resources: Training sets, etc.
**Library 2:** Machine Learning
conf: Training parameters, log4j
resources: Dependent C++ batch files (i.e. system calls)
**Library 3:** Reporting Tool
resources: Reporting templates
**Library 4:** Text Mining Toolkit
conf: Encoding, character sets, heuristics
resources: Helper PHP scripts
**Executable Project 1: **
Uses Library 1 to process images
Uses Library 2 to do machine learning on processed images
Uses Library 3 to make reports
**Executable Project 2: **
Uses Library 4 to do text mining
Uses Library 2 to do machine learning on collected textual information
Uses Library 3 to make reports
我们可以假设可执行项目1和2在部署后可以为其组成库使用不同的参数。
答案 0 :(得分:2)
查看可以复制deps并将其复制到特定位置的maven-dependency-plugin。
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
答案 1 :(得分:2)
我在你的例子中看到以下内容。我以图书馆1为例。
图书馆1:图像处理
conf:处理配置,log4j 资源:训练集等
您的库1包含处理配置,这听起来像运行时配置。这意味着它应该是创建的jar的一部分(src / main / resources这些东西的位置)。对于log4j配置也是如此。把它放进jar(项目的src / main / resources。
现在投入资源:训练集。如果您创建一个包含训练集的单独maven项目,那么这将生成一个工件,以后可以用于将其集成到示例1中。如果您有多个训练集,则可以创建不同的工件并将它们用作通常的依赖项或使用maven-dependency-plugin(或者可能是maven-remote-resources-plugin)在你的项目中使用它们。
通过此设置,您可以将Library 1部署到本地存储库中,当然也可以部署到存储库管理器中并将其用作依赖项。
您可以使用相同的方法来处理图书馆2,3等。
可能你可以看一下maven-remote-resource-plugin(我不确定这是否有帮助。)