Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 808
Kurt Pattyn Avatar asked Apr 06 '10 20:04

Kurt Pattyn


3 Answers

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
like image 176
Fırat KÜÇÜK Avatar answered Oct 07 '22 08:10

Fırat KÜÇÜK


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

like image 44
Pascal Thivent Avatar answered Oct 07 '22 10:10

Pascal Thivent


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.

like image 39
Adrian Shum Avatar answered Oct 07 '22 09:10

Adrian Shum