2012-06-14 148 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"