How can I add JDT as a Maven dependency?

自闭症网瘾萝莉.ら 提交于 2019-12-23 07:41:05

问题


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?


回答1:


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>



回答2:


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.




回答3:


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>


来源:https://stackoverflow.com/questions/22548545/how-can-i-add-jdt-as-a-maven-dependency

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