首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加附加路径到exec-maven-plugin

添加附加路径到exec-maven-plugin
EN

Stack Overflow用户
提问于 2010-04-07 04:11:55
回答 4查看 13.2K关注 0票数 6

我想在exec-maven-plugin中添加一个额外的类路径。

除了%classpath之外,我还想为包含资源的目录(/Users/kornp/ resources )添加一个额外的路径。目前,我的pom是这样的:

代码语言:javascript
复制
<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>

我应该如何配置它?

EN

回答 4

Stack Overflow用户

发布于 2012-09-19 20:55:41

我在我的源文件夹之外的特定目录中有一些配置文件。因此,我在pom.xml文件中定义了额外的资源。

我的示例目录结构是:

代码语言:javascript
复制
+ src
+ conf
  - app.properties
  - log4j.xml
- pom.xml

我的pom.xml:

代码语言:javascript
复制
<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>

现在我们可以执行程序了:

代码语言:javascript
复制
mvn clean compile exec:java
票数 5
EN

Stack Overflow用户

发布于 2010-04-07 04:51:12

您是否尝试过使用commandlineArgs参数(如exec example中所述)?

票数 2
EN

Stack Overflow用户

发布于 2011-09-19 11:46:44

虽然它看起来不那么优雅,但切换到antrun插件应该是可行的:

代码语言:javascript
复制
<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,这样您就可以将其作为插件依赖项。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2587935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档