簡體   English   中英

如何編寫Maven構建腳本來執行Java

[英]How to write a Maven build script to execute Java

如何在構建期間或構建完成后執行Java程序? 是否有可能直接從pom這樣做?

mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main

編輯

假設我想執行org.eclipse.content.MyClass 我怎么需要編寫代碼?

這會構建項目,但它不會執行我的類:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>org.eclipse.content.MyClass</mainClass>
                </configuration>
            </plugin>

用你的pom配置maven-exec-plugin

<build>
<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <phase>yourPhase</phase>
        ...
        <goals>
          <goal>java</goal>
        </goals>
           <configuration>
             <mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
          </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>

在行<phase>yourPhase</phase>插入maven 階段應該運行此插件。

這個類需要在pom類路徑中可用(作為源或依賴)。 在其他情況下,如果它不應該是項目依賴項,請閱讀本文如何配置exec插件。

嘗試exec maven插件 ......哎呀,我應該仔細閱讀:-(

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM