gpt4 book ai didi

java - 无法将库添加到 Eclipse 中的 xtext 项目(返回错误)

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:45 31 4
gpt4 key购买 nike

首先,我使用默认值创建了一个 xtext 项目(以简单的 Greetings 语法为例)。

然后我创建了一个包含一些代码的 .java 文件(如下所示)并将其添加到验证文件夹中。

我已经将一些 jar 加载到构建路径中,就像在普通 Java 项目中一样。如果我将特定的 java 文件作为独立的文件运行,它将加载库并运行代码。 java 文件非常简单:

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.xtext.example.mydsl.myDsl.Greeting;

public static void main(String[] args){
Greeting hey = null;
try {
test(hey);
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
}
}

public static void test(Greeting imp) throws OWLOntologyCreationException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
System.out.println("success!");
}

但是,如果从 .xtend validator 文件调用“test”函数,则会生成此错误:

java.lang.NoClassDefFoundError: org/semanticweb/owlapi/model/OWLOntologyCreationException
at org.xtext.example.mydsl.validation.MyDslValidator.checkGreetingStartsWithCapital(MyDslValidator.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
/* (has some more "at" in the middle) */
Caused by: java.lang.ClassNotFoundException: org.semanticweb.owlapi.model.OWLOntologyCreationException cannot be found by org.xtext.example.mydsl_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 32 more

当它提到“无法通过 org.xtext.example.mydsl_1.0.0.qualifier 找到”时,我认为问题出在 list 中,但我尝试以各种可能的方式将库添加到 list 中,但无济于事。

最佳答案

如果将库添加到构建路径

  1. 将其复制到插件内的新 lib 文件夹
  2. 调整 list 并将 jar 添加为条目(运行时选项卡、类路径部分)
  3. 添加要包含在 build.properties 中的 jar(应该有警告和快速修复)

关于java - 无法将库添加到 Eclipse 中的 xtext 项目(返回错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40731406/

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