0

In Eclipse Java, while developing a Java Project, I can easily use these methods to compile external Java files:

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
compiler.run(null, null, null, javaNamesArray);

However, the exact same thing in Eclipse DSL, in an Xtext Project, isn't working because the JavaCompiler object doesn't find the JARs (which are in the classpath) nor the class binaries from my own project. In order to be able to compile, I have to export the classes I need and tell the compiler where they are as well as the JARs.

Why is the compiler behavior so different in an Xtext project? What am I missing?

ps: then, when loading the classes, the problem repeats itself

Edit:

Example

I have this interface in my code:

public static interface CustomSWRLInterface {...}

Then I create an external Java file ("swrl1.java"), which contains the class:

public class swrl1 implements CustomSWRLInterface {...}

I run the Xtext Project as an Eclipse Application which loads the environment where I can code in my DSL. I have then a Validator which tries to compile the external swrl1.java to swrl1.class. However, it gives a lot of errors like this:

C:\Users\Manuel\Documents\EclipseDSLNeon\runtime-DSL1\Test\swrl\swrl1.java:4:
error: package org.mindswap.pellet does not exist import org.mindswap.pellet.ABox;

It doesn't find the JARs associated with these imports nor the internal class where I defined the interface. This problem only happens in the Xtext Project, which leads me to think that, when launching the Eclipse instance, something happens to the classpath or the visibility of loaded classes (but I have no idea how to work around it).

  • can you elaborate what you are exactly doing. e.g provide an example? – Christian Dietrich Mar 17 '17 at 17:16
  • I have included a minimal example. The problem occurs even with the simplest case scenario. I know it has to do with the Xtext Project and the way the instance is launched but I have no clue how to solve it. – Manuel Luís Mar 17 '17 at 18:58
  • But where is the jar.. Did you verify this works with a normal eclipse plugin project or does it work neither – Christian Dietrich Mar 17 '17 at 19:00
  • And of course inside eclipse there are eclipse / Osgi classloading rules – Christian Dietrich Mar 17 '17 at 19:03
  • The JAR is in a folder which I called lib, located in the same folder as the src folder. The JARs were added to the buildpath of the project and to the classpath on the MANIFEST.MF (runtime section). I am a noob about "eclipse / Osgi classloading rules". (ps: everything works fine with an Eclipse Java Project, but that isn't my goal) – Manuel Luís Mar 17 '17 at 19:42
  • can you please share something that allows me to reproduce this problem. – Christian Dietrich Mar 17 '17 at 19:51
  • i believe this is a general osgi problem: http://stackoverflow.com/questions/6457515/using-javacompiler-in-an-osgi-bundle – Christian Dietrich Mar 17 '17 at 20:08
  • That might actually be my problem! How do I use the bundle that was referenced in the answer to the question you mentioned? Should I start by "activateCompiler" ? Where can I get the "ComponentContext" ? (If this doesn't work, I will make a simple project to reproduce the problem. – Manuel Luís Mar 17 '17 at 22:45

0 Answers0