简体   繁体   English

如何将JDT添加为Maven依赖项?

[英]How can I add JDT as a Maven dependency?

I'm trying to create a project that depends on JDT core . 我正在尝试创建一个依赖于JDT核心的项目。 I was using the entries in Maven central until I realized they were several years out of date . 我正在使用Maven中心的条目,直到我意识到它们已经过时了几年 After poking around a little, I came across https://repo.eclipse.org . 经过一番探索后,我遇到了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. 无法解析org.eclipse.core.runtime.IProgressMonitor类型。 It is indirectly referenced from required .class files 它是从所需的.class文件间接引用的

I managed to find the type in one of the Nexus repositories and added it: 我设法在其中一个Nexus存储库中找到了类型并添加了它:

<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. org.eclipse.core.runtime.Plugin类型无法解析。 It is indirectly referenced from required .class files 它是从所需的.class文件间接引用的

And I cannot find the class in any of the Nexus repositories. 我无法在任何Nexus存储库中找到该类。 org.eclipse.jdt.core.JavaCore is the class referencing org.eclipse.core.runtime.Plugin . org.eclipse.jdt.core.JavaCore是引用org.eclipse.core.runtime.Plugin的类。

1. Which dependency do I need to add to include org.eclipse.core.runtime.Plugin ? 1.我需要添加哪个依赖项才能包含 org.eclipse.core.runtime.Plugin
2. Is there a better way to include JDT as a dependency in Maven? 2.有没有更好的方法将JDT作为Maven中的依赖项包含在内?

/e1 / E1

I found org.eclipse.core.runtime.Plugin with the help of http://grepcode.com . 我在http://grepcode.com的帮助下找到了org.eclipse.core.runtime.Plugin This time, the up-to-date dependency is in Maven Central (and not in Eclipse's Nexus repo): 这一次,最新的依赖在Maven Central中(而不是在Eclipse的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. 此时我正在考虑下载完整的JAR并将其添加为系统依赖项。 Is there any better way to add JDT as a Maven dependency? 有没有更好的方法将JDT添加为Maven依赖项?

A temporary work around until a better solution is found (all dependencies in Maven central): 临时工作直到找到更好的解决方案(Maven中心的所有依赖项):

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

Eclipse JDT is now available on maven central using a new approach to publish the artifacts. Eclipse JDT现在可以在maven central上使用新方法发布工件。 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...). 对于最终用户来说,不再需要解决方法,poms是用户友好的(简单版本号,依赖项的标准maven元数据,源工件,第三方依赖...)。

Just add this to your pom: 只需将其添加到您的pom:

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

See a complete example here . 请在此处查看完整示例。

Updated version found in maven repository 在maven存储库中找到的更新版本

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM