如何配置sbt以使用代理?
例如,我的生成定义需要连接到GitHub上,用于指定连接参数http.proxy,http.proxyPort,user,和password.
我如何将这些设置传递给sbt?
当我在家工作时,是否有一种简单的方法可以在代理/无代理设置之间切换?
Fai*_*aiz 129
sbt 尊重http代理设置的常用环境变量:
export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=yourserver -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=password"
Run Code Online (Sandbox Code Playgroud)
(当然,假设是Unix(Linux/OSX等).在Windows上你可以%JAVA_OPTS%像往常一样在Windows中设置相同的环境变量().)
然后sbt像往常一样运行:
sbt
Run Code Online (Sandbox Code Playgroud)
在代理/无代理之间切换应该是设置一个小脚本,你可以随时"啜饮"它.
yourserver值中包含"http://"yourserver值中包含端口https.proxyHost,https.proxyPort因为很多东西都适用于httpsshred或srm整个文件).如果您使用的是Windows,请不要担心,您的安全性已经搞砸了,您不能再做任何伤害.Jac*_*ski 25
sbt 与通常配置其他基于JVM的项目的方式相比,它以相当标准的方式工作.
sbt实际上是两个"子系统" - 发射器和核心.通常xsbt.boot.Boot在核心启动之前执行我们都知道的功能(有些甚至更喜欢).
因此,您应该如何执行sbt,说明如何为HTTP,HTTPS和FTP网络流量设置代理.
以下是可以为任何Java应用程序设置的可用属性的完整列表,包括指示Java API通过代理路由通信的sbt:
将http以上替换为https和ftp获取服务的属性列表.
某些sbt脚本用于JAVA_OPTS设置代理设置-Dhttp.proxyHost以及-Dhttp.proxyPort其他脚本(如上所列).请参阅Java Networking and Proxies.
某些脚本使用自己的方式来设置代理配置SBT_OPTS,.sbtopts或者(仅在Windows上)%SBT_HOME%\conf\sbtconfig.txt.您可以使用它们专门设置sbt以使用代理,而其他基于JVM的应用程序根本不受影响.
从sbt命令行工具:
# jvm options and output control
JAVA_OPTS environment variable, if unset uses "$java_opts"
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
.sbtopts if this file exists in the current directory, it is
prepended to the runner args
/etc/sbt/sbtopts if this file exists, it is prepended to the runner args
-Dkey=val pass -Dkey=val directly to the java runtime
-J-X pass option -X directly to the java runtime
(-J is stripped)
-S-X add -X to sbt's scalacOptions (-S is stripped)
Run Code Online (Sandbox Code Playgroud)
这里有一段摘录sbt.bat:
@REM Envioronment:
@REM JAVA_HOME - location of a JDK home dir (mandatory)
@REM SBT_OPTS - JVM options (optional)
@REM Configuration:
@REM sbtconfig.txt found in the SBT_HOME.
Run Code Online (Sandbox Code Playgroud)
小心sbtconfig.txt,仅仅适用于Windows 只.当您使用cygwin该文件时,不会咨询,您将不得不求助于使用其他方法.
我正在使用带有以下脚本的sbt:
$JAVA_HOME/bin/java $SBT_OPTS -jar /Users/jacek/.ivy2/local/org.scala-sbt/sbt-launch/$SBT_LAUNCHER_VERSION-SNAPSHOT/jars/sbt-launch.jar "$@"
Run Code Online (Sandbox Code Playgroud)
该脚本的要点是使用从源构建的最新版本的sbt(这就是我使用的原因/Users/jacek/.ivy2/local/org.scala-sbt/sbt-launch/$SBT_LAUNCHER_VERSION-SNAPSHOT/jars/sbt-launch.jar)和$SBT_OPTS属性作为将JVM属性传递给JVM sbt使用的方法.
上面的脚本让我在MacOS X上的命令行上设置代理,如下所示:
SBT_OPTS="-Dhttp.proxyHost=proxyhost -Dhttp.proxyPort=9999" sbt
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,有很多方法可以为sbt设置代理,所有这些方法都可以归结为为JVM sbt使用设置代理.
blu*_*sky 11
我用过(这是一个unix环境):
export SBT_OPTS="$SBT_OPTS -Dhttp.proxyHost=myproxy-Dhttp.proxyPort=myport"
Run Code Online (Sandbox Code Playgroud)
这对我的设置不起作用:
export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=myproxy-Dhttp.proxyPort=myport"
Run Code Online (Sandbox Code Playgroud)
在sbt.sh文件中:
JAVA_OPTS environment variable, if unset uses "$java_opts"
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
Run Code Online (Sandbox Code Playgroud)
但显然使用SBT_OPTS而不是JAVA_OPTS
小智 11
在Windows环境中,只需在sbt/sbtconfig.txt中添加以下行
-Dhttp.proxyHost=PROXYHOST
-Dhttp.proxyPort=PROXYPORT
-Dhttp.proxyUser=USERNAME
-Dhttp.proxyPassword=XXXX
Run Code Online (Sandbox Code Playgroud)
或Https等价物(感谢评论)
-Dhttps.proxyHost=PROXYHOST
-Dhttps.proxyPort=PROXYPORT
-Dhttps.proxyUser=USERNAME
-Dhttps.proxyPassword=XXXX
Run Code Online (Sandbox Code Playgroud)
小智 9
对于Windows用户,请输入以下命令:
set JAVA_OPTS=-Dhttp.proxySet=true -Dhttp.proxyHost=[Your Proxy server] -Dhttp.proxyPort=8080
Run Code Online (Sandbox Code Playgroud)
提供一个适用于所有Windows用户的答案:
将以下内容添加到sbtconfig.txt(C:\ Program Files(x86)\ sbt\conf)
-Dhttp.proxyHost=XXXXXXX -Dhttp.proxyPort=YYYY -Dhttp.proxySet=true -Dhttps.proxyHost=XXXXXXX -Dhttps.proxyPort=YYYY -Dhttps.proxySet=true
Run Code Online (Sandbox Code Playgroud)
将XXXXXXX替换为您的proxyHost,将YYYY替换为您的proxyPort.
如果您收到错误"无法找到或加载主类",则需要设置JAVA_HOME:
set JAVA_HOME=C:\Progra~1\Java\jdkxxxxxx
Run Code Online (Sandbox Code Playgroud)
在64位窗口上时,使用:
Progra~1 ='程序文件'
Progra~2 ='程序文件(x86)'
| 归档时间: |
|
| 查看次数: |
90732 次 |
| 最近记录: |