使用maven为应用程序创建目录结构

时间:2014-06-26 18:06:41

标签: maven build

如何告诉maven创建特定的目录结构并将jar文件放在某些位置?

例如,我想将一些jar放在名为plugins的目录中,这些目录在运行时加载。

这可能吗?或者我错过了maven背后的原则?

1 个答案:

答案 0 :(得分:0)

看起来您的jar是您的项目依赖项,因此要复制插件文件夹中的所有依赖项,请使用next:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-alldeps</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/plugins</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>false</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
          <excludeTransitive>false</excludeTransitive>
        </configuration>
      </execution>
    </executions>
  </plugin>

当您的项目使用资源等jar时,请使用maven 资源部分或下一个插件:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
       <executions>
           <execution>
               <id>copy-config-files</id>
               <phase>package</phase>
               <goals>
                   <goal>copy-resources</goal>
               </goals>
               <configuration>
                   <outputDirectory>${project.build.directory}/plugins/</outputDirectory>

                   <resources>
                       <resource>
                        <filtering>false</filtering>
                        <directory>${project.basedir}/jars/</directory>
                        <includes>
                          <include>file1.jar</include>
                          <include>file5.jar</include>
                        </includes>
                       </resource>

                   </resources>
               </configuration>
           </execution>
       </executions>
    </plugin>