java - Maven GWT编译器编译两次?

标签 java maven gwt

我是 Maven pom 配置的新手,并且被这种情况困扰。我已经通过谷歌搜索和“stackoverflowed”寻找答案,但我看到的解决方案对我不起作用。

我在 Eclipse Mars 中有以下项目结构:

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>  

最后,EAR 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>    

如果您需要更多信息,请询问。我真的被这个问题困扰了,而且我很确定这完全是菜鸟的失败。

最佳答案

最后通过更改执行maven命令解决了,我的意思是:

我通过 Eclipse 启动 Maven,如下所示:

mvn clean install -e wildfly:deploy

现在,改变这个之后..

mvn clean -e wildfly:deploy

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

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

另一个解决方案,使用第一个 Maven 命令行是:

mvn clean install -e wildfly:deploy-only

这避免了“打包”阶段。更多信息 aboy

感谢您的解答!

关于java - Maven GWT编译器编译两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35456256/

相关文章:

java - 如何将 Excel 文件写入可选文件位置?

java - Java 中 PKCS#5 PBKDF1 的算法名称是什么?

java - 下面两组代码有什么区别

java - 在 weblogic 上部署 Ear 时出现 classNotFound 异常

Maven 依赖插件 : copy dependencies : exclude single artifact

java - GWT 如何知道它是否是第一次从后端接收非空 JSON 数据?

java - 由 : com. google.gson.JsonSyntaxException : java. lang.IllegalStateException 引起:预期为 BEGIN_OBJECT,但在第 1 行第 2 列处为 STRING

java - 向 Java 程序添加一个在特定点打开和关闭的消息框

java - Eclipse 中的 Maven 版本

gwt - 如何找到 GWT 项目 session 中使用的客户端浏览器?