添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to learn Scala through the Creative Scala guide. However, I get an error when I try to run on terminal the command below that is on page 12.

Now change to the directory we just created and run SBT.

cd creative-scala-template
./sbt.sh

The error I get is:

Unrecognized VM option 'CMSClassUnloadingEnabled'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

It seems that the problem is with sbt?

I tried to follow the top comment in this other question, that says to go to the folder /usr/local/etc/sbtopts and do some changes, but my folder /usr/local/ is empty.

Can anyone tells me what I am likely doing wrong, please?

By doing java -version I get:

openjdk version "18.0.2" 2022-07-19
OpenJDK Runtime Environment (build 18.0.2+9-61)
OpenJDK 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing)

And sbt -version gets me:

sbt version in this project: 1.7.1
sbt script version: 1.7.1

After the solution by Tim, I am now getting a different error when running ./sbt.sh. Does anyone knows how to fix this?

java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
    at java.base/java.lang.System.setSecurityManager(System.java:416)
    at sbt.TrapExit$.installManager(TrapExit.scala:53)
    at sbt.StandardMain$.runManaged(Main.scala:128)
    at sbt.xMain.run(Main.scala:89)
    at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
    at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
    at xsbt.boot.Launch$.run(Launch.scala:109)
    at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
    at xsbt.boot.Launch$.launch(Launch.scala:117)
    at xsbt.boot.Launch$.apply(Launch.scala:18)
    at xsbt.boot.Boot$.runImpl(Boot.scala:56)
    at xsbt.boot.Boot$.main(Boot.scala:18)
    at xsbt.boot.Boot.main(Boot.scala)
Error during sbt execution: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release

In this case, the option is defined in the sbt.sh file itself, included in the template project. This option was removed in Java 14 and later, and the guide you are using was developed with an earlier Java version.

You can edit this file and delete the text -XX:+CMSClassUnloadingEnabled from it.

All of the other options currently in that file are still supported as of Java 18.

The resulting command will look like this:

java -Xmx3g -Xms1g -XX:+TieredCompilation -XX:ReservedCodeCacheSize=256m -XX:+UseNUMA -XX:+UseParallelGC -jar sbt-launch.jar "$@"
                I submitted a pull request to remove that option, and it was accepted: github.com/creativescala/creative-scala-template/pull/6. If you get the latest version of the template, this should be fixed.
– Tim Moore
                Aug 27, 2022 at 14:26
                Thanks a lot, Tim!!! I am now getting a different error. I edited my question to include it in the end. Can you also help with this one, please?
– Rafael Pinheiro
                Aug 28, 2022 at 3:14
                I think that's related to this issue, which hasn't been fixed yet: github.com/creativescala/creative-scala-template/issues/3. If I can find some time, I'll try to submit a fix. In the meantime, your best bet may be to install an older version of Java. If you use Java 17, it will only print a warning.
– Tim Moore
                Aug 28, 2022 at 8:22
                Tim, thanks a lot again! I switched to Java 17 but I ran into a long list of errors that start with java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI, that I believe is the same as this. My solution was to install Java 1.8 (available here) and then switch my Java version to it following this guide. Now it all seems to work!! Thanks a lot!!!
– Rafael Pinheiro
                Aug 28, 2022 at 12:02
                In general, I’d stay away from options someone deemed useful for an ancient Java version and apparently never revised for newer versions. -XX:+TieredCompilation is obsolete, as it is the default and honestly, I don’t know what default ReservedCodeCacheSize has, but if it differs from 256m, I’d rather trust the default than the decision someone made a decade ago for the JVM implementation of that time. There’s a tendency to ship software with tons of options in the startup, with rather esoteric reasoning, if anyone remembers who added them and why. Give the defaults a try…
– Holger
                Aug 29, 2022 at 7:35
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.