'What are sbtconfig.txt and sbtopts used for?
In the 0.13 release of sbt, I saw these two files in sbt/conf directory, it would be really nice if I can change option inside these files instead of the launcher script.
I changed some options in sbtopts, it doesn't take effect at all, and the sbtconfig.txt does work for some options but for this option, -Dinput.encoding=iso-8859-1
(I need this option to use up arrow key to view history, otherwise it shows me messy codes) it only take effect when I add it in the sbt.bat.
Another question is, can I put these two files somewhere in ~/.sbt/
? I want to store all my sbt configurations in one place.
My OS is Windows 8.1 and working with the SBT 0.13.
Solution 1:[1]
sbtconfig.txt
(Windows only) is a configuration file that lists JVM options, and is used by sbt.bat
. sbtopts
is used by sbt
shell script.
It's probably better to read the actual script to understand exactly how's it's used, but eventually the contents would end up in a variable named _JAVA_OPTS
and passed into:
"%_JAVACMD%" %_JAVA_OPTS% %SBT_OPTS% -cp "%SBT_HOME%sbt-launch.jar" xsbt.boot.Boot %*
So you should be able to add -Dinput.encoding=Cp1252
or whatever in there. If that's not working for you, either %JAVA_OPTS%
could be non-empty (then sbtconfig.txt
is ignored), or %SBT_OPTS%
could be overriding the setting to something else? Not sure.
You can check to see if the properties are set or not using sbt console
:
scala> sys.props("input.encoding")
res0: String = null
scala> sys.props("file.encoding")
res1: String = UTF-8
Another question is, can I put these two files somewhere in
~/.sbt/
?
You should be able to modify the sbt.bat
to get that done. In fact looking at sbt
shell script, it says it looks at .sbtopts
. You can use Cygwin and see if that works.
Solution 2:[2]
$ man sbt
...
Java Options
--java-home <path>
alternate JAVA_HOME
-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)
FILES
~/.sbt
The user configuration directory.
.jvmopts
if this file exists in the current directory, its contents are appended to the JAVA_OPTS.
.sbtopts
if this file exists in the current directory, its contents are prepended to the runner args.
/etc/sbt/sbtopts
if this file exists, it is prepended to the runner args
ENVIRONMENT
JAVA_OPTS
If non-null a set of arguments passed to java.
SBT_OPTS
environment variable, if unset uses "-Dfile.encoding=UTF-8".
NOTES
In the case of duplicated or conflicting options, the order above shows precedence: JAVA_OPTS lowest, command line options high-
est.
...
Examples:
$ pwd
/tmp/helo
$ cat .sbtopts
-Dinput.encoding=iso-8859-1
$ cat .jvmopts
-Xms512m
$ sbt -v console
[sbt_options] declare -a sbt_options=()
[process_args] java_version = '8'
# Executing command line:
java
-Xms512m
-Dinput.encoding=iso-8859-1
-Dsbt.script=/usr/bin/sbt
-jar
/home/hadoop/.cache/sbt/boot/sbt-launch/1.6.2/sbt-launch-1.6.2.jar
console
[info] welcome to sbt 1.6.2 (Debian Java 1.8.0_312)
[info] loading settings for project helo-build from site.sbt ...
[info] loading project definition from /tmp/helo/project
[info] loading settings for project helo from build.sbt ...
[info] set current project to helo (in build file:/tmp/helo/)
[info] Starting scala interpreter...
Welcome to Scala 2.12.15 (OpenJDK 64-Bit Server VM, Java 1.8.0_312).
Type in expressions for evaluation. Or try :help.
scala> sys.props("input.encoding")
res1: String = iso-8859-1
scala> :q
[success] Total time: 51 s, completed Apr 29, 2022 2:26:53 PM
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Eugene Yokota |
Solution 2 |