gpt4 book ai didi

java - 使用 maven-dependency-plugin 运行具有 eclipse swt 依赖项的 java jar

转载 作者:行者123 更新时间:2023-12-01 09:27:43 26 4
gpt4 key购买 nike

我正在制作一个 Eclipse 插件,我也想让它在命令行中工作。正常情况下,常见的问题是在命令行中遇到 Eclipse 依赖项:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Layout
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more

现在我知道这个问题有一个 Eclipse FAQ,但是这里有点不同。我使用 Maven 与 maven-dependency-plugin 进行构建,将我需要的其他项目的 jar 添加到此 jar 作为依赖项:

<build>
<plugins>
<plugin>
<!-- Copy non-Eclipse plugins to target/dependency so that may be referenced
for runtime use. -->
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- seems the line below is needed otherwise every second run the
copy-dependencies fails , link to bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=393978 -->
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

我的 list 文件中的依赖项如下所示:

Rsrc-Class-Path: ./ 
lib/jcommon-1.0.23.jar
lib/jfreechart-1.0.19.jar
lib/jfreechart-1.0.19-swt.jar
lib/jfreechart-1.0.19-experimental.jar
lib/swt.jar
target/dependency/my.first.package.jar
target/dependency/my.second.package.jar
Class-Path: .
Rsrc-Main-Class: my.package.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

Bundle-ClassPath: .,
lib/jcommon-1.0.23.jar,
lib/jfreechart-1.0.19-experimental.jar,
lib/jfreechart-1.0.19-swt.jar,
lib/jfreechart-1.0.19.jar,
lib/swt.jar

Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui,
my.first.package;visibility:=reexport,
my.second.package;visibility:=reexport,
ca.odell.glazedlists,
org.eclipse.nebula.widgets.nattable.core,
org.eclipse.core.resources,
org.eclipse.swt

如您所见,我将 swt.jar 添加到项目内的 lib 中,并在那里引用它,以便将所有依赖项包含在我的 jar 中。

当我尝试在命令行运行它时,我仍然收到上述错误,就好像 swt.jar 不存在一样。

我错过了什么?

最佳答案

如果您想让 Eclipse 插件命令行友好,最好的办法是让该插件还定义一个 Eclipse 应用程序,然后您可以从命令行调用该应用程序:https://wiki.eclipse.org/FAQ_How_do_I_create_an_application%3F

关于java - 使用 maven-dependency-plugin 运行具有 eclipse swt 依赖项的 java jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39706557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com