Maven'忘了'它在以前的包中生成的类'命令

时间:2016-10-06 17:32:38

标签: java maven jaxb

我完全坚持我认为是基本的东西,但Maven并没有让我在不做清理的情况下两次打包我的项目。

我正在开发一个具有多依赖项的java项目(由不同的人开发的不同模块,通常的东西),其中一个使用使用JAXB生成的java类。 我使用maven来完成所有工作(每个模块一个pom,一个pom父来构建整个项目,我说的基本内容)。

当我使用专用的pom包装模块时,没有任何问题(即使我连续几个包没有清洁)。当我第一次打包整个项目时(或者在干净之后)也没有任何问题(* .java从XSD生成,* .class,执行测试,Jar生成正确)。

但是现在,如果我重新执行package命令,那么maven说它无法找到使用JAXB生成的类(并且由于无法找到的符号,逻辑上存在其他java类中的编译问题)。

我认为Maven有点"忘了"它在以前的包中生成了java类,但我不知道如何记住它。所以,到目前为止,我不得不让它一次又一次地生成那些类并删除它们(而且它很长,因为clean会清理所有其他模块,然后再重新构建......)。

所以,如果有人对我错过/做错了什么有任何线索,我会很高兴因为我的搜索没有成功。

我希望我足够清楚。如果没有,请随时要求进一步解释。

谢谢

P.S。我忘了告诉你我在命令行使用Maven

编辑:

父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>my.package.for.mysoft</groupId>
    <artifactId>mysoft-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.3.0-SNAPSHOT</version>
    <name>Main parent for MySoft modules</name>

<properties>
  <mysoft_version>1.3.0-SNAPSHOT</mysoft_version>
  <main_other_soft_version>1.3.1</main_other_soft_version>

  <!-- SCADAsoft packages -->
  <scadasoft.version>6.2.4.4</scadasoft.version>

  <!-- Hypervisor packages -->
  <othersoft2.version>2.9.0_P03</othersoft2.version>
  <othersoft1.version>1.8.0_P03</othersoft1.version>
  <othersoft3.version>1.2.8</othersoft3.version>
  <hv.quartz-tc.version>2.2.1</hv.quartz-tc.version>

  <!-- TVS packages -->
  <tvs.common.version>3.6.5.0001</tvs.common.version>

  <!-- Loggers -->
  <slf4j.version>1.7.2</slf4j.version>
  <log4j.version>1.2.17</log4j.version>
</properties>

    <modules>
    <module>mysoft-bom</module>
    <module>mysoft-jaxb</module>
    <module>mysoft-common</module>
    <module>My-project-that-uses-jaxb-generated-classes</module>
    </modules>

  <distributionManagement>  
    <snapshotRepository>  
      <id>soft-repo-releases</id>  
      <name>SOFT maven repository - SNAPSHOTS</name>  
      <url>http://url.of.the.server:123/nexus/content/repositories/mysoft_snapshots/</url>  
    </snapshotRepository>  
    <repository>  
      <id>soft-repo-releases</id>  
      <name>Soft maven repository - RELEASES</name>  
      <url>http://url.of.the.server:123/nexus/content/repositories/mysoft_releases/</url>  
    </repository>  
  </distributionManagement>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.terracotta.quartz</groupId>
      <artifactId>quartz-terracotta</artifactId>
      <version>${hv.quartz-tc.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

<build>
  <pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-deploy-plugin</artifactId>
      <version>2.8.2</version>
      <configuration>
        <deployAtEnd>false</deployAtEnd>
        <skip>false</skip>
      </configuration>

    </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>1.4.1</version>
      <executions>
        <execution>
          <id>enforce-parent-version</id>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireProperty>
                <property>project.parent.version</property>
                <regex>1.3.0.SNAPSHOT</regex>
              </requireProperty>
            </rules>
          <fail>true</fail>
          </configuration>
        </execution>
      </executions>
    </plugin>

  </plugins>
  </pluginManagement>
</build>

</project>

生成java类的模块的Pom

<?xml version="1.0" encoding="UTF-8"?>
<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>

  <artifactId>mysoft-jaxb</artifactId>
  <packaging>jar</packaging>

  <parent>
    <groupId>my.package.for.mysoft</groupId>
    <artifactId>mysoft-parent</artifactId>
    <version>1.3.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <name>MySoft generated classes</name>
  <description>Classes generated by JAXB</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <othersoft1.version>1.8.0</othersoft1.version>
    <othersoft2.version>2.9.0</othersoft2.version>
    <othersoft3.version>1.2.8</othersoft3.version>
    <mysoft.data.model>${main_other_soft_version}</mysoft.data.model>
    <mysoft.common>${main_other_soft_version}</mysoft.common>
    <mysoft.core>${main_other_soft_version}</mysoft.core>
    <skipTests>false</skipTests>
  </properties>

  <distributionManagement>  
    <snapshotRepository>  
      <id>soft-repo-releases</id>  
      <name>Soft maven repository - SNAPSHOTS</name>  
      <url>http://url.of.the.server:123/nexus/content/repositories/mysoft_snapshots/</url>  
    </snapshotRepository>  
    <repository>  
      <id>soft-repo-releases</id>  
      <name>Soft maven repository - RELEASES</name>  
      <url>http://url.of.the.server:123/nexus/content/repositories/mysoft_releases/</url>  
    </repository>  
  </distributionManagement>

  <dependencies>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>jsr311-api</artifactId>
      <version>1.1.1</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
  <groupId>org.jvnet.jaxb2_commons</groupId>
  <artifactId>jaxb2-basics</artifactId>
  <version>0.6.5</version>
</dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
          <configuration>
            <environmentVariables>
              <PATH>${java.library.path};${my_api_dir}\Bin;${project.basedir}\..\module-with-cpp\target\nar\lib\x86-Windows-msvc\jni</PATH>
            </environmentVariables>

            <argLine>-Xmx1024m</argLine>
          </configuration>
        </plugin>
        <!-- Maven Compiler plugin: Inherited from Parent -->
        <!-- Maven Jar plugin: Inherited from Parent -->
        <!-- Maven Check Style Plugin: Inherited from Parent -->
        <!-- Maven Assembly Plugin Plugin: Inherited from Parent -->
        <!-- Maven JavaDoc Plugin: Inherited from Parent -->
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
      </plugin>

      <!-- generation of java classes using JAXB -->
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <id>xjc</id>
            <goals>
              <goal>xjc</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <sources>
            <source>${project.build.sourceDirectory}/../resources/xsd/config.xsd</source>
          </sources>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>system_configuration/**</exclude>
            <exclude>mysoft.properties</exclude>
            <exclude>connector_configuration.xml</exclude>
            <exclude>log4j.xml</exclude>
          </excludes>
        </configuration>
      </plugin>

    </plugins>
  </build>
</project>

使用JAXB生成的java类的模块

<?xml version="1.0" encoding="UTF-8"?>
<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>

  <artifactId>My-project-that-uses-jaxb-generated-classes</artifactId>
  <packaging>jar</packaging>

  <parent>
    <groupId>my.package.for.mysoft</groupId>
    <artifactId>mysoft-parent</artifactId>
    <version>1.3.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <name>My project module 1</name>
  <description>Module that uses Jaxb generated classes</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <othersoft1.version>1.8.0</othersoft1.version>
    <othersoft2.version>2.9.0</othersoft2.version>
    <othersoft3.version>1.2.8</othersoft3.version>
    <mysoft.data.model>${main_other_soft_version}</mysoft.data.model>
    <mysoft.common>${main_other_soft_version}</mysoft.common>
    <mysoft.core>${main_other_soft_version}</mysoft.core>
    <skipTests>false</skipTests>
  </properties>

  <distributionManagement>  
    <snapshotRepository>  
      <id>soft-repo-releases</id>  
      <name>Soft maven repository - SNAPSHOTS</name>  
      <url>http://url.of.the.server:123/nexus/content/repositories/mysoft_snapshots/</url>  
    </snapshotRepository>  
    <repository>  
      <id>soft-repo-releases</id>  
      <name>Soft maven repository - RELEASES</name>  
      <url>http://url.of.the.server:123/nexus/content/repositories/mysoft_releases/</url>  
    </repository>  
  </distributionManagement>

  <dependencies>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>jsr311-api</artifactId>
      <version>1.1.1</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>dependency.package.1</groupId>
      <artifactId>connector-sdk-impl</artifactId>
      <version>2.8.0</version>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>

    <!-- datamodels -->     
    <dependency>
      <groupId>dependency.package.1</groupId>
      <artifactId>data-model-1</artifactId>
      <version>3.6.5.0001</version>
    </dependency>

    <dependency>
      <groupId>dependency.package.2</groupId>
      <artifactId>data-model-2</artifactId>
      <version>${scadasoft.version}</version>
    </dependency>

    <!-- 

    ...

    -->
    <dependency>
      <groupId>my.package.for.mysoft</groupId>
      <artifactId>mysoft-common</artifactId>
      <version>${mysoft_version}</version>
    </dependency>

    <dependency>
      <groupId>my.package.for.mysoft</groupId>
      <artifactId>mysoft-jaxb</artifactId>
      <version>${mysoft_version}</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
          <configuration>
            <environmentVariables>
              <PATH>${java.library.path};${my_api_dir}\Bin;${project.basedir}\..\module-with-cpp\target\nar\lib\x86-Windows-msvc\jni</PATH>
            </environmentVariables>
            <argLine>-Xmx1024m</argLine>
          </configuration>
        </plugin>
        <!-- Maven Compiler plugin: Inherited from Parent -->
        <!-- Maven Jar plugin: Inherited from Parent -->
        <!-- Maven Check Style Plugin: Inherited from Parent -->
        <!-- Maven Assembly Plugin Plugin: Inherited from Parent -->
        <!-- Maven JavaDoc Plugin: Inherited from Parent -->
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>system_configuration/**</exclude>
            <exclude>mysoft.properties</exclude>
            <exclude>connector_configuration.xml</exclude>
            <exclude>log4j.xml</exclude>
          </excludes>
        </configuration>
      </plugin>

      <!-- One of the dependencies uses C++ -->
      <plugin>
        <groupId>com.github.maven-nar</groupId>
        <artifactId>nar-maven-plugin</artifactId>
        <extensions>true</extensions>
        <executions>
          <execution>
            <id>nar-download</id>
            <goals>
              <goal>nar-download</goal>
            </goals>
          </execution>
          <execution>
            <id>nar-test-unpack</id>
            <goals>
              <goal>nar-test-unpack</goal>
            </goals>
          </execution>
          <execution>
            <id>nar-integration-test</id>
            <goals>
              <goal>nar-integration-test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>

0 个答案:

没有答案