Add additional path to exec-maven-plugin

牧云@^-^@ 提交于 2019-12-07 02:46:49

问题


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?


回答1:


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



回答2:


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




回答3:


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.




回答4:


Okay,

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



来源:https://stackoverflow.com/questions/2587935/add-additional-path-to-exec-maven-plugin

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