如何解决 Maven exec 插件:类路径太长错误?
我有一个大型 Java 项目,其中有大量 jar 文件依赖项。 当我尝试从 Eclipse 或 Netbeans 运行项目(使用 exec)时,Maven 抛出异常,结果是类路径上的条目数量过多(仅包含所需条目的 2/3)。 有谁知道这个问题的解决方法? (除了构建可执行 jar 并从终端运行它。)是否可以“扩展”“类路径缓冲区”大小?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个 Maven exec 插件错误,记录在 MEXEC-68 中,记者创建了一个补丁,所以我希望它能尽快得到解决。
一种解决方法是使用 maven-jar-plugin 的此配置将类路径添加到清单文件中,将依赖项添加到文件夹中,然后仅将该文件夹添加到 CLASSPATH envvar 中。
例如:
这将添加到清单中,如下所示:
如果 JAR 位于 CLASSPATH 文件夹中,则可以使用 maven exec 插件运行 JAR,隐藏类路径,如:
我使用 -Dexec.classpathScope="test" 来制作插件忽略依赖项并仅添加范围测试中的依赖项。
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:
This will add to the manifest something like:
If that JARs are in a CLASSPATH folder, you can run your JAR using maven exec plugin hidding the classpath with something like:
I used -Dexec.classpathScope="test" to make the plugin ignore the dependencies and add just the ones in scope test.
此问题在 Netbeans 6.10M1 中已修复。 请查看错误 188864。 如果您有旧版本,您仍然可以自己修复此问题(您只需编辑 org-netbeans-modules-maven.jar 内的 xml 文件)。
然后,不要忘记检查 Maven 最佳实践 (http://wiki.netbeans.org/MavenBestPractices# Binding_Maven_goals_to_IDE_actions),其中解释了如何将 Maven 目标绑定到 IDE 操作。
问候,
马赫
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
在 Java 6(我希望您使用)中,您可以在类路径条目中使用通配符。 有关确切的语法,请检查此页面设置类路径 并通过搜索“
了解类路径和包名称
”搜索到右侧部分。或者您尝试通过将所有必需的 jar 放在具有短路径的单个文件夹中来缩短路径。 例如
C:\jars\
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\