如何解决Maven exec插件:classpath太长错误?

时间:2021-11-28 17:18:04

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?

我有一个大型Java项目,具有大量的jar文件依赖项。当我尝试从Eclipse或Netbeans运行项目(使用exec)时,Maven抛出一个异常,结果是类路径上的条目数量过多(仅包括所需条目的2/3)。有没有人知道这个的解决方法? (除了构建可执行jar并从终端运行它。)是否可以“扩展”“classpath-buffer”-size?

3 个解决方案

#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.

这是一个Maven exec插件bug,它记录在MEXEC-68中,记者创建了一个补丁,所以我希望它很快就会得到解决。

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.

一种解决方法是使用此配置为maven-jar-plugin将类路径添加到清单文件,将依赖项添加到文件夹并将该文件夹添加到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:

如果JAR位于CLASSPATH文件夹中,则可以使用maven exec插件运行JAR,使用以下内容隐藏类路径:

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.

我使用-Dexec.classpathScope =“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).

Netbeans 6.10M1中修复了此问题。请查看Bug 188864.如果您有旧版本,您仍然可以自行修复(您只需编辑org-netbeans-modules-maven.jar中的xml文件)。

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.

然后,不要忘记检查Maven最佳实践(http://wiki.netbeans.org/MavenBestPractices#Binding_Maven_goals_to_IDE_actions),其中解释了如何将maven目标绑定到IDE操作。

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".

在Java 6中(我希望您使用),您可以在类路径条目中使用通配符。有关确切的语法,请查看此页面设置类路径并通过搜索“了解类路径和包名称”搜索到右侧部分。

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

或者您尝试通过将所有必需的jar放在具有短路径的单个文件夹中来缩短路径。例如C:\罐\

#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.

这是一个Maven exec插件bug,它记录在MEXEC-68中,记者创建了一个补丁,所以我希望它很快就会得到解决。

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.

一种解决方法是使用此配置为maven-jar-plugin将类路径添加到清单文件,将依赖项添加到文件夹并将该文件夹添加到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:

如果JAR位于CLASSPATH文件夹中,则可以使用maven exec插件运行JAR,使用以下内容隐藏类路径:

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.

我使用-Dexec.classpathScope =“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).

Netbeans 6.10M1中修复了此问题。请查看Bug 188864.如果您有旧版本,您仍然可以自行修复(您只需编辑org-netbeans-modules-maven.jar中的xml文件)。

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.

然后,不要忘记检查Maven最佳实践(http://wiki.netbeans.org/MavenBestPractices#Binding_Maven_goals_to_IDE_actions),其中解释了如何将maven目标绑定到IDE操作。

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".

在Java 6中(我希望您使用),您可以在类路径条目中使用通配符。有关确切的语法,请查看此页面设置类路径并通过搜索“了解类路径和包名称”搜索到右侧部分。

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

或者您尝试通过将所有必需的jar放在具有短路径的单个文件夹中来缩短路径。例如C:\罐\