从命令行运行Netbeans Maven Scala应用程序

时间:2010-11-26 07:19:55

标签: maven-2 scala netbeans

我有一个基于“一个简单的scala项目(1.2)”原型的Scala项目,我已经将其导入Netbeans 6.9.1作为现有pom的maven项目。我可以从Netbeans内部成功运行这个项目,但无法弄清楚如何从命令行运行它。我看到了几个类似的问题,但无法成功应用于我的情况。

当它在IDE中运行时,执行的命令是:

mvn -Dexec.classpathScope=runtime -Dexec.args=-classpath %classpath com.sentientswarm.trade_grouper.TradeParseMain /Users/jstanford/Development/test_data/trades/100410.csv -Dexec.executable=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java -Dnetbeans.execution=true process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec

我最接近现实的命令行版本是:

mvn -Dexec.classpathScope=runtime -Dexec.args=-classpath /Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper:/Users/jstanford/Development/scala/lib/scala-library.jar com.sentientswarm.trade_grouper.TradeParseMain /Users/jstanford/Development/test_data/trades/100410.csv -Dexec.executable=java  process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec

上面的类路径包括项目的构建类以及scala库的文件夹。不确定我是否遗漏了其他东西。结果是:

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: '/Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper'.
[WARNING] POM for 'org.apache.maven.plugins:maven-/Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper-plugin:pom:LATEST' is invalid.

Its dependencies (if any) will NOT be available to the current build.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: org.apache.maven.plugins:maven-/Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper-plugin

Reason: POM 'org.apache.maven.plugins:maven-/Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper-plugin' not found in repository: Unable to determine the latest version

  org.apache.maven.plugins:maven-/Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper-plugin:pom:LATEST


 for project org.apache.maven.plugins:maven-/Users/stanford/Development/NetBeansProjects/target/classes/com/sentientswarm/trade_grouper-plugin


[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Nov 25 23:15:14 PST 2010
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------

这是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>com.sentientswarm</groupId>
    <artifactId>trade_grouper</artifactId>
    <version>1.0-SNAPSHOT</version>
    <inceptionYear>2008</inceptionYear>
    <properties>
        <scala.version>2.8.0</scala.version>
    </properties>

    <repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>
        <repository>
            <id>BumNetworksReleaseRepository</id>
            <name>Bum Networks Release Repository</name>
            <url>http://repo.bumnetworks.com/releases/</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.specs</groupId>
            <artifactId>specs</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.novus</groupId>
            <artifactId>casbah_2.8.0</artifactId>
            <version>1.0.8.5</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <args>
                        <arg>-target:jvm-1.5</arg>
                    </args>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <buildcommands>
                        <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
                    </buildcommands>
                    <additionalProjectnatures>
                        <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
                    </additionalProjectnatures>
                    <classpathContainers>
                        <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
                        <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
                    </classpathContainers>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
    <name>TradeGrouper</name>
</project>

我发现很难相信从命令行运行一个简单的应用程序会非常复杂,所以希望有人可以告诉我这条路......

谢谢, 约翰

1 个答案:

答案 0 :(得分:1)

运行Maven项目有两种可能的方法。首先,你可以简单地使用excec:java - 这样的任务:

mvn exec:java -Dexec.mainClass=com.acme.Main

如果您不需要传递给java命令的任何特定参数,则此方法可以正常工作。

您也可以使用exec:exec任务,但不得扩展由Maven评估的%classpath

mvn exec:exec -Dexec.args="-classpath %classpath com.acme.Main" \
  -Dexec.executable="java"

如果你这样运行你的项目java当然必须在$PATH,或者你必须通过exec.executable提供完整路径。

您还可以在pom.xmlconfigure the exec-maven-plugin,以便在命令行中省略属性定义。