gpt4 book ai didi

java - Eclipse 和 Gradle 类路径导致启动缓慢

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:39 25 4
gpt4 key购买 nike

好吧,这有点奇怪。

我们有一个 Gradle 多模块项目。我们使用 Gradle Eclipse 插件来生成 Eclipse 类路径。

Gradle 版本 2.0Eclipse 4.4(开普勒)JDK 1.8.05

问题是运行 Junit 测试或启动 Java 时,测试需要很长时间才能开始运行。超过 5 秒。

我在“进度”窗口中看到以下输出。

Launching: Starting virtual machine...

我之前没有遇到过这个问题,其他项目工作正常(不使用 gradle 生成的类路径)

生成的 .classpath 文件如下所示

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="build"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.2/decd76e2c461157804473468bbdc6b8eb6d6121b/logback-classic-1.1.2-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.2/b316e9737eea25e9ddd6d88eaeee76878045c6b2/logback-classic-1.1.2.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.slf4j/jcl-over-slf4j/1.7.7/b5a646b81b899e930f8600c5f45766dd82743d93/jcl-over-slf4j-1.7.7-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.slf4j/jcl-over-slf4j/1.7.7/56003dcd0a31deea6391b9e2ef2f2dc90b205a92/jcl-over-slf4j-1.7.7.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/com.google.guava/guava/17.0/7ca0efbeb87ca845b5d7a0ac9c21a4b7b95f7b28/guava-17.0-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/com.google.guava/guava/17.0/9c6ef172e8de35fd8d4d8783e4821e57cdef7445/guava-17.0.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.3.2/d2a489573c0ed2c4942b3660decad5d65087b406/commons-lang3-3.3.2-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.apache.commons/commons-lang3/3.3.2/90a3822c38ec8c996e84c16a3477ef632cbc87a3/commons-lang3-3.3.2.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/javax.inject/javax.inject/1/a00123f261762a7c5e0ec916a2c7c8298d29c400/javax.inject-1-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/javax.inject/javax.inject/1/6975da39a7040257bd51d21a231b76c915872d38/javax.inject-1.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-web/4.0.6.RELEASE/ea420724d884a43e3db4b08d2ca5ff75715ff9bb/spring-web-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-web/4.0.6.RELEASE/85ef4b91fcdd86d81e4a9b3e5f006dcb4128e6d/spring-web-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/com.google.code.gson/gson/2.2.4/a6dc5db8a12928e583bd3f23e72d3ab611ecd58f/gson-2.2.4-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/com.google.code.gson/gson/2.2.4/a60a5e993c98c864010053cb901b7eab25306568/gson-2.2.4.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.hamcrest/hamcrest-library/1.3/47a7ee46628ab7133129cd7cef1e92657bc275e/hamcrest-library-1.3-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.hamcrest/hamcrest-library/1.3/4785a3c21320980282f9f33d0d1264a69040538f/hamcrest-library-1.3.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.mockito/mockito-core/1.9.5/46f703fb4266140c544d48a189cb25947eb6333e/mockito-core-1.9.5-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.mockito/mockito-core/1.9.5/c3264abeea62c4d2f367e21484fbb40c7e256393/mockito-core-1.9.5.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-test/4.0.6.RELEASE/f0e39db787769d8926a6ae7baed1a1ebb9d6e50a/spring-test-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-test/4.0.6.RELEASE/b2f65445f300f1317fe694e6530cce39d7090ff6/spring-test-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/ch.qos.logback/logback-core/1.1.2/502e1c764542fe747896c1dc04f023acfe0e5cbc/logback-core-1.1.2-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/ch.qos.logback/logback-core/1.1.2/2d23694879c2c12f125dac5076bdfd5d771cc4cb/logback-core-1.1.2.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-aop/4.0.6.RELEASE/d21d57199535402a4afdb4e9406d6f5276a5b205/spring-aop-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-aop/4.0.6.RELEASE/e377760b7692569535573ba9f6e80b4b74869369/spring-aop-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-beans/4.0.6.RELEASE/5e37af2dc3a230912dbb06b45cc2c1d53c2c9abb/spring-beans-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-beans/4.0.6.RELEASE/587879b58acebeb5b0a63c01e822f9b44d9a4c77/spring-beans-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-context/4.0.6.RELEASE/778949f894ac1ee2d42a8f074a7477540f4d04a/spring-context-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-context/4.0.6.RELEASE/3bb3a52edabf9ffe73aa534fb085c816bac28b4d/spring-context-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-core/4.0.6.RELEASE/5b16ad4018f9012ce3917e2e1038d19d2da57285/spring-core-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-core/4.0.6.RELEASE/d880beac77d42c5798aa2b632ddd0e4ae47c79ad/spring-core-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.objenesis/objenesis/1.0/b10c90e57b7bb985a7b6a704769428fe5c2a732c/objenesis-1.0-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.objenesis/objenesis/1.0/9b473564e792c2bdf1449da1f0b1b5bff9805704/objenesis-1.0.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/junit/junit/4.11/28e0ad201304e4a4abf999ca0570b7cffc352c3c/junit-4.11-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/aopalliance/aopalliance/1.0/4a4b6d692e17846a9f3da036438a7ac491d3c814/aopalliance-1.0-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/aopalliance/aopalliance/1.0/235ba8b489512805ac13a8f9ea77a1ca5ebe3e8/aopalliance-1.0.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-expression/4.0.6.RELEASE/b86718cc9e7b5f53be187e8e35b44ad2dfd0196b/spring-expression-4.0.6.RELEASE-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.springframework/spring-expression/4.0.6.RELEASE/5f0a135b8cf290aa244097dc6264ad0989d25c56/spring-expression-4.0.6.RELEASE.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/commons-logging/commons-logging/1.1.3/28bb0405fddaf04f15058fbfbe01fe2780d7d3b6/commons-logging-1.1.3-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/commons-logging/commons-logging/1.1.3/f6f66e966c70a83ffbdb6f17a0919eaf7c8aca7f/commons-logging-1.1.3.jar" exported="true"/>
<classpathentry sourcepath="C:/gradlehome/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.7/acd62e31cc314266e73eebed0b6dd7ea974a0ed/slf4j-api-1.7.7-sources.jar" kind="lib" path="C:/gradlehome/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.7/2b8019b6249bb05d81d3a3094e468753e2b21311/slf4j-api-1.7.7.jar" exported="true"/>
<classpathentry kind="src" path="/my-api-core" exported="true"/>
</classpath>

如果我将库复制到项目内的文件夹并删除突出显示的行最后一个条目,那么测试将在几毫秒内开始!最后一个类路径条目的类型为“src”

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="build"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
<classpathentry kind="lib" path="lib/aopalliance-1.0.jar" />
<classpathentry kind="lib" path="lib/commons-lang3-3.3.2.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.1.3.jar"/>
<classpathentry kind="lib" path="lib/guava-17.0.jar"/>
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/hamcrest-library-1.3.jar"/>
<classpathentry kind="lib" path="lib/javax.inject-1.jar"/>
<classpathentry kind="lib" path="lib/jcl-over-slf4j-1.7.7.jar"/>
<classpathentry kind="lib" path="lib/logback-classic-1.1.2.jar"/>
<classpathentry kind="lib" path="lib/logback-core-1.1.2.jar"/>
<classpathentry kind="lib" path="lib/marketplace-api-core-1.0.jar"/>
<classpathentry kind="lib" path="lib/mockito-core-1.9.5.jar"/>
<classpathentry kind="lib" path="lib/objenesis-1.0.jar"/>
<classpathentry kind="lib" path="lib/slf4j-api-1.7.7.jar"/>
<classpathentry kind="lib" path="lib/spring-aop-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/spring-beans-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/spring-context-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/spring-core-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/spring-expression-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/spring-gson-http-message-converter.jar"/>
<classpathentry kind="lib" path="lib/spring-test-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/spring-web-4.0.6.RELEASE.jar"/>
<classpathentry kind="lib" path="lib/gson-2.2.4.jar" exported="true"/>
**<classpathentry exported="true" kind="src" path="/my-api-core"/>**
</classpath>

我无法找出导致启动缓慢的原因?

更新:如果我创建 Ubuntu VM 并使用与 Gradle 生成的 Eclipse 类路径相同的项目,则不会出现问题

最佳答案

正如您所见,Gradle 在生成 Eclipse 配置文件方面做得很糟糕。我推荐installing the Gradle IDE features from Spring Tool Suite并让它管理您的 Eclipse 构建路径。这样,您最终会得到一个 .classpath,它没有每个依赖项的绝对路径。它看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry exported="true" kind="con" path="org.springsource.ide.eclipse.gradle.classpathcontainer">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

我真的希望生成 Eclipse 项目文件的 Gradle 插件更智能,但从我读到的内容来看,该团队似乎对此主题不感兴趣。

顺便说一句,还建议将 .project.classpath 以及其他 Eclipse 配置文件 checkin 源代码管理中,以便每个用户都获得完全相同的项目配置。

关于java - Eclipse 和 Gradle 类路径导致启动缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25425983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com