PlayFramework - Creating Scala seed template with sbt - scala

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

Related

Сan't run examples. Couldn't find artemis.home error

I get an error when I want to run any example through mvn verify
[ERROR] ********************************************************************************************
[ERROR] Could not locate suitable Artemis.home on either D:\Documents\IdeaProjects\activemq-artemis\examples\features\standard\security\..\..\..\.. or D:\Documents\IdeaProjects\activemq-artemis\examples\features\standard\security\..
\..\..\..\artemis-distribution\target\apache-artemis-2.18.0-SNAPSHOT-bin\apache-artemis-2.18.0-SNAPSHOT
[ERROR] Use the binary distribution or build the distribution before running the examples
[ERROR] ********************************************************************************************
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.087 s
[INFO] Finished at: 2021-02-26T22:03:39+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.activemq:artemis-maven-plugin:2.18.0-SNAPSHOT:create (create) on project security: Couldn't find artemis.home -> [Help 1]
I tried to specify the path to the directory with artemis at startup, but it does not help mvn verify -Dartemis.home="D:\Documents\apache-artemis-2.17.0"
How to fix this error?
It appears you're running the example directly from the project source since it reports 2.18.0-SNAPSHOT. If that's the case then you should do what the ERROR message indicates:
Use the binary distribution or build the distribution before running the examples
You can get a snapshot binary distribution here or you can build the distribution from the source using mvn install -Prelease -DskipTests.
If you must point the example at a different home directory you can do so using the activemq.basedir system property, e.g.:
mvn verify -Dactivemq.basedir="D:\Documents\apache-artemis-2.17.0"
Or you can change the activemq.basedir property defined in the example's pom.xml.

sbt run only work if I select class not if I pass it as argument

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"

Why does the sbt ~compile command do not recompile on code change?

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.

How can I run akka-sample-distributed-data-scala demo

The code is from this repository: https://github.com/akka/akka-samples/tree/2.5/akka-sample-distributed-data-scala
➜ akka-sample-distributed-data-scala git:(2.5) ✗ sbt run
[info] Loading project definition from /Volumes/Macintosh HD/github/akka-samples/akka-sample-distributed-data-scala/project
[info] Set current project to akka-sample-distributed-data-scala (in build file:/Volumes/Macintosh%20HD/github/akka-samples/akka-sample-distributed-data-scala/)
[info] Updating {file:/Volumes/Macintosh%20HD/github/akka-samples/akka-sample-distributed-data-scala/}akka-sample-distributed-data-scala...
[info] Resolving jline#jline;2.14.5 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Volumes/Macintosh HD/github/akka-samples/akka-sample-distributed-data-scala/target/scala-2.12/classes...java.lang.RuntimeException: No main class detected.
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) No main class detected.
[error] Total time: 6 s, completed 2018-5-27 10:07:14
It seems I run in a wrong way, how can I run it?
So I think it's an example that you need to add to your project. So you can't run it because as console tell you "No main class detected". This example contains code and you can go through it and learn.
So if you want to run it, you need to create an object with the main method and inside main, you can use everything from another part of the project.
Here you can see that everything is okay with code because compilation finished correctly.
Here you can find more information about this library:
https://doc.akka.io/docs/akka/2.5/distributed-data.html?language=scala

How to run Lift's 'Ecommerce example' app

I'm new to Scala and Lift and SBT. I've cloned Ecommerce example from Lift's sample applications.
Now I want to simply run the application.
Documentation says, that container:start should start the app. But I'm getting error:
> container:start
[error] No action named 'container:start' exists.
[info] Execute 'help' for a list of commands or 'actions' for a list of available project actions and methods.
[info]
[info] Total time: 0 s, completed 25.05.2013 16:47:05
I guess that maybe it's because version difference.
[info] using LiftProject with sbt 0.7.5 and Scala 2.7.7
How can I start this application ?
And if it's caused by version difference is it possible to upgrade the application to latest sbt and scala version ?
Update
I've tried to use jetty-start and received another error:
> jetty-start
[error] No action named 'jetty-start' exists.
[info] Execute 'help' for a list of commands or 'actions' for a list of available project actions and methods.
I've also found another similar command jetty-run from sbt help. When I run it I'm getting a huge number of compilation errors. It seems like my scala 2.9.2 cannot compile the code.
This project, as far as I see, uses the old SBT version. The old way to start the web application is:
./sbt
> jetty-start
if you want to reload the app on source change, use ~ jetty-start
Note that there's a far more up to date liftweb project example here: https://github.com/lift/lift_25_sbt
probably sbt did not download the requried jar files.
run the following command
> sbt
> update
now sbt should download the requried jar files
>jetty-run
now sbt should compile and run the web-app.