2016-02-17 125 views
1

我是一个maven pom配置的新手,并且坚持使用这种情况。我已经搜索了一个答案,并且'stackoverflowed',但我看到的解决方案不适合我。Maven GWT编译器编译两次?

我已经在Eclipse火星以下项目结构:

parent project(folder) 
....pom.xml 
....ear project(folder) 
.......pom.xml 
....rest project(war)(folder) 
........pom.xml 
....front project(war)(folder) 
........pom.xml 

当我执行maven clean install -e wildfly:deploy我得到编了两次客户端(正面)项目。我究竟做错了什么?

其pom.xml的是如下:

<?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> 

<parent> 
    <artifactId>parent</artifactId> 
    <groupId>com</groupId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 

<artifactId>client</artifactId> 
<packaging>war</packaging> 
<name>client</name> 

<properties>   
    <version.com.google.gwt>2.7.0</version.com.google.gwt> 
    <version.org.codehaus.mojo.gwt.maven.plugin>2.7.0</version.org.codehaus.mojo.gwt.maven.plugin> 
</properties> 

<repositories> 
    <repository> 
     <id>redhat-techpreview-all-repository</id> 
     <url>https://maven.repository.redhat.com/techpreview/all/</url> 
     <releases> 
      <enabled>true</enabled> 
     </releases> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
    </repository> 
</repositories> 

<pluginRepositories> 
    <pluginRepository> 
     <id>redhat-techpreview-all-repository</id> 
     <url>https://maven.repository.redhat.com/techpreview/all/</url> 
     <releases> 
      <enabled>true</enabled> 
     </releases> 
     <snapshots> 
      <enabled>false</enabled> 
     </snapshots> 
    </pluginRepository> 
</pluginRepositories> 

<dependencyManagement> 
    <dependencies> 
     <!-- Google Web Toolkit (GWT) --> 
     <dependency> 
      <groupId>com.google.gwt</groupId> 
      <artifactId>gwt-user</artifactId> 
      <version>${version.com.google.gwt}</version> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 

    <!-- GWT --> 
    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-user</artifactId> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-servlet</artifactId> 
     <version>${version.com.google.gwt}</version> 
    </dependency> 

    <dependency> 
     <groupId>com.google.gwt</groupId> 
     <artifactId>gwt-dev</artifactId> 
     <version>${version.com.google.gwt}</version> 
    </dependency> 

    <dependency> 
     <groupId>com.googlecode.mgwt</groupId> 
     <artifactId>mgwt</artifactId> 
     <version>2.0.0</version> 
    </dependency> 

    <dependency> 
     <groupId>com.googlecode.gwtphonegap</groupId> 
     <artifactId>gwtphonegap</artifactId> 
     <version>3.5.0.1</version> 
    </dependency> 

    <dependency> 
     <groupId>com.allen-sauer.gwt.log</groupId> 
     <artifactId>gwt-log</artifactId> 
     <version>3.3.2</version> 
    </dependency> 
</dependencies> 

<build> 
    <!-- Maven will append the version to the finalName (which is the name 
     given to the generated war, and hence the context root) --> 
    <finalName>${project.artifactId}</finalName> 
    <plugins> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>${version.war.plugin}</version> 
      <configuration> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
       <packagingExcludes>**/client/local/**/*.class</packagingExcludes> 
      </configuration> 
     </plugin> 

     <!-- GWT plugin to compile client-side java code to javascript and 
      to run GWT development mode --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>gwt-maven-plugin</artifactId> 
      <version>${version.org.codehaus.mojo.gwt.maven.plugin}</version> 
      <configuration> 
       <inplace>true</inplace> 
       <logLevel>INFO</logLevel> 
       <extraJvmArgs>-Xmx512m</extraJvmArgs> 
       <!-- Configure GWT's development mode (formerly known as hosted 
        mode) to not start the default server (embedded jetty), but to download the 
        HTML host page from the configured runTarget. --> 
       <noServer>true</noServer> 
       <runTarget>http://localhost:8080/client/index.html</runTarget> 
       <!-- <skip>true</skip> --> 
      </configuration> 
      <executions> 
       <execution> 
        <id>gwt-compile</id> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>gwt-clean</id> 
        <phase>clean</phase> 
        <goals> 
         <goal>clean</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

<profiles> 

    <profile> 
     <!-- When built in OpenShift the 'openshift' profile will be used when 
      invoking mvn. --> 
     <!-- Use this profile for any OpenShift specific customization your app 
      will need. --> 
     <!-- By default that is to put the resulting archive into the 'deployments' 
      folder. --> 
     <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> 
     <id>openshift</id> 
     <build> 
      <plugins> 
       <plugin> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>${version.war.plugin}</version> 
        <configuration> 
         <outputDirectory>deployments</outputDirectory> 
         <warName>ROOT</warName> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

和家长的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<name>parent</name> 
<description>Main parent project</description> 

<modelVersion>4.0.0</modelVersion> 
<groupId>com</groupId> 
<artifactId>parent</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>pom</packaging> 

<modules> 
    <module>client</module> 
    <module>projectEar</module> 
    <module>server</module> 
</modules> 

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

    <!-- JBoss dependency versions --> 
    <version.wildfly.maven.plugin>1.1.0.Alpha5</version.wildfly.maven.plugin> 
    <version.jboss.maven.plugin>7.7.Final</version.jboss.maven.plugin> 

    <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. --> 
    <version.jboss.bom>8.2.2.Final</version.jboss.bom> 
    <version.wildfly>9.0.2.Final</version.wildfly> 

    <!-- other plugin versions --> 
    <version.compiler.plugin>3.1</version.compiler.plugin> 
    <version.ear.plugin>2.10.1</version.ear.plugin> 
    <version.ejb.plugin>2.5.1</version.ejb.plugin> 
    <version.surefire.plugin>2.16</version.surefire.plugin> 
    <version.war.plugin>2.6</version.war.plugin> 

    <!-- maven-compiler-plugin --> 
    <maven.compiler.target>1.7</maven.compiler.target> 
    <maven.compiler.source>1.7</maven.compiler.source> 
</properties> 

<dependencyManagement> 
    <dependencies> 
     <!-- REST Services WAR --> 
     <dependency> 
      <groupId>com</groupId> 
      <artifactId>server</artifactId> 
      <version>${project.version}</version> 
      <type>war</type> 
     </dependency> 

     <!-- GWT WAR --> 
     <dependency> 
      <groupId>com</groupId> 
      <artifactId>client</artifactId> 
      <version>${project.version}</version> 
      <type>war</type> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<build> 
    <pluginManagement> 
     <plugins> 
      <!-- The WildFly plugin deploys your ear to a local JBoss 
       AS container --> 
      <!-- Due to Maven's lack of intelligence with EARs we need 
       to configure the wildfly maven plugin to skip deployment for all modules. 
       We then enable it specifically in the ear module. --> 
      <plugin> 
       <groupId>org.wildfly.plugins</groupId> 
       <artifactId>wildfly-maven-plugin</artifactId> 
       <version>${version.wildfly.maven.plugin}</version> 
       <inherited>true</inherited> 
       <configuration> 
        <skip>true</skip> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

最后,耳朵的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<name>pEAR</name> 
<description>ear module</description> 

<modelVersion>4.0.0</modelVersion> 

<parent> 
    <artifactId>parent</artifactId> 
    <groupId>com</groupId> 
    <version>0.0.1-SNAPSHOT</version> 
</parent> 

<artifactId>projectEar</artifactId> 
<packaging>ear</packaging>  

<dependencies> 
    <dependency> 
     <groupId>com</groupId> 
     <artifactId>server</artifactId> 
     <type>war</type> 
    </dependency> 
    <dependency> 
     <groupId>com</groupId> 
     <artifactId>client</artifactId> 
     <type>war</type> 
    </dependency> 
</dependencies> 

<build> 
    <finalName>${project.artifactId}</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>${version.ear.plugin}</version> 
      <configuration> 
       <!-- Tell Maven we are using Java EE 7 --> 
       <version>7</version> 
       <!-- Use Java EE ear libraries as needed. Java EE ear libraries 
        are in easy way to package any libraries needed in the ear, and automatically 
        have any modules (EJB-JARs and WARs) use them --> 
       <defaultLibBundleDir>lib</defaultLibBundleDir> 
       <fileNameMapping>no-version</fileNameMapping> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.wildfly.plugins</groupId> 
      <artifactId>wildfly-maven-plugin</artifactId> 
      <configuration> 
       <filename>${project.artifactId}.ear</filename> 
       <skip>false</skip> 
       <home>C:\Develop\wildfly9</home> 
       <hostname>127.0.0.1</hostname> 
       <port>9990</port> 
       <username>admin</username> 
       <password>password</password> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<profiles> 
    <profile> 
     <!-- When built in OpenShift the 'openshift' profile will be used when invoking mvn. --> 
     <!-- Use this profile for any OpenShift specific customization your app will need. --> 
     <!-- By default that is to put the resulting archive into the 'deployments' folder. --> 
     <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html --> 
     <id>openshift</id> 
     <build> 
      <plugins> 
       <plugin> 
        <artifactId>maven-ear-plugin</artifactId> 
        <version>${version.ear.plugin}</version> 
        <configuration> 
         <outputDirectory>deployments</outputDirectory> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles>  

如果您需要更多信息,请询问。我真的坚持这一点,我敢肯定,这是一个彻底的失败。

+0

感谢高峰期的编辑。现在更清晰哟了解:) – Tirias

+1

你有没有试过在你的前端项目中查看你的gwt-maven-plugin的部分?我可以看到两个节点,一个用于'clean'和一个用于'compile'。这可能是原因 - 尝试取消注释'干净'执行节点,看看它是否仍然编译两次 – subrunner

+0

我会稍后再试。感谢您的建议! – Tirias

回答

1

最后,它通过改变执行的Maven命令解决,我的意思是:

我正在发起行家throught蚀这样的:

mvn clean install -e wildfly:deploy 

而现在,这改变后..

mvn clean -e wildfly:deploy 

根据documentation,此插件中的“部署”阶段调用“包”阶段:

Invokes the execution of the lifecycle phase package prior to executing itself. 

另一种解决方案,使用所述第一行家命令行是:

mvn clean install -e wildfly:deploy-only 

其中避免了 “包” 阶段。更多关于我们的信息

感谢您的回答!