IntelliJ IDEA / Scala:在类路径上运行配置丢失资源 [英] IntelliJ IDEA / Scala: run configuration miss resources on class path
问题描述
我一直处于关闭状态,因为有一段时间我一直不了解发生了什么:我在IntelliJ中导入了一个基于sbt的项目,并且在IntelliJ中运行它时,它似乎缺少了项目资源( src / main / resources
)放在类路径上,导致 .getClass.getResource(...)
调用返回 null
。
我倾向于删除 .idea
并重新创建项目,因为我怀疑是从以前的IntelliJ版本升级现有的 .idea
导致的缓存问题。但是今天没有运气。有时将 .getResource
更改为 .getResourceAsStream
似乎可以解决问题,但今天仍然没有运气。
检查项目设置,目录已正确切换为资源:
不用说,在终端机上使用 sbt test:run
FWIF,这是来自IDEA的运行调用,在这里我根本无法在类路径中找到资源:
/ usr / lib / jvm / java-8-oracle / bin / java -agentlib:jdwp = tra nsport = dt_socket,地址= 127.0.0.1:47427,suspend = y,服务器= n -Dfile.encoding = UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar: /usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm /java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8 -oracle / jre / lib / ext / jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/ usr / lib / jvm / java-8-oracle / jre /lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext /sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar :/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/ usr / lib / jvm / java-8-oracle / jre / lib / jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/ usr / lib / jvm / java-8-oracle / jre / lib / jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/ usr / lib / jvm / java-8 -oracle / jre / lib / plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/ usr / lib / jvm / java-8-oracle / jre / lib / rt .jar:/home/hhrutz/Documents/devel/Wolkenpumpe/target/scala-2.11/test-classes:/home/hhrutz/Documents/devel/Wolkenpumpe/target/scala-2.11/classes:/home/hhrutz/.ivy2 /cache/com.github.scopt/scopt_2.11/jars/scopt_2.11-3.4.0.jar:/home/hhrutz/.ivy2/cache/org.slf4j/slf4j-simple/jars/slf4j-simple-1.7 .18.jar:/home/hhrutz/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.18.jar:/home/hhrutz/.ivy2/cache/org.scalatest/scalatest_2 .11 / bundles / scalatest_2.11-2.2.6.jar:/home/hhrutz/.ivy2/cache/org.scala-stm/scala-stm_2.11/jars/scala-stm_2.11-0.7.jar:/ home / hhrutz / .ivy2 / cache / org.scala-lang.modules / scala-xml_2.11 / bundles / scala-xml_2.11-1.0.5.jar:/home/hhrutz/.ivy2/cache/org.scala -lang.modules / scala-swing_2.11 / bundles / scala-swing_2.11-1.0.2.jar:/home/hhrutz/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect -2.11.7.jar:/home/hhrutz/.ivy2/cache/org.scala-lang/scala-library/jars/scala-li brary-2.11.8.jar:/home/hhrutz/.ivy2/cache/net.sourceforge.jtransforms/jtransforms/jars/jtransforms-2.4.0.jar:/home/hhrutz/.ivy2/cache/net.html解析器。 jericho / jericho-html / jars / jericho-html-3.3.jar:/home/hhrutz/.ivy2/cache/lucene/lucene/jars/lucene-1.4.3.jar:/home/hhrutz/.ivy2/cache/ junit / junit / jars / junit-4.8.2.jar:/home/hhrutz/.ivy2/local/de.sciss/weblaf-ui/2.1.0/jars/weblaf-ui.jar:/ home / hhrutz /。 ivy2 / local / de.sciss / weblaf-core / 2.1.0 / jars / weblaf-core.jar:/home/hhrutz/.ivy2/local/de.sciss/treetable-scala_2.11/1.3.8/jars/ treetable-scala_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/treetable-java/1.3.8/jars/treetable-java.jar:/home/hhrutz/.ivy2/cache/de。 sciss / topology_2.11 / jars / topology_2.11-1.0.0.jar:/home/hhrutz/.ivy2/local/de.sciss/swingplus_2.11/0.2.1/jars/swingplus_2.11.jar:/ home /hhrutz/.ivy2/local/de.sciss/submin/0.2.0/jars/submin.jar:/home/hhrutz/.ivy2/cache/de.sciss/span_2.11/jars/span_2.11-1.3。 1.jar:/home/hhrutz/.ivy2/local/de.sciss/soundprocesses-views_2.11/3.4.0/jars/soundprocesses -views_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/soundprocesses-core_2.11/3.4.0/jars/soundprocesses-core_2.11.jar:/home/hhrutz/.ivy2/cache /de.sciss/serial_2.11/jars/serial_2.11-1.0.2.jar:/home/hhrutz/.ivy2/cache/de.sciss/scissdsp_2.11/jars/scissdsp_2.11-1.2.2.jar :/home/hhrutz/.ivy2/local/de.sciss/scalaosc_2.11/1.1.5/jars/scalaosc_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderugens-plugins_2.11 /1.14.1/jars/scalacolliderugens-plugins_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderugens-core_2.11/1.14.1/jars/scalacolliderugens-core_2.11.jar:/ home / hhrutz / .ivy2 / local / de.sciss / scalacolliderugens-api_2.11 / 1.14.1 / jars / scalacolliderugens-api_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderswing-core_2 .11 / 1.28.0 / jars / scalacolliderswing-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacollider_2.11/1.18.1/jars/scalacollider_2.11.jar:/ home / hhrutz / .ivy2 / cache / de.sciss / scalaaudiofile_2.11 / jars / scalaaudiofile_2.11-1.4.5.jar:/home/hhrutz/.ivy2/local/de.sciss/raphael-ico ns_2.11 / 1.0.3 / jars / raphael-icons_2.11.jar:/home/hhrutz/.ivy2/cache/de.sciss/processor_2.11/jars/processor_2.11-0.4.0.jar:/ home /hhrutz/.ivy2/local/de.sciss/prefuse-core/1.0.1/jars/prefuse-core.jar:/home/hhrutz/.ivy2/cache/de.sciss/numbers_2.11/jars/numbers_2。 11-0.1.1.jar:/home/hhrutz/.ivy2/cache/de.sciss/model_2.11/jars/model_2.11-0.3.2.jar:/home/hhrutz/.ivy2/local/de。 sciss / lucresynth_2.11 / 3.4.0 / jars / lucresynth_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucreswing_2.11/1.3.0/jars/lucreswing_2.11.jar:/ home /hhrutz/.ivy2/local/de.sciss/lucre-expr_2.11/3.3.1/jars/lucre-expr_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucre-core_2。 11 / 3.3.1 / jars / lucre-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucre-confluent_2.11/3.3.1/jars/lucre-confluent_2.11.jar: /home/hhrutz/.ivy2/local/de.sciss/lucre-bdb_2.11/3.3.1/jars/lucre-bdb_2.11.jar:/home/hhrutz/.ivy2/cache/de.sciss/intensitypalette/ jars / intensitypalette-1.0.0.jar:/home/hhrutz/.ivy2/cache/de.sciss/fingertree_2.11/jars/fingertree_2.11-1.5.2.jar: /home/hhrutz/.ivy2/cache/de.sciss/fileutil_2.11/jars/fileutil_2.11-1.1.1.jar:/home/hhrutz/.ivy2/local/de.sciss/desktop_2.11/0.7。 2 / jars / desktop_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/audiowidgets-swing_2.11/1.9.4/jars/audiowidgets-swing_2.11.jar:/ home / hhrutz /。 ivy2 / local / de.sciss / audiowidgets-core_2.11 / 1.9.4 / jars / audiowidgets-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/audiowidgets-app_2.11/1.9。 2 / jars / audiowidgets-app_2.11.jar:/home/hhrutz/.ivy2/cache/com.thoughtworks.xstream/xstream/jars/xstream-1.4.8.jar:/home/hhrutz/.ivy2/cache/ com.sleepycat / je / jars / je-5.0.104.jar:/home/hhrutz/.ivy2/cache/com.mortennobel/java-image-scaling/jars/java-image-scaling-0.8.6.jar: /home/hhrutz/.ivy2/cache/com.jhlabs/filters/jars/filters-2.0.235.jar:/home/hhrutz/Applications/idea-IC-16/lib/idea_rt.jar de.sciss.nuages。演示
删除运行配置并重新创建它 问题。
上一个中断的调用是:
java -agentlib:jdwp = transport = dt_socket,地址= 127.0.0.1:47427,suspend = y,server = n \
-classpath ... \
de.sciss.nuages.Demo
新的正确呼叫变为:
java -Didea.launcher.port = 7534 \
-Didea.launcher.bin.path = / home / hhrutz / Applications / idea-IC-16 / bin \
-classpath ... \
com.intellij.rt.execution.application.AppMain de.sciss.nuages.Demo
因此,尽管类路径相同,但启动机制却完全不同。
I have this problem on an off since quite while without ever understanding what is going on: I import an sbt-based project in IntelliJ, and when running it from within IntelliJ, it seems to be missing project resources (src/main/resources
) on the class path, resulting in .getClass.getResource(...)
calls to return null
.
I tend to delete .idea
and create the project anew as I'm suspecting a caching problem from upgrading an existing .idea
from previous IntelliJ version. But no luck today. Sometimes changing .getResource
to .getResourceAsStream
seems to solve it, but again no luck today.
Checking the project settings, the directory is correctly toggled as 'Resources':
And checking the run configuration, the module/class-path is correctly selected:
Needless to say, using sbt test:run
from the terminal works as expected, resources are found.
FWIF, here is the run call from IDEA, where I cannot find the resources in the classpath at all:
/usr/lib/jvm/java-8-oracle/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:47427,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/deploy.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jaccess.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/nashorn.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunec.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-8-oracle/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-8-oracle/jre/lib/javaws.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfxswt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/management-agent.jar:/usr/lib/jvm/java-8-oracle/jre/lib/plugin.jar:/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/home/hhrutz/Documents/devel/Wolkenpumpe/target/scala-2.11/test-classes:/home/hhrutz/Documents/devel/Wolkenpumpe/target/scala-2.11/classes:/home/hhrutz/.ivy2/cache/com.github.scopt/scopt_2.11/jars/scopt_2.11-3.4.0.jar:/home/hhrutz/.ivy2/cache/org.slf4j/slf4j-simple/jars/slf4j-simple-1.7.18.jar:/home/hhrutz/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.18.jar:/home/hhrutz/.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.6.jar:/home/hhrutz/.ivy2/cache/org.scala-stm/scala-stm_2.11/jars/scala-stm_2.11-0.7.jar:/home/hhrutz/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.5.jar:/home/hhrutz/.ivy2/cache/org.scala-lang.modules/scala-swing_2.11/bundles/scala-swing_2.11-1.0.2.jar:/home/hhrutz/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.7.jar:/home/hhrutz/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.8.jar:/home/hhrutz/.ivy2/cache/net.sourceforge.jtransforms/jtransforms/jars/jtransforms-2.4.0.jar:/home/hhrutz/.ivy2/cache/net.htmlparser.jericho/jericho-html/jars/jericho-html-3.3.jar:/home/hhrutz/.ivy2/cache/lucene/lucene/jars/lucene-1.4.3.jar:/home/hhrutz/.ivy2/cache/junit/junit/jars/junit-4.8.2.jar:/home/hhrutz/.ivy2/local/de.sciss/weblaf-ui/2.1.0/jars/weblaf-ui.jar:/home/hhrutz/.ivy2/local/de.sciss/weblaf-core/2.1.0/jars/weblaf-core.jar:/home/hhrutz/.ivy2/local/de.sciss/treetable-scala_2.11/1.3.8/jars/treetable-scala_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/treetable-java/1.3.8/jars/treetable-java.jar:/home/hhrutz/.ivy2/cache/de.sciss/topology_2.11/jars/topology_2.11-1.0.0.jar:/home/hhrutz/.ivy2/local/de.sciss/swingplus_2.11/0.2.1/jars/swingplus_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/submin/0.2.0/jars/submin.jar:/home/hhrutz/.ivy2/cache/de.sciss/span_2.11/jars/span_2.11-1.3.1.jar:/home/hhrutz/.ivy2/local/de.sciss/soundprocesses-views_2.11/3.4.0/jars/soundprocesses-views_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/soundprocesses-core_2.11/3.4.0/jars/soundprocesses-core_2.11.jar:/home/hhrutz/.ivy2/cache/de.sciss/serial_2.11/jars/serial_2.11-1.0.2.jar:/home/hhrutz/.ivy2/cache/de.sciss/scissdsp_2.11/jars/scissdsp_2.11-1.2.2.jar:/home/hhrutz/.ivy2/local/de.sciss/scalaosc_2.11/1.1.5/jars/scalaosc_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderugens-plugins_2.11/1.14.1/jars/scalacolliderugens-plugins_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderugens-core_2.11/1.14.1/jars/scalacolliderugens-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderugens-api_2.11/1.14.1/jars/scalacolliderugens-api_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacolliderswing-core_2.11/1.28.0/jars/scalacolliderswing-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/scalacollider_2.11/1.18.1/jars/scalacollider_2.11.jar:/home/hhrutz/.ivy2/cache/de.sciss/scalaaudiofile_2.11/jars/scalaaudiofile_2.11-1.4.5.jar:/home/hhrutz/.ivy2/local/de.sciss/raphael-icons_2.11/1.0.3/jars/raphael-icons_2.11.jar:/home/hhrutz/.ivy2/cache/de.sciss/processor_2.11/jars/processor_2.11-0.4.0.jar:/home/hhrutz/.ivy2/local/de.sciss/prefuse-core/1.0.1/jars/prefuse-core.jar:/home/hhrutz/.ivy2/cache/de.sciss/numbers_2.11/jars/numbers_2.11-0.1.1.jar:/home/hhrutz/.ivy2/cache/de.sciss/model_2.11/jars/model_2.11-0.3.2.jar:/home/hhrutz/.ivy2/local/de.sciss/lucresynth_2.11/3.4.0/jars/lucresynth_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucreswing_2.11/1.3.0/jars/lucreswing_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucre-expr_2.11/3.3.1/jars/lucre-expr_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucre-core_2.11/3.3.1/jars/lucre-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucre-confluent_2.11/3.3.1/jars/lucre-confluent_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/lucre-bdb_2.11/3.3.1/jars/lucre-bdb_2.11.jar:/home/hhrutz/.ivy2/cache/de.sciss/intensitypalette/jars/intensitypalette-1.0.0.jar:/home/hhrutz/.ivy2/cache/de.sciss/fingertree_2.11/jars/fingertree_2.11-1.5.2.jar:/home/hhrutz/.ivy2/cache/de.sciss/fileutil_2.11/jars/fileutil_2.11-1.1.1.jar:/home/hhrutz/.ivy2/local/de.sciss/desktop_2.11/0.7.2/jars/desktop_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/audiowidgets-swing_2.11/1.9.4/jars/audiowidgets-swing_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/audiowidgets-core_2.11/1.9.4/jars/audiowidgets-core_2.11.jar:/home/hhrutz/.ivy2/local/de.sciss/audiowidgets-app_2.11/1.9.2/jars/audiowidgets-app_2.11.jar:/home/hhrutz/.ivy2/cache/com.thoughtworks.xstream/xstream/jars/xstream-1.4.8.jar:/home/hhrutz/.ivy2/cache/com.sleepycat/je/jars/je-5.0.104.jar:/home/hhrutz/.ivy2/cache/com.mortennobel/java-image-scaling/jars/java-image-scaling-0.8.6.jar:/home/hhrutz/.ivy2/cache/com.jhlabs/filters/jars/filters-2.0.235.jar:/home/hhrutz/Applications/idea-IC-16/lib/idea_rt.jar de.sciss.nuages.Demo
Deleting the run configuration and creating it anew "fixed" the problem. It seems to be a bug in IntelliJ, perhaps related to caching or indexing.
The previous broken call was:
java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:47427,suspend=y,server=n \
-classpath ... \
de.sciss.nuages.Demo
The new correct call became:
java -Didea.launcher.port=7534 \
-Didea.launcher.bin.path=/home/hhrutz/Applications/idea-IC-16/bin \
-classpath ... \
com.intellij.rt.execution.application.AppMain de.sciss.nuages.Demo
So while the classpath is same, the launching mechanism is completely different.
这篇关于IntelliJ IDEA / Scala:在类路径上运行配置丢失资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!