I have a Scala project based on the "a simple scala project (1.2)" archetype that I've imported into Netbeans 6.9.1 as a maven project wtih existing pom. I can successfully run this project from inside Netbeans, but can't figure out how to run it from the command line. I saw a couple similar questions, but wasn't able to apply them to my situation successfully.
When it runs in the IDE, the command that executes is:
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
The closest I've come to a realistic command line version is:
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
The classpath above includes the folder where the built classes for the project are as well as the scala library. Not sure if I'm missing something else there. The result is:
[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.plugin开发者_如何学Gos: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] ------------------------------------------------------------------------
Here is the 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>
I'm finding it pretty hard to believe that running a simple app from the command line can be so complicated, so hopefully someone can show me the path...
Thanks, John
There are two possible ways to run your Maven project. First you can simply use the excec:java
-task like this:
mvn exec:java -Dexec.mainClass=com.acme.Main
This works fine if you do not need any specific arguments passed to the java
command.
You also can use the exec:exec
task but then you must not expand the %classpath
as it is evaluated by Maven:
mvn exec:exec -Dexec.args="-classpath %classpath com.acme.Main" \
-Dexec.executable="java"
If you run your project like this java
must be in your $PATH
of course or you have to supply the full path via exec.executable
.
You can also configure the exec-maven-plugin
in your pom.xml
so that you could leave out the property definitions in your command line.
精彩评论