1

我对 Maven 和 Maven 源插件有疑问,即生成的 zip 文件(和*-sources.jar文件)的结构与原始结构不同。这使得人们很难再次修改我们的源代码。因此,我想获得与原始版本相同的结构。

下面我将简要介绍项目的原始结构,zip文件的结构和文件的结构*-sources.jar。之后我将展示两个 pom.xml 文件,即 parent-pom 和其中一个模块。我所要求的基本上是一种如何将主 pom.xml 添加到 zip 文件并保持模块结构的方法(例如,eimassim->src->main)。当然,我可以添加一个完成任务的 bash 脚本,但是我认为有一个我不知道的通用解决方案。

让我从整体描述开始:我在 Maven 中有一个多模块项目,它具有以下结构:

.
|-- dep.xml
|-- pom.xml
|-- documents
|-- eismassim
|   |-- dep.xml
|   |-- pom.xml
|   `-- src
|       |-- main
|       |   `-- java
|       `-- test
|           `-- java
|-- javaagents
|   |-- dep.xml
|   |-- pom.xml
|   |-- scripts
|   `-- src
|       |-- main
|       |   `-- java
|       `-- test
|           `-- java
|-- massim
|   |-- dep.xml
|   |-- pom.xml
|   |-- scripts
|   `-- src
|       `-- main
|           |-- java
|           `-- resources
|-- webapp
|   |-- pom.xml
|   |-- scripts
|   |-- src
|   |   `-- main
|   |       |-- java
|   |       |-- resources
|   |       `-- webapp

生成的 zip 文件massim-2013-1.0-bin.zip具有以下结构:

.
|-- massim-2013-1.0
|   |-- CHANGELOG
|   |-- documents
|   |-- eismassim
|   |   `-- target
|   |       |-- dependency
|   |       |   |-- eis-0.3.jar
|   |       |   `-- junit-4.8.2.jar
|   |       |-- eismassim-2.1.jar
|   |       |-- eismassim-2.1-javadoc.jar
|   |       `-- eismassim-2.1-sources.jar
|   |-- javaagents
|   |   |-- scripts
|   |   `-- target
|   |       |-- dependency
|   |       |   |-- apltk-0.1.jar
|   |       |   |-- eis-0.3.jar
|   |       |   |-- eismassim-2.1.jar
|   |       |   `-- junit-4.8.2.jar
|   |       |-- javaagents-2.1.jar
|   |       |-- javaagents-2.1-javadoc.jar
|   |       `-- javaagents-2.1-sources.jar
|   |-- massim
|   |   |-- scripts
|   |   `-- target
|   |       |-- agentcontest-2013-1.0.jar
|   |       |-- agentcontest-2013-1.0-javadoc.jar
|   |       |-- agentcontest-2013-1.0-sources.jar
|   |       `-- dependency
|   |           |-- appframework-1.03.jar
|   `-- webapp
|       |-- scripts
|       |-- target
|       |   |-- massim-javadoc.jar
|       |   |-- massim-sources.jar
|       |   `-- massim.war

三、结构eismassim-2.1-sources.jar

.
|-- massim
|   |-- App.java
|   |-- eis
|   `-- eismassim
|       |-- connection
|       |-- CowboysEntity.java
|       |-- Entity.java
|-- META-INF
|   `-- MANIFEST.MF
`-- pom.xml

解压jar文件后执行mvn package会导致一个空包。所以我必须src->main->java再次为每个模块创建并将文件移动到正确的位置或手动修改 pom.xml。有可能解决这个问题吗?

父 pom 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>massim</groupId>
  <artifactId>massim</artifactId>
  <version>2013-1.0</version>
  <packaging>pom</packaging>

  <name>MAPC Package</name>
  <url>http://multiagentcontest.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <modules>
    <module>massim</module>
    <module>eismassim</module>
    <module>javaagents</module>
    <module>webapp</module>
  </modules>

<build>
   <plugins>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <id>auto-clean</id>
            <phase>initialize</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
     <plugin>
       <artifactId>maven-assembly-plugin</artifactId>
       <executions>
         <execution>
           <goals>
             <goal>attached</goal>
           </goals>
           <phase>package</phase>
         </execution>
       </executions>
       <configuration>
         <descriptor>dep.xml</descriptor>
       </configuration>
     </plugin>
</plugins>
</build>

</project>

对于 eismassim:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>massim</groupId>
  <artifactId>eismassim</artifactId>
  <version>2.1</version>
  <packaging>jar</packaging>

  <name>EISMASSim</name>
  <url>http://multiagentcontest.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>apleis</groupId>
      <artifactId>eis</artifactId>
      <version>0.3</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Main-Class>massim.eismassim.EnvironmentInterface</Main-Class>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.2.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      <configuration>
        <includePom>true</includePom>
      </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>

        <configuration>
          <quiet>true</quiet>
        </configuration>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-ssh-external</artifactId>
         <version>1.0-beta-6</version>
      </extension>
    </extensions>
  </build>

</project>

谢谢您的帮助。

4

0 回答 0