maven编译器:编译工作,mvn编译没有

时间:2012-05-11 10:00:28

标签: maven

我有一个带有maven pom.xml的项目

<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>Minimal-J</groupId>
    <artifactId>Minimal-J</artifactId>
    <version>0.1-SNAPSHOT</version>
    <name>Minimal-J</name>
    <dependencies>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.8.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.8.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin</artifactId>
            <version>6.7.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.miglayout</groupId>
            <artifactId>miglayout</artifactId>
            <version>3.7.4</version>
        </dependency>
        <dependency>
            <groupId>commons-dbutils</groupId>
            <artifactId>commons-dbutils</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20090211</version>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-dev</artifactId>
            <version>2.3.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <packaging>pom</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

如果我执行

  

mvn编译器:编译

我的所有189个java类都已编译

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Minimal-J 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-compiler-plugin:2.4:compile (default-cli) @ Minimal-J ---
[INFO] Compiling 189 source files to C:\projects\open-ech\workspace\minimal-j\MinimalJ\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.386s
[INFO] Finished at: Fri May 11 11:50:54 CEST 2012
[INFO] Final Memory: 13M/37M
[INFO] ------------------------------------------------------------------------

如果我只是输入

  

mvn compile

似乎没有做任何事情:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Minimal-J 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.120s
[INFO] Finished at: Fri May 11 11:53:36 CEST 2012
[INFO] Final Memory: 1M/15M
[INFO] ------------------------------------------------------------------------

在另一个项目中,一切正常。

我可能在哪里配置错误来触发此行为?

1 个答案:

答案 0 :(得分:4)

这是因为pom包装。通过调用mvn compiler:compile,您可以在Maven的默认生命周期之外运行compile目标,并且基本上在src/main/java中编译源代码。通过mvn compile,您可以将生命周期运行到compile阶段,并且每个阶段执行的实际目标都取决于项目的包装类型。 pom - 类型项目在compile阶段没有任何作用,因为 - 实际上 - 没有任何东西可以用POM编译。

我想你的意图是jar打包并改变应该有所帮助。