开发者

Add additional path to exec-maven-plugin

I would like to add an additional class path to the exec-maven-plugin.

Besides the %classpath, I would like to add an extra path to a directory containing resources (/Users/kornp/resources). Currently, my pom looks like this:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
 开发者_Python百科 <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>

How should I configure this?


I have some configuration files in a specific directory outside of my source folder. So i defined additonal resources to my pom.xml file.

my sample directory structure is:

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

my 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>

Now we may execute the program:

mvn clean compile exec:java


Did you try using the commandlineArgs parameter (as mentioned in the exec example)?


Though it looks less elegant, but switching to antrun plugin should works:

<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>

However, it doesn't seems a good idea to have the extra resources put in somewhere outside the project, as your op suggested. You should either consider putting that as part of the project, or make it a jar and deploy to maven repo so you can put it as a plugin dependency.


Okay,

I adapted the plugin so that the command line arguments can be fully specified (including the %classpath parameter)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜