How to resolve Maven exec plugin: classpath too long error?

风流意气都作罢 提交于 2019-12-10 23:09:36

问题


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?


回答1:


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.

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.

For example:

<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

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"

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




回答2:


This problem is fixed in Netbeans 6.10M1. Please take a look at Bug 188864. If you have an older version, you can still fix this yourself (you just have to edit an xml file inside org-netbeans-modules-maven.jar).

Then, don't forget to check Maven Best Practices (http://wiki.netbeans.org/MavenBestPractices#Binding_Maven_goals_to_IDE_actions) where it is explained how to bind maven goals to IDE actions.

Regards,

Mach




回答3:


In Java 6 (which I hope you use) you can use wildcards in classpath entries. For the exact syntax check this page Setting the classpath and search to the right section by searching for "Understanding the class path and package names".

Or you try shortening the paths by placing all required jars in a single folder with a short path. e.g. C:\jars\



来源:https://stackoverflow.com/questions/1067563/how-to-resolve-maven-exec-plugin-classpath-too-long-error

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