如何解决Maven exec插件:类路径太长错误? [英] How to resolve Maven exec plugin: classpath too long error?

查看:124
本文介绍了如何解决Maven exec插件:类路径太长错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有大量jar文件依赖项的大型Java项目.当我尝试从Eclipse或Netbeans运行项目(使用exec)时,Maven引发了一个异常,该异常导致类路径上的条目过多(仅包含所需条目的2/3).有谁知道解决方法? (除了构建可执行的jar并从终端运行它.)是否可以扩展""classpath-buffer"大小?

I have a large Java project with a large number of jar file dependencies. When I try to run the project (using exec) from Eclipse or Netbeans, Maven throws an exception which turns out to be a too large number of entries on the classpath (only 2/3 of the needed entries are included). Does anyone know a workaround for this? (Except from building an executable jar and running it from terminal.) Is it possbile to "extend" the "classpath-buffer"-size?

推荐答案

这是一个Maven exec插件错误,已记录在 MEXEC-68 ,记者创建了一个补丁,希望尽快解决.

This is a Maven exec plugin bug, it is documented in MEXEC-68, the reporter created a patch so I hope it will be resolved soon.

一种解决方法是使用maven-jar-plugin的此配置将类路径添加到清单文件,将依赖项添加到文件夹,然后仅将该文件夹添加到CLASSPATH envvar.

One workaround would be to add the classpath to the manifest file using this config for the maven-jar-plugin, add the dependencies to a folder and add just that folder to the CLASSPATH envvar.

例如:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        ...
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
        </configuration>
        ...
      </plugin>
    </plugins>
  </build>
  ...
</project>

这会将类似清单的内容添加到清单中

This will add to the manifest something like:

Class-Path: plexus-utils-1.1.jar commons-lang-2.1.jar

如果该JAR位于CLASSPATH文件夹中,则可以使用maven exec插件运行该JAR,将其隐藏在类路径中,例如:

If that JARs are in a CLASSPATH folder, you can run your JAR using maven exec plugin hidding the classpath with something like:

mvn exec:exec [...] -Dexec.classpathScope="test"

我使用-Dexec.classpathScope ="test"来使插件忽略依赖项,而仅在范围测试中添加依赖项.

I used -Dexec.classpathScope="test" to make the plugin ignore the dependencies and add just the ones in scope test.

这篇关于如何解决Maven exec插件:类路径太长错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆