【问题标题】:Need help with maven example需要有关 Maven 示例的帮助
【发布时间】:2010-02-02 14:00:04
【问题描述】:

我正在尝试尽快学习 maven,因为它是我当前工作场所的必需品。我发现 this 很棒的书,它几乎解释了有关 maven 的一切。

我正在使用 eclipse 进行 java 开发,并安装了 maven eclipse 插件,在我上面提到的书中有示例(可能相关也可能不相关)4.2.1。雅虎!天气 RSS

本示例的目的是通过连接到 yahoo weather rss 服务器并从中获取适当的数据来说明 maven 如何以稍微复杂的方式工作。

我挣扎的是下面的这一行,我设法从cmd执行它(我使用的是win-7)

mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main

当我使用文本编辑器和 cmd 时,首先是编辑文件,其次是使用 maven 执行命令日食。

我如何从 Eclipse 中做到这一点?

这是我尝试运行的图像:

alt text http://postavi.com/hosted/bc0de2440ba2b5017a92672c721dcca1.gif

所以我进入下一个屏幕:

alt text http://postavi.com/hosted/5c79320f64e850879d49823c4a6e2ecb.gif

我运行它并收到此错误:

Version: 1.1.1
Mojo: exec
brought in via: Direct invocation

While building project:
Group-Id: org.sonatype.mavenbook.custom
Artifact-Id: weather
Version: 0.0.1-SNAPSHOT
From file: C:\OPR-CS\weather\pom.xml


Missing parameters include:
executable



[INFO] ------------------------------------------------------------------------
[INFO] For more information, run with the -e flag
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILED
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Feb 02 14:47:04 CET 2010
[INFO] Final Memory: 1M/7M
[INFO] ------------------------------------------------------------------------

我假设我没有像上面错误所说的那样传递适当的参数。

-Dexec.mainClass=org.sonatype.mavenbook.weather.Main 

上面这行。因为我不知道怎么做。这是 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.sonatype.mavenbook.custom</groupId>
    <artifactId>weather</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>weather</name>
    <url>http://maven.apache.org</url>

    <licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>

    <organization>
        <name>ORIGIGI</name>
        <url>http://www.devs.com</url>
    </organization>

    <developers>
        <developer>
            <id>emco</id>
            <name>Myself and I</name>
            <email>devs@devs.com</email>
            <url>http://www.devs.com</url>
            <organization>ORIGIGI</organization>
            <organizationUrl>http://www.devs.com</organizationUrl>
            <roles>
                <role>developer</role>
            </roles>
            <timezone>-6</timezone>
        </developer>

    </developers>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>jaxen</groupId>
            <artifactId>jaxen</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.5</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

谁能帮帮我?谢谢

【问题讨论】:

    标签: java eclipse maven-2 eclipse-plugin maven-plugin


    【解决方案1】:

    您正在调用 exec:exec 而不是 exec:java

    目标部分应该是exec:java,并且在JRE 选项卡和-Dexec.mainClass=... 参数中。

    【讨论】:

    • @Robert Munteanu 我现在收到此错误Invalid mojo or lifecycle phase: org.codehaus.mojo:exec-maven-plugin:1.1.1:exec:java Original error message was: Invalid task 'org.codehaus.mojo:exec-maven-plugin:1.1.1:exec:java': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
    • 现在构建再次失败,但这次我收到此错误Reason: An exception occured while executing the Java class. null
    • @Robert Munteanu,这是否意味着我的/books 代码中某处有错误?
    • 是的,这是错误的.. 本书作者犯了错误.. 将 int 与字符串混淆.. 谢谢..
    • 这是 -Dexec.mainClass= 而不是 -DmainClass .. 提问者至少是对的。
    猜你喜欢
    • 1970-01-01
    • 2015-06-23
    • 2014-12-26
    • 2013-08-12
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多