簡體   English   中英

添加exec-maven-plugin的附加路徑

[英]Add additional path to exec-maven-plugin

我想為exec-maven-plugin添加一個額外的類路徑。
除了%classpath,我想添加一個額外的路徑到包含資源的目錄(/ Users / kornp / resources)。 目前,我的pom看起來像這樣:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.1.1</version>
  <configuration>
    <executable>java</executable>
    <classpathScope>runtime</classpathScope>
    <arguments>
      <argument>%classpath:/Users/kornp/resources</argument>
      <argument>org.drrabbit.maventest.App</argument>
    </arguments>
  </configuration>
</plugin>

我該如何配置?

我在源文件夾之外的特定目錄中有一些配置文件。 所以我為我的pom.xml文件定義了額外的資源。

我的示例目錄結構是:

+ src
+ conf
  - app.properties
  - log4j.xml
- pom.xml

我的pom.xml:

<build>
  <resources>
    <resource>
      <directory>conf</directory>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
    </resource>
  </resources>

  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.2.1</version>
      <configuration>
        <executable>java</executable>
        <mainClass>com.mycompany.MyMainClass</mainClass>
      </configuration>
    </plugin>
  </plugins>
<build>

現在我們可以執行程序:

mvn clean compile exec:java

您是否嘗試使用commandlineArgs參數(如exec示例中所述 )?

雖然它看起來不那么優雅,但切換到antrun插件應該有效:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>runSomething</id>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <property name="runtime_classpath" refid="maven.runtime.classpath"/>

                    <java classname="org.drrabbit.maventest.App" 
                            fork="true" 
                            failonerror="true" 
                            maxmemory="512m">

                        <classpath>
                            <pathelement path="${project.build.directory}/some/extra/resources" />
                            <pathelement path="${runtime_classpath}" />
                        </classpath>
                    </java>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

但是,正如您的操作建議的那樣,將額外資源放在項目之外的某個地方似乎並不是一個好主意。 您應該考慮將其作為項目的一部分,或者將其作為jar並部署到maven repo,這樣您就可以將其作為插件依賴項。

好的,

我調整了插件,以便可以完全指定命令行參數(包括%classpath參數)

暫無
暫無

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

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