问题描述
在IntelliJ IDEA中运行 VERY 简单的URL抓取脚本时,我得到: > java.net.SocketException:Permission denied:connect
但是当我运行它来自Groovy控制台,它工作得很好。
以下是完整的脚本:
def data = new URL(http://wisc.edu).getText()
这里是IntelliJ完整的控制台输出:
C:\ Program Files \Java\\ \\ jdk1.7.0_01\bin\java-Dtools.jar = C:\程序文件\Java\jdk1.7.0_01\lib\tools.jar-Dgroovy.home = C: \ Program Files(x86)\Groovy\Groovy-1.8.2-Dgroovy.starter.conf = C:\ Program Files(x86)\Groovy\Groovy-1.8.2\conf\ groovy-starter.conf-Didea.launcher.port = 7534-Didea.launcher.bin.path = C:\ Program Files(x86)\JetBrains\IntelliJ IDEA 110.492\bin-Dfile。 encoding = UTF-8 -classpathC:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\groovy-1.8.2.jar; C:\程序文件(x86) \\JetBrains\IntelliJ IDEA 110.492\lib\idea_rt.jarcom.intellij.rt.execution.application.AppMain org.codehaus.groovy.tools.GroovyStarter --confC:\程序文件(x86)\\ \\ Groovy \ Groovy-1.8.2 \conf \groovy-starter.conf--main groovy.ui.GroovyMain --classpathC:\ Users \ \IdeaProjects\test\ out \production\test; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\ant-1.8.2.jar; C:\程序文件(x86)\\ \\ Groovy\Groovy-1.8.2\lib\ant-antlr-1.8.2.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\ant- junit-1.8.2.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\ant-launcher-1.8.2.jar; C:\程序文件(x86 )\Groovy\Groovy-1.8.2\lib\antlr-2.7.7.jar; C:\Prog ram文件(x86)\Groovy\Groovy-1.8.2\lib\asm-3.2.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\ asm-analysis-3.2.jar; C:\程序文件(x86)\ Groovy\Groovy-1.8.2\lib\asm-commons-3.2.jar; C:\程序文件(x86)\\ \\ Groovy\Groovy-1.8.2\lib\asm-tree-3.2.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\asm-util- 3.2.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\balloontip-20090102.jar; C:\ Program Files(x86)\Groovy\Groovy- 1.8.2\lib\batik-anim-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-awt-util-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-bridge-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8。 2 \lib\batik-codec-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-css-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-dom-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib \ batik-ext-1.7.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\batik-extension-1.7.jar; C:\程序文件(x86 )\Groovy\Groovy-1.8.2\lib\batik-gui-util-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\ batik-gvt-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-parser-1.7.jar; C:\ Program Files(x86)\\ \\ Groovy\Groovy-1.8.2\lib\batik-script-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-svg- dom-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-svggen-1.7.jar; C:\ Program Files(x86)\Groovy \Groovy-1.8.2\lib\batik-swing-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\batik-tran scoder-1.7.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\batik-util-1.7.jar; C:\程序文件(x86)\Groovy \Groovy-1.8.2\lib\batik-xml-1.7.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\bsf-2.4.0。 jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\commons-cli-1.2.jar; C:\程序文件(x86)\Groovy\Groovy- 1.8.2\lib\commons-logging-1.1.1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\cssbuilder-0.5.jar; C: \ Program Files(x86)\Groovy\Groovy-1.8.2\lib\cssparser-0.9.5.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\\ \\ lib \easyb-0.9.8.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\extra166y-1.7.0.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\flamingo-4.1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\flam ingobuilder-0.4.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\forms-1.2.1.jar; C:\程序文件(x86)\Groovy \Groovy-1.8.2\lib\gant-1.9.6_groovy-1.8.1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\gfxbuilder- core-0.5.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\gfxbuilder-svg-0.5.jar; C:\ Program Files(x86)\Groovy \Groovy-1.8.2\lib\gfxbuilder-swingx-0.5.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\gmock-0.8.1。 jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\gpars-0.12.jar; C:\程序文件(x86)\Groovy\Groovy-1.8。 2 \lib\groovy-1.8.2.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\groovypp-0.9.0_1.8.2.jar; C: \程序文件(x86)\Groovy\Groovy-1.8.2\lib\groovyserv-0.9.jar; C:\程序文件(x86)\Groovy\Groovy -1.8.2\lib\ivy-2.2.0.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\jacob-1.14.3.jar; C :\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\jansi-1.6.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\ lib \ jcsp-1.1-rc5.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\jide-oss-2.9.1.jar; C:\ Program文件(x86)\Groovy\Groovy-1.8.2\lib\jidebuilder-4.0.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\jline -0.9.94.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\jna-3.2.2.jar; C:\程序文件(x86)\ Groovy\Groovy-1.8.2\lib\jsilhouette-geom-0.4.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\jsp-api-2.0 .jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\jsr166y-1.7.0.jar; C:\程序文件(x86)\Groovy\Groovy -1.8.2\lib \\ junit-4.8.2.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\l2fprod-common-all-6.9.1.jar; C:\Program文件(x86)\Groovy\Groovy-1.8.2\lib\macwidgets-0.9.4.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\\ \\ macwidgetsbuilder-0.4.1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\maven-ant-tasks-2.1.0.jar; C:\Program文件(x86)\Groovy\Groovy-1.8.2\lib\multiplegradientpaint-1.0.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\multiverse -beta-0.7-RC-1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\\\
etty-3.1.5.GA.jar; C:\ Program文件(x86)\Groovy\Groovy-1.8.2\lib\sac-1.3.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\scriptom -1.6.0.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\scriptom-ie-6-tlb-1.6.0.jar; C:\ Program费尔es(x86)\Groovy\Groovy-1.8.2\lib\scriptom-office-2K3-tlb-1.6.0.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8 .2 \lib\scriptom-sapi-tlb-1.6.0.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\scriptom-scripting-tlb-1.6 .0.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\scriptom-wbem-tlb-1.6.0.jar; C:\程序文件(x86) \Groovy\Groovy-1.8.2\lib\scriptom-wsh-tlb-1.6.0.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\\ \\servlet-api-2.4.jar; C:\ Program Files(x86)\ Groovy\Groovy-1.8.2\lib\spock-core-0.6-groovy-1.8-SNAPSHOT.jar; C:\\ \\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\swing-worker-1.1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\ lib \swingx-beaninfo-1.6.2-2.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\swingx-core-1.6.2-2.jar ; C:\程序F iles(x86)\Groovy\Groovy-1.8.2\lib\swingxbuilder-0.1.8.1.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\\ \swingxtrasbuilder-0.3.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\timingframework-1.0.jar; C:\程序文件(x86)\Groovy\\ \\ Groovy-1.8.2 \ lib \ trident-6.2.jar; C:\程序文件(x86)\ Groovy\Groovy-1.8.2\lib\tridentbuilder-0.5.jar; C:\\ \\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\xml-apis-ext-1.3.04.jar; C:\ Program Files(x86)\Groovy\Groovy-1.8 .2\lib\xmlpull-1.1.3.1.jar; C:\程序文件(x86)\Groovy\Groovy-1.8.2\lib\xstream-1.4.1.jar; C:\ \\ Program Files(x86)\Groovy\Groovy-1.8.2\lib\xswingx-0.2.jar--encoding = UTF-8 C:\ Users \ \IdeaProjects\test \test.groovy
捕获:java.net.SocketException:权限被拒绝:连接
java.net.Soc ketException:Permission denied:在test.run(test.groovy:9)处连接
;在com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
处连接
过程完成退出代码1
我完全没有 no 想法是什么导致了这个问题,但我的猜测是这是IDEA在运行groovy代码时所做的一些事情,它使它无法访问网络。
任何人都经历过这个?有人知道解决方法吗?
。添加 -Djava.net.preferIPv4Stack = true
在 VM选项中可以解决问题。
本网站上的相关问题。
When running a VERY simple URL grab script from within IntelliJ IDEA, I get:
java.net.SocketException: Permission denied: connect
but when I run it from the Groovy Console, it works just fine.
Here is the full script:
def data = new URL("http://wisc.edu").getText()
and here is the full console output from IntelliJ:
"C:\Program Files\Java\jdk1.7.0_01\bin\java" "-Dtools.jar=C:\Program Files\Java\jdk1.7.0_01\lib\tools.jar" "-Dgroovy.home=C:\Program Files (x86)\Groovy\Groovy-1.8.2" "-Dgroovy.starter.conf=C:\Program Files (x86)\Groovy\Groovy-1.8.2\conf\groovy-starter.conf" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 110.492\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\groovy-1.8.2.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 110.492\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.groovy.tools.GroovyStarter --conf "C:\Program Files (x86)\Groovy\Groovy-1.8.2\conf\groovy-starter.conf" --main groovy.ui.GroovyMain --classpath "C:\Users\[REDACTED]\IdeaProjects\test\out\production\test;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\ant-1.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\ant-antlr-1.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\ant-junit-1.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\ant-launcher-1.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\antlr-2.7.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\asm-3.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\asm-analysis-3.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\asm-commons-3.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\asm-tree-3.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\asm-util-3.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\balloontip-20090102.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-anim-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-awt-util-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-bridge-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-codec-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-css-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-dom-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-ext-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-extension-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-gui-util-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-gvt-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-parser-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-script-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-svg-dom-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-svggen-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-swing-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-transcoder-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-util-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\batik-xml-1.7.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\bsf-2.4.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\commons-cli-1.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\commons-logging-1.1.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\cssbuilder-0.5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\cssparser-0.9.5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\easyb-0.9.8.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\extra166y-1.7.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\flamingo-4.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\flamingobuilder-0.4.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\forms-1.2.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\gant-1.9.6_groovy-1.8.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\gfxbuilder-core-0.5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\gfxbuilder-svg-0.5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\gfxbuilder-swingx-0.5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\gmock-0.8.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\gpars-0.12.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\groovy-1.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\groovypp-0.9.0_1.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\groovyserv-0.9.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\ivy-2.2.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jacob-1.14.3.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jansi-1.6.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jcsp-1.1-rc5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jide-oss-2.9.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jidebuilder-4.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jline-0.9.94.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jna-3.2.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jsilhouette-geom-0.4.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jsp-api-2.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\jsr166y-1.7.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\junit-4.8.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\l2fprod-common-all-6.9.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\macwidgets-0.9.4.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\macwidgetsbuilder-0.4.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\maven-ant-tasks-2.1.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\multiplegradientpaint-1.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\multiverse-beta-0.7-RC-1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\netty-3.1.5.GA.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\sac-1.3.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-ie-6-tlb-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-office-2K3-tlb-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-sapi-tlb-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-scripting-tlb-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-wbem-tlb-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\scriptom-wsh-tlb-1.6.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\servlet-api-2.4.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\spock-core-0.6-groovy-1.8-SNAPSHOT.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\swing-worker-1.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\swingx-beaninfo-1.6.2-2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\swingx-core-1.6.2-2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\swingxbuilder-0.1.8.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\swingxtrasbuilder-0.3.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\timingframework-1.0.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\trident-6.2.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\tridentbuilder-0.5.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\xml-apis-ext-1.3.04.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\xmlpull-1.1.3.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\xstream-1.4.1.jar;C:\Program Files (x86)\Groovy\Groovy-1.8.2\lib\xswingx-0.2.jar" --encoding=UTF-8 C:\Users\[REDACTED]\IdeaProjects\test\test.groovy
Caught: java.net.SocketException: Permission denied: connect
java.net.SocketException: Permission denied: connect
at test.run(test.groovy:9)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Process finished with exit code 1
I have absolutely no idea what is causing the problem, but my guess is that it's something IDEA is doing when it runs the groovy code that keeps it from being able to access the network.
Has anyone else experienced this? Does anyone know of a workaround?
There is a known bug in JDK 1.7 related to IPv6.
Adding -Djava.net.preferIPv4Stack=true
in VM Options should fix the problem.
See also related question on this site.
这篇关于奇怪的java.net.SocketException权限在Intellij IDEA中运行Groovy时,拒绝连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!