Cannot add libraries to xtext Project in Eclipse (returns error)

萝らか妹 提交于 2019-12-11 04:13:36

问题


Firstly, I created an xtext project using default values (with the simple Greetings grammar which comes as an example).

I created then a .java file with some code (that can be seen below) and added it to the validation folder.

I have loaded some jars to the build path as I would do in a normal Java Project. If I run my specific java file as a standalone it will load the libraries and run the code. The java file is quite simple:

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!");     
}

However, if a call the "test" function from the .xtend validator file, it will generate this error:

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

When it mentioned "cannot be found by org.xtext.example.mydsl_1.0.0.qualifier" I assumed the problem was in the manifest, but I've tried adding the libraries to the manifest in every way possible but to no avail.


回答1:


if you add libs to the buildpath

  1. copy it to a new lib folder inside the plugin
  2. adapt the manifest and add the jars as entries (runtime tab, classpath section)
  3. add the jars to be included in build.properties (there should be a warning and a quickfix)


来源:https://stackoverflow.com/questions/40731406/cannot-add-libraries-to-xtext-project-in-eclipse-returns-error

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