Add additional path to exec-maven-plugin

帅比萌擦擦* 提交于 2019-12-05 07:49:39

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

Adrian Shum

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!