Xtext Project: Add Jar Libraries with the Project Wizard Manager into the Classpath/Referenced Libaries of the clients Project

眉间皱痕 提交于 2019-12-22 13:59:47

问题


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:

  1. You turn your library into an Eclipse plugin, which you make part of your DSL feature
  2. 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
  3. You create a subclass of ClasspathContainerInitializer that creates an instance of your IClasspathContainer implementation
  4. You create a small IClasspathContainerPage wizard page for users to add your library using the Java Build Path -> Libraries page in the project settings
  5. 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

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