English 中文(简体)
我如何使用Maven实施一个方案?
原标题:How do I execute a program using Maven?

我愿有一个马文目标,促使执行一个 j马类。 Im试图通过Makefile迁移,行文如下:

neotest:
    mvn exec:java -Dexec.mainClass="org.dhappy.test.NeoTraverse"

我愿mvn Newtest ,以制作make Newtest is present.

http://mojo.codehaus.org/exec-maven-plugin/usage.html Maven 任务:网页有任何形式的直截了当。

目前:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.1</version>
  <executions><execution>
    <goals><goal>java</goal></goals>
  </execution></executions>
  <configuration>
    <mainClass>org.dhappy.test.NeoTraverse</mainClass>
  </configuration>
</plugin>

不过,我不知道如何触发从指挥线的原始.。

最佳回答
问题回答

为了执行多个方案,我还需要一个<条码>明细表部分:

<profiles>
  <profile>
    <id>traverse</id>
    <activation>
      <property>
        <name>traverse</name>
      </property>
    </activation>
    <build>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <configuration>
            <executable>java</executable>
            <arguments>
              <argument>-classpath</argument>
              <argument>org.dhappy.test.NeoTraverse</argument>
            </arguments>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>

因此,可以起诉:

mvn exec:exec -Ptraverse

Better use maven-antrun-plugin. It allows to call what you want using more flexible way. If you need to get it (tool and all required dependencies) appeared in class path just add it as plugin dependencies. Such dependencies will not be picked up during final jar building (if you build it). They are added to maven.plugin.classpath for plugin execution only. I remember that we have some troubles with maven-exec plugin. It was able to find only dependencies added as dependencies for whole pom file and didn t want to use plugin s runtime dependencies (something like that). Anyway stop talking let s go through the example below:

<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
    <dependency>
        <groupId>x.y.z.codegen</groupId>
        <artifactId>Generator-Project</artifactId>
        <version>${generator.project.version}</version>
    </dependency>
</dependencies>
<executions>
    <execution>
        <id>Code generation</id>
        <phase>generate-sources</phase>
        <configuration>
            <target>
                <parallel threadsPerProcessor="2">
                    <java classname="x.y.z.codegen.ObjectModelCodeGenerator" fork="true" failonerror="true">
                        <classpath>
                            <path refid="maven.plugin.classpath"/>
                        </classpath>
                        <jvmarg value="-Duser.dir=${generator.root}"/>
                        <arg value="arg1"/>
                        <arg value="arg2"/>
                        <arg value="arg3"/>
                    </java>
                    <java classname="x.y.z.codegen.ObjectModelCodeGenerator" fork="true" failonerror="true">
                        <classpath>
                            <path refid="maven.plugin.classpath"/>
                        </classpath>
                        <jvmarg value="-Duser.dir=${generator.root}"/>
                        <arg value="arg1"/>
                        <arg value="arg2"/>
                        <arg value="arg3"/>
                    </java>
                </parallel>
            </target>
        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
    </execution>
  </executions>

P.s. You can see that I use parallel execution here. It can be done if your tool can be called in parallel. Such possibility exists for maven-antrun-plugin 1.8 but was lot for much recent versions. Means that parallel execution doesn t happen.





相关问题
Derby gets stuck closing?

I ve got unit tests (in maven) that use derby. At the end of the test run, there is a very long pause, with these log messages before the pause. INFO: Closing Hibernate SessionFactory Nov 16, 2009 8:...

Execute goal on parent after children complete

I have a multi-module maven project (several levels of nesting). Normally, when I execute a maven build (like mvn install or whatever), maven will run all the goals for the parent project before ...

Including dependencies in a jar with Maven

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file? I have a project the builds into a single jar file. I want the classes from dependencies to be copied into ...

Java Equivalent of distcc

Distcc makes it easy to distribute a C or C++ compile job across a number of machines, and is a godsend for working with large, frequently-built codebases. An increasing number of our large projects ...

Maven Assembly Problem

I have a maven multiple-module project, which is giving me headaches in the assembly:assembly phase. I have a module which has an assembly defined in it which works fine when I invoke mvn assembly:...

热门标签