Run gatling project from an executable jar - scala

I have a small Gatling project which I would like to package through sbt and then run on different Linux/Windows machines with different JVM parameters. I tried already the sbt package command but that didn't work out. Anyone has done something similar before?

Package doesn't include the dependencies of your project.
You need something like sbt-assembly, sbt-pack or sbt-native-packager.
Then you can start your tests from within a main method (depending on the type of your package, e.g. java -jar fat-jar-name.jar).

Related

how to keep jar dependancy while checking in code

I have a scala project built with dependancy on a locally built jar file (java code). Once I need to check in my scala code into a different environment for building and deployment, what's the best way to keep my jar file in the dependancy?
I know that if I use the sbt dependancy from online modules, I don't need to worry, it will download the version and build, but what if I want to use my own jar file for this purpose?
This is in OSX, and code will be checked into linux machines, I am using intellij and sbt to manage my scala project. I also used intellij to build my external java lib into jar file and added dependancy of this specific path.
I hope there should be some generic solution, but I am new in JAVA and SBT
I got it figured out. Add the jar files under the lib directory right under the project will solve the problem. SBT will pick it up automatically and you can certainly check in the jar files like source code.

scala and akka on linux: compiling and executing

I'm trying to run a scala/akka based program on a linux cluster machine. I was following the tutorial link (this was the only example I could find):
http://doc.akka.io/docs/akka/2.0/intro/getting-started-first-scala.html
It says to use the command to obtain the akka library:
git clone git://github.com/akka/akka.git
But it doesn't have any jars files inside it as per the tutorial.
I'm not able to get a basic akka-scala-sbt combo working on linux. So any help on this is much appreciated. I'm not aware (not able to find any clear source) of the commands needed to compile/execute with and without using SBT.
Java version: "1.8.0_31"
Scala version: "2.11.5"
Akka: I'm not sure, I did git clone, believe its the latest
SBT: 0.13.9
Java,Scala are already installed on the cluster, I had to just use module load.
You can start with this simple example: https://github.com/izmailoff/SmallAkkaProjectExample. It will help you to understand how to compile and run a project.
Usually the steps are:
Start SBT
Compile code
Run it from SBT
or:
Start SBT
Compile executable JAR
Run the JAR from command line
If you want a more advanced example take a look at: https://github.com/izmailoff/remote-akka-server-template
In either of these projects you don't need to download any libraries/JARs. SBT will download everything you need automatically.
In short, you need to understand how to build projects with SBT and how to run them - not related to Akka. Separately from that you need to know how Akka runs, i.e. ActorSystem, kernel, etc.

multi-project sbt build - package all dependent JARs in one directory

I have a multi-project SBT build: some projects are dependent on each other, some are dependent on third-party JARs, and there's a "main" project which depends on everything .
When I sbt package it, I get one JAR in each target/ directory.
What I want to achieve is getting all relevant JARs (mine and external) is one directory. Very similar to the way you package a WAR with Maven.
(And to clarify - I'm not interested in an assembled "FAT JAR" that contains all the dependencies in a single file. Just one directory with all JARs in it)
Im not 100% sure about the suprobject dependencies but I think SBT native packager should help you do something like that, and will also provide a start-script for windows and unixes:
http://www.scala-sbt.org/sbt-native-packager/GettingStartedApplications/MyFirstProject.html
I would recommend sbt-pack for creating self-contained JARs:
https://github.com/xerial/sbt-pack
I use it and haven't seen a glitch so far.
It also generates both OS X/Linux as well as Windows .bat entry scripts for the main classes/objects you choose.

Call sbt externally

I am designing a tool, that takes an sbt project path as a parameter. I would like to be able to build that given project on the fly, and be able to get its classpath.
I previously designed my tool as a sbt plugin to achieve this but it is not flexible enough for my purpose: I don't want to have to parameter anything in the sbt config files of the project I am studying.
I would like to use sbt externally, construct a project (from a sbt directory path) and compile it externally in my scala code without invoking sbt in a console. This is a reproduction in code of what happens when "sbt" is typed in a given directory in the console. Is there a straightforward way to achieve this?
I think you need to look at SBT jar file and source code. Find the "Main" class and call it programmatically. The code is here: https://github.com/sbt/sbt. The main class is: xsbt.boot.Boot. I got it from sbt jar file by unzipping it and looking at META-INF/MANIFEST.MF. So you can see how SBT passes command line arguments to it and take it from there. Here is the Boot class just in case: https://github.com/sbt/sbt/blob/0.13/launch/src/main/scala/xsbt/boot/Boot.scala. Have fun! :)
p.s. in your code just call Boot.main(<your sbt commands>).
I have a vaguely similar requirement. I produce a command-line tool as one of the deliverables from my project. The script launches the Scala runtime itself and naturally needs the effective class-path for the project's dependencies. To get that in an external form, I use the SBT-Start-Script plug-in. While that plug-in does produce an actual launcher, I need to do more than it provides, so I just use it to externalize the project's (current) class-path, which I extract into a shell array initialization in a separate source file that may be source-ed by the main launcher script.

Packaging and Deploying Scala Applications

What is the simplest way to package a Scala application for use on a desktop PC? I'm guessing that would be in the form of a jar file.
At the moment I'm using SBT to compile and run programs
I'd be interested in solutions for machines that have Scala installed (and the library in their classpath), as well as those that only have Java.
The simplest (and the most consistent) way to package a Scala application, is packaging into a JAR (like you do with normal Java applications). As long as JAR consists of standard compiled Java classes, you may run "Scala" JAR, even if you don't have Scala runtime at the box (all you need is a Java Runtime and scala-lang.jar on the classpath). You may specify the main class (gateway to functionalities of your application) in the manifast
Main-Class: mypackage.MyClass
so that you'll be able to call it only passing a JAR name to java.exe.
java -jar myjar.jar
You may specify the main class in SBT project definition.
http://www.scala-sbt.org/sbt-native-packager/index.html
The plugin allows you to package in a variety of formats(zip, tar, deb, dmg, msi, etc) and in different archtypes.