I tried running my scala project with CLI arguments using sbt launcher version 0.12.1. It works OK when run from the scala prompt:
$ sbt
[info] (...)
> run sth
(...)
[success] Total time: 0 s, completed Nov 9, 2012 3:04:47 PM
But when I want to run it whole from shell, as per this answer for example, I'm getting an error:
$ sbt "run sth"
[info] (...)
you need to provide source file name
[success] Total time: 0 s, completed Nov 9, 2012 3:07:07 PM
[error] Not a valid command: sth (similar: set, last, shell)
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: sth (similar: test, state, watch)
[error] sth
[error] ^
And the "you need to provide source file name" info is given by my scala project to indicate that main didn't get any CLI arguments.
Is it something that worked in the previous version of sbt (in the referenced question), or am I doing something wrong?
The problem could be the way you pass arguments in your sbt launch file to Java. In my case it is:
java -Xmx4096M -jar `dirname $0`/sbt-launch_0.12.1.jar "$#"
And I just confirmed: It works with both 0.12 and 0.12.1. For instance, for a program that just prints its arguments I get:
$ sbt "run-main SomeMain blah blah"
Outut:
[blah, blah]
By using run-main you can also avoid the possibility that sbt somehow does not see your main function.
That's a bug in the 0.12.1 launcher: https://github.com/sbt/sbt-launcher-package/issues/34
Related
I am attempting to create the PlayFramework Scala seed project.
So far I've used sbt new playframework/play-scala-seed.g8 command and it has created the necessary files within my root directory movie-app.
From this point, PlayFramework says to run sbt run, so I tried that, but I get the following error:
[info] Updated file *omitting personal directories*/Movie-App/project/build.properties: set sbt.version to 1.4.7
[info] welcome to sbt 1.4.7 (Ubuntu Java 11.0.10)
[info] loading project definition from *omitting personal directories*/Movie-App/project
[info] set current project to movie-app (in build file:*omitting personal directories*/Movie-App/)
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 0 s, completed Jul 2, 2021, 11:27:33 PM
I haven't found anything helpful online yet.
Do I need to set the current project to "movie-app" like the error says? If so what do I need to write in the build.properties file?
If not, can anyone please explain the issue?
Thanks
$> sbt new playframework/play-scala-seed.g8
This template generates a Play Scala project.
Give it a name when asked. Skip rest by pressing enter.
name [play-scala-seed]: movie-app
$> cd movie-app
$> sbt run
Yes, a beginner question! I'm looking at https://github.com/sbt/sbt-license-report and see the usage section of:
> dumpLicenseReport
This dumps a ...
Well no, that is a partial application of the greater-than operator, >. But seriously, I think this means:
One: Run sbt
$ sbt
... debug info ...
[proj-name] $
OK, we're in a sort of REPL. Now two: dumpLicenseReport:
[proj-name] $ dumpLicenseReport
[error] dumpLicenseReport
[error] ^
Ok so that wasn't a repl so much as an "sbt shell". In this shell one valid command is console which does get to a repl:
[proj-name] $ console
...
scala> dumpLicenseReport
^
error: not found: value dumpLicenseReport
OOps, I didn't define the license.sbt file they show in the instructions. Doing that then...
[proj-name] $ console
...
scala> dumpLicenseReport
...
[error] stack trace is suppressed; run last update for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.typesafe.sbt:sbt-license-report;sbtVersion=1.0;scalaVersion=2.13:1.2.0
[error] Not found
[error] Not found
[error] not found: .../.ivy2/local/com.typesafe.sbt/sbt-license-report/scala_2.13/sbt_1.0/1.2.0/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/typesafe/sbt/sbt-license-report_2.13_1.0/1.2.0/sbt-license-report-1.2.0.pom
[error] not found: https://repo.typesafe.com/typesafe/releases/com/typesafe/sbt/sbt-license-report_2.13_1.0/1.2.0/sbt-license-report-1.2.0.pom
[error] Total time: 1 s, completed Feb 5, 2021, 10:18:25 PM
Now I'm guessing I just need to enter the right upstream location somewhere but I've not used sbt before. Would someone show me how to go from a *nix system with bash + sbt + jdk11 to running sbt-license-report?
#LuisMiguelMejíaSuárez indicated this is an SBT command intended to be ran from an SBT shell so the process is:
Enter your repository directory
Ensure you created license.sbt correctly, including having it under the project sub directory.
run sbt compile
run sbt dumpLicenseReport
Or Instead of steps 3 and 4 you can enter the shell with just sbt and execute commands of compile then dumpLicenseReport. The > prompt in the readme of the sbt-license-report repository indicates an SBT shell and not a repl (the "console") and certainly not a naked *nix shell (bash, zsh, etc).
I have a project created from a template. When I do sbt run I select a class with main and it runs. But when I pass the class with sbt "runMain com.mitzit.WordCount" it fails. How can I pass the class with main that I want to run from the command line? I don't want to edit build.sbt
Steps to reproduce
get project:
sbt new tillrohrmann/flink-project.g8 \
--name=sbt-flink-template \
--organization=com.mitzit \
--version=0.1 \
--flink_version=1.7.0 \
--scala=2.12.11
This works
run
sbt run
Multiple main classes detected, select one to run:
[1] com.mitzit.Job
[2] com.mitzit.SocketTextStreamWordCount
[3] com.mitzit.WordCount
Enter number: 3
[success] Total time: 395 s, completed Apr 22, 2020 4:24:22 PM
This Fails
sbt "runMain com.mitzit.WordCount"
[error] Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/common/typeinfo/TypeInformation
[error] at com.mitzit.WordCount.main(WordCount.scala)
How can I run a specific main without having to select it each time?
The issue is that in the root project part of the Flink libraries are classified as provided
To overcome this issue this template project tillrohrmann/flink-project.g8 is providing an utility sub-project mainRunner that simply edit the dependency configuration, removing the provided classifier to enable running it from IntelliJ (or sbt as you are asking)
you can simply run
sbt "mainRunner/runMain com.mitzit.WordCount"
I currently have a problem with recompile on code change with sbt.
I was following the sbt reference 'sbt by example'
I installed sbt 1.2.8 and followed the instructions:
Create a minimum sbt build
$ mkdir foo-build
$ cd foo-build
$ touch build.sbt
Start sbt shell
$ sbt
[info] Loading global plugins from C:\Users\hce\.sbt\1.0\plugins
[info] Loading project definition from E:\learn\Scala\demo\foo-build\project
[info] Loading settings for project foo-build from build.sbt ...
[info] Set current project to foo-build (in build file:/E:/learn/Scala/demo/foo-build/)
[info] sbt server started at local:sbt-server-57c501e502d72a00d890
Recompile on code change (Note the ~ prefix before the compile command)
sbt:foo-build> ~compile
[success] Total time: 0 s, completed Jul 6, 2019 12:01:24 PM
1. Waiting for source changes in project foo-build... (press enter to interrupt)
Create a source file
Leave the previous command running. From a different shell or in your file manager create in the project directory the following nested directories: src/main/scala/example. Then, create Hello.scala in the example directory using your favorite editor as follows:
package example
object Hello extends App {
println("Hello")
}
This new file should be picked up by the running command. But it is not working on my system.
Expected Behaviour:
[info] Compiling 1 Scala source to /tmp/foo-build/target/scala-2.12/classes ...
[info] Done compiling.
[success] Total time: 2 s, completed May 6, 2018 3:53:42 PM
2. Waiting for source changes... (press enter to interrupt)
Here are some Information about my environment
$ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
$ sbt sbtVersion
[info] Loading global plugins from C:\Users\hce\.sbt\1.0\plugins
[info] Loading project definition from E:\learn\Scala\demo\foo-build\project
[info] Loading settings for project foo-build from build.sbt ...
[info] Set current project to foo-build (in build file:/E:/learn/Scala/demo/foo-build/)
[info] 1.2.8
$ systeminfo.exe | grep '^OS'
OS Name: Microsoft Windows 10 Enterprise LTSC
OS Version: 10.0.17763 N/A Build 17763
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
What I already tried:
reinstall sbt
try it with windows commad line
try it mingw64 bash
What am I missing to run the sbt ~compile command correctly?
I found the answer.
The instruction contains an error.
We are supposed to put the src/main/scala/example directory in the project directory.
From a different shell or in your file manager create in the project directory the following nested directories: src/main/scala/example.
But this leads to the problem described. foo-build/project/ is for build definition code.
If I put the src/main/scala/example directory in the foo-build directory it is working.
I should have executed the run command beforehand, which gives the 'No main class detected' error. Which in turn helped to discover, that the directory structure was incorrect by reading the following stackoverflow question: how to set main class in sbt project .
My mistake. Sorry for bothering you.
This question already has an answer here:
How to pass command line args to program in SBT 0.13.1?
(1 answer)
Closed 5 years ago.
I want to refine sbt assembly/package operation by combine two step to one.
The two step is:
$ sbt
> project XXX
....
> assembly
Ctrl + c to exit
Besides, assembly is a task form fat jar sbt plugin.
I have attempt with sbt project analysis assembly but not works.A error encounter:
[error] Not a valid command: analysis (similar: alias)
[error] Not a valid key: analysis (similar: readAnalysis, mainClass, less)
[error] analysis
[error] ^
How to achieve this?Thanks
Within the sbt shell, use ; to chain commands:
;project XXX; assembly
Calling from the command line, enclose individual commands with quotes:
sbt "project XXX" assembly
or enclose a whole chain in quotes:
sbt ";project XXX; assembly"
To call a task in subproject XXX from the context of another project in the shell:
XXX/assembly