2012-06-14 149 views
1

我想用maven的参数执行一个jar文件。我想要执行的命令如下所示。我在依赖关系中有perf4j jar文件。 times.log文件在他们的文件系统中。maven执行java命令

java -jar perf4j-0.9.16.jar times.log 

感谢

回答

0

我看着行家Exec插件,但不知道如何以及在何处指定的jar文件名,所以感谢您的答复,但我看着特别是JAR文件中的一点信息。随着一些试验和错误,以下工作。我必须从jar文件中找到要使用的主类。 mvn install运行该文件,并生成以下输出:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>install</phase> 
        <goals> 
         <goal>java</goal> 
        </goals> 
        <configuration> 
         <mainClass>org.perf4j.LogParser</mainClass> 
         <arguments> 
          <argument>InlineLogging.log</argument> 
         </arguments> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

<dependencies> 
    <dependency> 
     <groupId>org.perf4j</groupId> 
     <artifactId>perf4j</artifactId> 
    </dependency> 
</dependencies> 
3

你可能想看看@exec-maven-plugin

+0

我在哪里可以指定JAR文件和-jar选项 – user373201

+0

从你的描述,我怀疑你需要它在单独的VM中运行。因此,您将需要使用exec:exec目标并将“java”指定为可执行文件,将jar文件和其余参数作为参数传递。 exec插件提供的所有参数在这里描述:http://mojo.codehaus.org/exec-maven-plugin/exec-mojo.html – Morfic

0

你到底想干什么?使用jar(这是一个依赖)来监视你的应用程序?

你看过maven exec plugin吗?

<project> 
    ... 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <version>1.2.1</version> 
     <executions> 
      <execution> 
      ... 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <executable>maven</executable> 
      <!-- optional --> 
      <workingDirectory>/tmp</workingDirectory> 
      <arguments> 
      <argument>-X</argument> 
      <argument>myproject:dist</argument> 
      ... 
      </arguments> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    ... 
</project> 
1

第一

mvn clean install 

mvn exec:java -Dexec.mainClass="com.java.App" -Dexec.args="Args"