为什么Eclipse没有将第三方lib文件源文件附加到WTP面的Gradle项目中? [英] Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?

查看:121
本文介绍了为什么Eclipse没有将第三方lib文件源文件附加到WTP面的Gradle项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

源文件被下载到Gradle缓存中,源文件的类路径条目看起来很好,但是Eclipse没有显示第三方库的源文件。

 <?xml version =1.0encoding =UTF-8?> 
< classpath>
< classpathentry kind =outputpath =bin / main/>
< classpathentry kind =srcpath =src / main / java/>
< classpathentry kind =srcpath =src / main / resources/>
< classpathentry output =bin / testkind =srcpath =src / test / java/>
< classpathentry output =bin / testkind =srcpath =src / test / resources/>
< classpathentry kind =conpath =org.eclipse.jdt.launching.JRE_CONTAINERexported =true/>
< classpathentry kind =conpath =org.eclipse.jst.j2ee.internal.web.containerexported =true/>
< classpathentry sourcepath =D:/Users/SSchneider/.gradle/cache/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/source/bc9c347358c5d59998b27e8a13c75106c3d0696/spring-webmvc- 3.1.2.RELEASE-sources.jarkind =libpath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/ jar / e02f3e5aa91c8caa37b2e9b780229d27e76c0f2e / spring-webmvc-3.1.2.RELEASE.jarexported =true>
<属性>
< attribute name =org.eclipse.jst.component.nondependencyvalue =/>
< / attributes>
< / classpathentry>
< classpathentry sourcepath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/source/ 19e4dedbb956cdc3bb1d34d61a351229b653029a / spring-data-jpa-1.2.0.BUILD-SNAPSHOT-sources.jarkind =libpath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework。 data / spring-data-jpa / 1.2.0.BUILD-SNAPSHOT / jar / 2a3cfc2ea0b2c8d87f32166e16bb56e1f092568b / spring-data-jpa-1.2.0.BUILD-SNAPSHOT.jarexported =true>
<属性>
< attribute name =org.eclipse.jst.component.nondependencyvalue =/>
< / attributes>
< / classpathentry>
< classpathentry sourcepath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/source/49e8d929d835d4ba4556ba9d138488ecc083a794/ spring-security-web-3.1.2.RELEASE-sources.jarkind =libpath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring- security-web / 3.1.2.RELEASE / jar / e43e7683289f08c1e073564a94e6f26298ec4f59 / spring-security-web-3.1.2.RELEASE.jarexported =true>
<属性>
< attribute name =org.eclipse.jst.component.nondependencyvalue =/>
< / attributes>
< / classpathentry>
< classpathentry sourcepath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/source/7a561191db2203550fbfa40d534d4997624cd369/validation-api- 1.0.0.GA-sources.jarkind =libpath =D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/ jar / b6bd7f9d78f6fdaa3c37dae18a4bd298915f328e / validation-api-1.0.0.GA.jarexported =true>
<属性>
< attribute name =org.eclipse.jst.component.nondependencyvalue =/>
< / attributes>
< / classpathentry>

< / classpath>


解决方案

这是一个奇怪的行为,在Eclipse中生成的.classpath -文件。只需将'Web App Libraries'条目放在classpath文件的底部( - > Java Build Path - > Order and Export)。



最好的解决方案是增强你的gradle.build文件(然后你不需要重新排序你的构建路径每次你通过gradle生成类路径文件):

  ... 
eclipse.classpath.file {
// Eclipse的类路径条目改变了classpathentries的顺序;否则没有显示第三方jar的来源
withXml {xml - >
def node = xml.asNode()
node.remove(node.find {it。@ path =='org.eclipse.jst.j2ee.internal.web.container'})
node.appendNode('classpathentry',[kind:'con',path:'org.eclipse.jst.j2ee.internal.web.container',exports:'true'])
}
}


The sources are downloaded in the Gradle cache and the classpath-entries for the source files looks ok, but Eclipse does not show the source files for 3rd party libs.

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="output" path="bin/main"/>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/resources"/>
    <classpathentry output="bin/test" kind="src" path="src/test/java"/>
    <classpathentry output="bin/test" kind="src" path="src/test/resources"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container" exported="true"/>
    <classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/source/bc9c347358c5d59998b27e8a13c75106c3d0696/spring-webmvc-3.1.2.RELEASE-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework/spring-webmvc/3.1.2.RELEASE/jar/e02f3e5aa91c8caa37b2e9b780229d27e76c0f2e/spring-webmvc-3.1.2.RELEASE.jar" exported="true">
        <attributes>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/source/19e4dedbb956cdc3bb1d34d61a351229b653029a/spring-data-jpa-1.2.0.BUILD-SNAPSHOT-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.data/spring-data-jpa/1.2.0.BUILD-SNAPSHOT/jar/2a3cfc2ea0b2c8d87f32166e16bb56e1f092568b/spring-data-jpa-1.2.0.BUILD-SNAPSHOT.jar" exported="true">
        <attributes>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/source/49e8d929d835d4ba4556ba9d138488ecc083a794/spring-security-web-3.1.2.RELEASE-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/org.springframework.security/spring-security-web/3.1.2.RELEASE/jar/e43e7683289f08c1e073564a94e6f26298ec4f59/spring-security-web-3.1.2.RELEASE.jar" exported="true">
        <attributes>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>
    <classpathentry sourcepath="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/source/7a561191db2203550fbfa40d534d4997624cd369/validation-api-1.0.0.GA-sources.jar" kind="lib" path="D:/Users/SSchneider/.gradle/caches/artifacts-14/filestore/javax.validation/validation-api/1.0.0.GA/jar/b6bd7f9d78f6fdaa3c37dae18a4bd298915f328e/validation-api-1.0.0.GA.jar" exported="true">
        <attributes>
            <attribute name="org.eclipse.jst.component.nondependency" value=""/>
        </attributes>
    </classpathentry>

</classpath>

解决方案

That's a weird behavior in Eclipse with the generated .classpath-file. Just put the 'Web App Libraries' entry at the bottom of your classpath file (-> Java Build Path -> Order and Export).

The best solution is to enhance your gradle.build file (then you don't need to reorder your build path each time you generate the classpath file via gradle):

...
eclipse.classpath.file {
    // Classpath entry for Eclipse which changes the order of classpathentries; otherwise no sources for 3rd party jars are shown
    withXml { xml ->
        def node = xml.asNode()
        node.remove( node.find { it.@path == 'org.eclipse.jst.j2ee.internal.web.container' } )
        node.appendNode( 'classpathentry', [ kind: 'con', path: 'org.eclipse.jst.j2ee.internal.web.container', exported: 'true'])
    }
}

这篇关于为什么Eclipse没有将第三方lib文件源文件附加到WTP面的Gradle项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆