2

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 :)

  • What do you mean? That Xtext/Xpand dependencies are missing? Or that you want to add custom jars into the classpath? – A.H. May 01 '13 at 09:51
  • 1
    No the dependencies are all fine, but I want to add some extra custom jars into the classpath, so that the client is able to use them – user1676210 May 02 '13 at 03:25

1 Answers1

0

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).

Bernhard Stadler
  • 1,725
  • 14
  • 24