Export usage error when doing example from sbt docs - scala

The sbt tutorial shows this example.
$ mkdir hello
$ cd hello
$ echo 'object Hi { def main(args: Array[String]) = println("Hi!") }' > hw.scala
$ sbt
...
> run
...
Hi!
However, when I try it, I get this:
$ mkdir hello
$ cd hello
$ echo 'object Hi { def main(args: Array[String]) = println("Hi!") }' > hw.scala
$ sbt
[info] Set current project to hello (in build file:/Users/coryklein/playground/hello/)
[error] export usage:
[error] export <tasks>+ Executes tasks and displays the equivalent command lines.
[error]
[error] export
[error]
My sbt version
$ sbt --version
sbt launcher version 0.13.6
Am I doing something wrong here?
Here is the output of sh -x sbt
+ '[' -f /Users/coryklein/.sbtconfig ']'
+ exec /usr/local/Cellar/sbt/0.13.6/libexec/sbt
[info] Set current project to hello (in build file:/Users/coryklein/playground/hello/)
[error] export usage:
[error] export <tasks>+ Executes tasks and displays the equivalent command lines.
[error]
[error] export
[error]
I installed sbt via brew install sbt.
$ ll `which sbt`
lrwxr-xr-x 1 coryklein admin 28B Oct 14 16:03 /usr/local/bin/sbt -> ../Cellar/sbt/0.13.6/bin/sbt
I'm trying to look through the source code to figure out what the problem is, but it's difficult when a working sbt is required to build sbt from source. :(

I was unable to figure out exactly why it failed to work, but I resolved it by doing the manual install like so:
brew remove sbt
wget https://dl.bintray.com/sbt/native-packages/sbt/0.13.6/sbt-0.13.6.tgz
extract sbt-0.13.6.tgz
mv sbt/bin/sbt-launch.jar ~/bin
echo 'SBT_OPTS="-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"\n
java $SBT_OPTS -jar `dirname $0`/sbt-launch.jar "$#"' > ~/bin/sbt
chmod u+x ~/bin/sbt

Related

Elastic Beanstalk failed to unzip source file with UTF-8 file name

I was trying to deploy a NextJS application to Elastic Beanstalk via eb deploy. But the source bundle failed to unzip during deployment as the source bundle contained some pre-built .next page which the file name is in UTF-8 encoding. The error is stated as below.
2022/xx/xx xx:xx:xx.xxxxxx [INFO] Executing instruction: StageApplication
2022/xx/xx xx:xx:xx.xxxxxx [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2022/01/31 04:56:44.300483 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2022/01/31 04:56:45.932820 [ERROR] An error occurred during execution of command [app-deploy] - [StageApplication]. Stop running the command. Error: Command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/ failed with error exit status 50. Stderr:error: cannot create /var/app/staging/.next/server/pages/\u6e2c\u8a66/\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66.html
File name too long
error: cannot create /var/app/staging/.next/server/pages/\u6e2c\u8a66/\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66\u6e2c\u8a66.json
File name too long
I was able to unzip the file with option -O UTF-8, is there any way I could add this flag to the eb deploy unzip process?
edit 1. I am working with the Platform 64bit Amazon Linux 2/5.4.9
Not sure if it is good practice, but I eventually added an ebextensions to overcome the original unzipping flow.
commands:
command backup original zip:
command: |
logger "backup zip" && cp /opt/elasticbeanstalk/deployment/app_source_bundle /tmp/app_source_bundle_bak &&
logger "rm existing zip .next folder" && zip -Ad /opt/elasticbeanstalk/deployment/app_source_bundle ".next/*"
cwd: /home/ec2-user
ignoreErrors: false
container_commands:
replace the original zip to staging:
command: |
logger "custom unzip" &&
unzip -O UTF-8 -q -o /tmp/app_source_bundle_bak -d /var/app/staging/
cwd: /home/ec2-user
ignoreErrors: false

How to properly run SpotBugs on a Scala project

I'm trying to get SpotBugs run on Scala project using the SpotBugs CLI.
I installed the CLI like this:
$ curl -L -o /tmp/spotbugs-4.0.3.tgz https://github.com/spotbugs/spotbugs/releases/download/4.0.3/spotbugs-4.0.3.tgz
$ gunzip -c /tmp/spotbugs-4.0.3.tgz | tar xvf - -C /tmp
Then I run it like this
$ time java -jar /tmp/spotbugs-4.0.3/lib/spotbugs.jar -textui -xml:withMessages -html -output target/scala-2.11/spotbugs-report.html vad/target/scala-2.11/projectx-SNAPSHOT-assembly.jar
^Cjava -jar /tmp/spotbugs-4.0.3/lib/spotbugs.jar -textui -xml:withMessages -htm 2462.79s user 135.67s system 130% cpu 33:16.98 total
You can notice that it took more than 30mn without even have finished, I had to halt it.
It obviously seems that SpotBugs is not running properly here, so what am I doing wrong here?

Run tests using docker compose in scala

Trying to execute integration tests using docker.
Below is the Dockerfile:
FROM openjdk:8u232
ARG SBT_VERSION=1.2.8
# Install sbt
RUN \
curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get install sbt && \
sbt sbtVersion
ENV WORK_DIR="/test"
USER root
COPY . ${WORK_DIR}/
RUN cd ${WORK_DIR}
RUN sbt clean it:test
Below is the docker-compose.yml:
version: '3.7'
services:
test:
build:
context: ../..
dockerfile: Dockerfile.test
restart: always
when I run docker-compose -f test.yaml up :
it gives me error:
Step 10/10 : RUN sbt clean it:test
---> Running in d9513c01439b
[warn] No sbt.version set in project/build.properties, base directory: /
[info] Set current project to root (in build file:/)
[success] Total time: 0 s, completed Jun 6, 2020 7:20:37 AM
[error] Expected ';'
[error] No such setting/task
[error] it:test
to check it i removed this line from docker file and built the image and exec into container and my tests ran fine.
The structure of my project is:
src
main
it
test
I tried executing the unit tests as well
but it gave me:
Step 10/10 : RUN sbt clean test
---> Running in c300fcf2bf53
[warn] No sbt.version set in project/build.properties, base directory: /
[info] Set current project to root (in build file:/)
[success] Total time: 0 s, completed Jun 6, 2020 7:19:13 AM
[success] Total time: 10 s, completed Jun 6, 2020 7:19:24 AM
Removing intermediate container c300fcf2bf53
---> c0215c62663d
Successfully built c0215c62663d
Successfully tagged it_it:latest
Creating it_it_1 ... done
Attaching to it_it_1
when i changed it to:
Step 10/10 : CMD sbt clean it:test
---> Running in 719b239fb7e4
Removing intermediate container 719b239fb7e4
---> f7adb19f2cb6
Successfully built f7adb19f2cb6
Successfully tagged it_it:latest
Creating it_it_1 ... done
Attaching to it_it_1
it_1 | [warn] No sbt.version set in project/build.properties, base directory: /
it_1 | [info] Set current project to root (in build file:/)
[success] Total time: 0 s, completed Jun 6, 2020 7:32:24 AM
[error] Expected ';'
it_1 | [error] No such setting/task
it_1 | [error] it:test
it_1 | [error]
How can i execute sbt it:test from dockerfile using compose?
If it was working inside the container then this must work:
ENTRYPOINT cd ${WORK_DIR} && \
sbt clean it:test
Change to next:
RUN cd ${WORK_DIR} && sbt clean it:test
Different RUN in dockerfile won't affect eachother.

java.lang.RuntimeException: No main class detected

I am trying to run Scala application using docker. I've created a sample project with the following structure.
build.sbt
name := "test"
version := "1.0"
scalaVersion := "2.12.2"
project/build.properties
sbt.version = 0.13.15
src/main/scala/HelloWorld.scala
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Now if I do sbt run, everything works fine and I have the lovely hello-world greeting.
$ sbt run
...
[info] Set current project to test (in build file:/Users/yuchen/Documents/test/)
[info] Running HelloWorld
Hello, world!
[success] Total time: 1 s, completed 22-May-2017 4:30:28 PM
I aded a Dockerfile:
FROM openjdk:8
ENV SCALA_VERSION 2.12.2
ENV SBT_VERSION 0.13.15
RUN touch /usr/lib/jvm/java-8-openjdk-amd64/release
RUN \
curl -fsL http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz | tar xfz - -C /root/ && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
RUN \
curl -L -o sbt-$SBT_VERSION.deb http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get install sbt && \
sbt sbtVersion
WORKDIR /root
CMD sbt run
They are all copied from https://hub.docker.com/r/hseeberger/scala-sbt/~/dockerfile/ and with the additional last line CMD sbt run.
And I tried running docker commands:
docker build -t test .
docker tag test test/test:1.0
docker run test/test:1.0
However, I keep getting this error:
[info] Set current project to root (in build file:/root/)
[info] Updating {file:/root/}root...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
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: 0 s, completed May 23, 2017 4:00:19 AM
What does it mean and how do I resolve this?
FYI: I am aware of http://www.scala-sbt.org/sbt-native-packager/formats/docker.html, but just want to try writing Dockerfile as I am learning this.
I don't really know sbt. But this appears that you are not copying the project into the image (there is no COPY or ADD in the Dockerfile).
Try doing something like:
FROM openjdk:8
ENV SCALA_VERSION 2.12.2
ENV SBT_VERSION 0.13.15
RUN touch /usr/lib/jvm/java-8-openjdk-amd64/release
RUN \
curl -fsL http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz | tar xfz - -C /root/ && \
echo >> /root/.bashrc && \
echo 'export PATH=~/scala-$SCALA_VERSION/bin:$PATH' >> /root/.bashrc
RUN \
curl -L -o sbt-$SBT_VERSION.deb http://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
dpkg -i sbt-$SBT_VERSION.deb && \
rm sbt-$SBT_VERSION.deb && \
apt-get update && \
apt-get install sbt && \
sbt sbtVersion
WORKDIR /myapp
CMD sbt run
COPY . /myapp
The addition here is just a COPY to copy all the code to /myapp and to changing the working directory to this folder as well. This would copy the build context to /myapp and then the WORKDIR should run sbt run from the same folder.

Apache Flink - org.apache.flink.client.program.ProgramInvocationException

I have created an application with Apache FLink 1.0.3 using Scala 2.11.7 and I want to test it locally (a single jvm). So I did the following as stated in the website:
./bin/start-local.sh
tail log/flink-*-jobmanager-*.log
And it starts just fine, I can see the web interface at localhost:8081.
Then, I tried to submit my application, but I get either an exception or a weird message. For example when I type either of the following commands:
./bin/flink run ./myApp.jar
./bin/flink run ./myApp.jar -c MyMain
./bin/flink run ./myApp.jar -c myMain.class
./bin/flink run ./myApp.jar -c myMain.scala
./bin/flink run ./myApp.jar -c my.package.myMain
./bin/flink run ./myApp.jar -c my.package.myMain.class
./bin/flink run ./myApp.jar -c my.package.myMain.scala
I get the following exception:
------------------------------------------------------------
The program finished with the following exception:
org.apache.flink.client.program.ProgramInvocationException: Neither a 'Main-Class', nor a 'program-class' entry was found in the jar file.
at org.apache.flink.client.program.PackagedProgram.getEntryPointClassNameFromJar(PackagedProgram.java:571)
at org.apache.flink.client.program.PackagedProgram.<init>(PackagedProgram.java:188)
at org.apache.flink.client.program.PackagedProgram.<init>(PackagedProgram.java:126)
at org.apache.flink.client.CliFrontend.buildProgram(CliFrontend.java:922)
at org.apache.flink.client.CliFrontend.run(CliFrontend.java:301)
at org.apache.flink.client.CliFrontend.parseParameters(CliFrontend.java:1192)
at org.apache.flink.client.CliFrontend.main(CliFrontend.java:1243)
And when I type either of the following commands:
./bin/flink run ./ -c myMain myApp.jar
./bin/flink run ./ -c myMain.class myApp.jar
./bin/flink run ./ -c myMain.scala myApp.jar
./bin/flink run ./ -c my.package.myMain myApp.jar
./bin/flink run ./ -c my.package.myMain.class myApp.jar
./bin/flink run ./ -c my.package.myMain.scala myApp.jar
I get the following error:
JAR file is not a file: .
Use the help option (-h or --help) to get help on the command.
The above commands do not work either with -c or --class. I use IntelliJ and I compiled the application using the Build Module from Dependencies option. What am I doing wrong?
The correct way to submit your JAR is:
bin/flink run -c my.package.myMain myApp.jar
You have to specify the arguments (like -c) before the JAR file. You got the error messages initially, because ./ was interpreted as the JAR and the rest of the line was ignored.
The -p argument is optional. Your last example works, because the argument order is correct and not because of the parallelism flag.
I figured out what was wrong. Flink needed to pass the parallelism degree as an argument, otherwise there was a program invocation exception. The command below worked for me:
./bin/flink run -p2 --class myMain myApp.jar
You have to mention the entry point class in your pom file.
see the following part in the pom file snippety
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xyz.myMain</mainClass>
</transformer>
</transformers>
Please check the below snippet.