How can I add JDT as a Maven dependency?
Asked Answered
G

3

9

I'm trying to create a project that depends on JDT core. I was using the entries in Maven central until I realized they were several years out of date. After poking around a little, I came across https://repo.eclipse.org. I found the repository I needed and added it:

<repository>
    <id>eclipse</id>
    <name>Eclipse Repository</name>
    <url>https://repo.eclipse.org/content/groups/eclipse/</url>
</repository>
...
<dependency>
    <groupId>org.eclipse.jdt</groupId>
    <artifactId>org.eclipse.jdt.core</artifactId>
    <version>3.10.0.v20140316-0146</version>
</dependency>

But then I started getting an error:

The type org.eclipse.core.runtime.IProgressMonitor cannot be resolved. It is indirectly referenced from required .class files

I managed to find the type in one of the Nexus repositories and added it:

<repository>
    <id>eclipse-acceleo</id>
    <name>Eclipse Repository</name>
    <url>https://repo.eclipse.org/content/groups/acceleo/</url>
</repository>
...
<dependency>
    <groupId>org.eclipse.equinox</groupId>
    <artifactId>org.eclipse.equinox.common</artifactId>
    <version>3.6.200.v20130402-1505</version>
</dependency>

Now I'm getting the error

The type org.eclipse.core.runtime.Plugin cannot be resolved. It is indirectly referenced from required .class files

And I cannot find the class in any of the Nexus repositories. org.eclipse.jdt.core.JavaCore is the class referencing org.eclipse.core.runtime.Plugin.

1. Which dependency do I need to add to include org.eclipse.core.runtime.Plugin?
2. Is there a better way to include JDT as a dependency in Maven?

/e1

I found org.eclipse.core.runtime.Plugin with the help of http://grepcode.com. This time, the up-to-date dependency is in Maven Central (and not in Eclipse's Nexus repo):

<dependency>
    <groupId>org.eclipse.core</groupId>
    <artifactId>runtime</artifactId>
    <version>3.9.100-v20131218-1515</version>
</dependency>

Now when I try to run my tests, I get the following exception all over the place:

java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource
    at org.eclipse.jdt.core.dom.ASTParser.<init>(ASTParser.java:177)
    at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java:126)
    .
    .
    .
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.resources.IResource
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 30 more

At this point I'm considering downloading the complete JAR and adding it as a system dependency. Is there any better way to add JDT as a Maven dependency?

Glossotomy answered 21/3, 2014 at 1:28 Comment(3)
What exactly do you need JDT core for? JDT core is an eclipse plugin and expects to be run inside of an OSGi container (eg- Eclipse equinox). So, consuming JDT as a standard maven dependency will not work. If you only need to use the compiler, then it is possible to consume the JDT compiler adapter, which can be run outside of Eclipse. So, what are your goals?Redfaced
@AndrewEisenberg I want to use the ASTParser.Glossotomy
Unfortundately, the ASTParser class is not part of the compiler adapter. The only supported way to use it would be through running JDT inside of the Eclipse platform. So, you'd need to create an eclipse plugin that depends on jdt core.Redfaced
G
6

A temporary work around until a better solution is found (all dependencies in Maven central):

<dependency>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>org.eclipse.jdt.core</artifactId>
    <version>3.9.1.v20130905-0837</version>
</dependency>
<dependency>
    <groupId>org.eclipse.core</groupId>
    <artifactId>runtime</artifactId>
    <version>3.9.100-v20131218-1515</version>
</dependency>
<dependency>
    <groupId>org.eclipse.birt.runtime</groupId>
    <artifactId>org.eclipse.core.resources</artifactId>
    <version>3.8.101.v20130717-0806</version>
</dependency>
Glossotomy answered 21/3, 2014 at 1:28 Comment(0)
C
7

Eclipse JDT is now available on maven central using a new approach to publish the artifacts. For end user like, no work around are needed anymore, the poms are user friendly (simple version numbers, standard maven metadata for dependencies, source artifacts, 3rd party dependencies...).

Just add this to your pom:

<dependency>
  <groupId>org.eclipse.jdt</groupId>
  <artifactId>org.eclipse.jdt.core</artifactId>
  <version>3.12.2</version>
</dependency>

See a complete example here.

Curettage answered 11/1, 2017 at 6:16 Comment(0)
G
6

A temporary work around until a better solution is found (all dependencies in Maven central):

<dependency>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>org.eclipse.jdt.core</artifactId>
    <version>3.9.1.v20130905-0837</version>
</dependency>
<dependency>
    <groupId>org.eclipse.core</groupId>
    <artifactId>runtime</artifactId>
    <version>3.9.100-v20131218-1515</version>
</dependency>
<dependency>
    <groupId>org.eclipse.birt.runtime</groupId>
    <artifactId>org.eclipse.core.resources</artifactId>
    <version>3.8.101.v20130717-0806</version>
</dependency>
Glossotomy answered 21/3, 2014 at 1:28 Comment(0)
S
0

Updated version found in maven repository

  <dependencies>
    <dependency>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>org.eclipse.jdt.core</artifactId>
        <version>3.12.0.v20160516-2131</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.core</groupId>
        <artifactId>runtime</artifactId>
        <version>LATEST</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.core</groupId>
        <artifactId>resources</artifactId>
        <version>LATEST</version>
    </dependency>
</dependencies>
Silvers answered 2/12, 2016 at 21:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.