问题
I have been searching quite a lot for this problem, however I can't really find a proper solution or a how-to manage this one.
I have written a simple DSL for generating some code via Xtext and Xtend. I optionally use the project wizard in the UI project of Xtext to be able to create an individual project for my grammar and plugin. I am able to create the project with ease, however I still need to add some important dependencies into my class path of the clients project. It seems to be a bit more tricky especially if the path of the .jar is not absolute.
This is probably pretty obvious to solve though.
Appreciate any help!! Thank you :)
回答1:
Assuming that you are talking about plain Java projects (no Eclipse Plugin projects or Maven/Gradle projects), you can create a classpath container (similar to the "JRE System Library" container that exists in every Java project).
A working, easily accessible example is the Xtend Library container
The essential steps are:
- You turn your library into an Eclipse plugin, which you make part of your DSL feature
- In your UI plugin, you create an implementation of
IClasspathContainer
that uses the Eclipse plug-in mechanisms to retrieve the location of the JAR file - You create a subclass of
ClasspathContainerInitializer
that creates an instance of yourIClasspathContainer
implementation - You create a small
IClasspathContainerPage
wizard page for users to add your library using the Java Build Path -> Libraries page in the project settings - You register everything in your UI project's plugin.xml using the org.eclipse.jdt.core.classpathContainerInitializer and org.eclipse.jdt.ui.classpathContainerPage extension points
In the Xtend UI, you'll also find some extensions, e.g. a quick fix for adding the libraries (which also handles the case of Eclipse plugin projects as client projects).
来源:https://stackoverflow.com/questions/16295864/xtext-project-add-jar-libraries-with-the-project-wizard-manager-into-the-classp