java - 需要有关 Maven 示例的帮助

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

我正在尝试尽快学习 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,所以我想学习如何做同样的事情与 eclipse 。

我如何从 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>

谁能帮帮我?谢谢

最佳答案

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

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

关于java - 需要有关 Maven 示例的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2184507/

相关文章:

java - 编码 java Double as asn1 Real {sign, mantissa, base, exponent}

LESS 的 Eclipse 插件 : How to hide errors of CSS frameworks?

eclipse - Maven/Eclipse : The default build path for resources excluded everything

Maven编译器错误

java - Hudson 偶尔会失败 Maven2 构建 - 缺少 webdav

java - Tomcat 被杀死时 Quartz 当前正在执行的作业

Java+MySQL - 添加 "on duplicate key update"

eclipse - 如何使用 EGit 取消 stash 更改?

c - eclipse在c项目中构建错误

java - Android 无法设置 TextView 的颜色