有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

maven管理具有外部资源依赖关系的多个Java模块

假设我有一组n个Java库,每个库都有一个conf和一个resources文件夹,然后我有一个Java项目X,它依赖于这些n个Java库中的一些,我如何使它在构建X时,所有依赖的conf和resources文件夹都被复制并合并到dist文件夹中。不,我不想把它们埋在罐子里

显然,重复的文件名会有问题,但让我们假设所有文件都有不同的名称

编辑:另一个相关问题:如何使ProjectX能够在开发阶段检测所有依赖项目的配置和资源,而无需将它们复制到ProjectX的文件夹中。例如,我希望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在部署后可以为其组成库使用不同的参数


共 (2) 个答案

  1. # 1 楼答案

    看看maven-dependency-plugin,它可以复制DEP并将它们复制到特定位置

    <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>
    
  2. # 2 楼答案

    我在你的例子中看到了以下内容。让我以库1为例

    库1:图像处理

    配置:处理配置,log4j 资源:培训集等

    你有一个库1,它包含处理配置,在我看来,它就像一个运行时配置。这意味着它应该是创建的jar的一部分(src/main/resources是这些东西的位置)。log4j配置也是如此。只需将其放入项目的jar(src/main/resources)中

    现在,我们来看看资源:培训集。如果您创建一个单独的maven项目,其中包含一个训练集,那么这将生成一个工件,并可用于以后将其集成到示例1中。如果您有多个培训集,您可以创建不同的工件,并像往常一样使用它们,或者使用maven dependency插件(或者可能是maven remote resources插件)在您的项目中使用它们

    通过这种设置,您可以将Library 1部署到本地存储库中,当然也可以部署到存储库管理器中,并将其用作依赖项

    您可以使用相同的方法来处理库2、3等

    也许你可以看看maven-remote-resource-plugin(我不确定这是否有用)