How can I send SMS from PC to mobile in scala? - scala

I am working on a live project involving technologies like Scala, Akka and Slick. I have to implement the SMS functionality. After googling I didn't get a single example using Scala, but I got a few using Java and some comments saying that Simplewire is best to implement this functionality. But I am not able to find the library dependencies for any of them. Help me to resolve and implement this simplewire example using Scala.
I tried to start like this,
import com.simplewire.sms._;
object SMSHelper {
def sendSMS = {
val sms = new SMS() // SMS() is not resolving
}
// ...
}

From the sbt documentation:
Unmanaged dependencies work like this: add jars to lib and they will
be placed on the project classpath. Not much else to it!
Download the JAR file from here and simply copy it into the lib folder located at the root of your SBT project then sbt compile and it should work.
If you want to place your libraries in another folder (for instance custom_lib), add this line to your build.sbt file :
unmanagedBase := baseDirectory.value / "custom_lib"

Related

How do I execute Scrooge from commandline?

I was able to include scrooge in my SBT project (the scrooge-sbt-plugin in my plugins.sbt as well as the library dependencies in my build.sbt), but I haven't been able to figure out how to execute scrooge from the commandline as listed here http://twitter.github.io/scrooge/CommandLine.html.
A bit late to the party.
#partycoder was indeed right, however a bit more may help those
who like myself aren't too sure.
Assuming your *.thrift files are located in src/main/thrift simply running sbt scrooge-gen will pick up the files and deposit them in target/src_managed/.
If your *.thrift files are not located in src/main/thrift and perhaps in src/main/resources/thrift, you can setscroogeThriftSourceFolder in you build.sbt using this example:
scroogeThriftSourceFolder in Compile <<= baseDirectory {
base => base / "src/main/resources/thrift/"
}
This setting and others can be found here.

How do I use shared configurations across SBT (Play) multi-projects?

I have several SBT 0.13 / Play 2.2 projects (websites). They are all multi-module as they share some common functionality. This makes their project configuration files both complex and almost identical, but not quite.
I would like to be able to share as much as possible of these configuration files across the projects (frequent play updates makes keeping 5+ websites up to date a royal pain, not to mention all the almost-identical-but-evolving dependency lists across the projects).
build.properties and plugins.sbt are identical across projects and can be overwritten by a simple script. Great.
Build.scala is trickier - I would like to introduce a shared base class like so:
abstract class MyBuildBase extends Build { ... }
that in Build.scala do:
object ApplicationBuild extends MyBuildBuild { ... }
In order for this to make any sense at all, MyBuildBase.scala needs to be shared across projects. This can be done with svn:external, which operates on directories. Which means I need to somehow make this shared directory accessible when Build.scala is compiled (otherwise sbt complains loudly).
Reading http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Classpaths.html and http://www.scala-sbt.org/0.13.0/docs/Getting-Started/Full-Def.html it seems like this should be possible.
However, it is exceptionally unclear to me what to actually put in the project/project/Build.scala file to actually achieve this - I can't find an example of "an sbt build file that's intended to build an sbt build file and include some extra source files in the build".
Any suggestions?
What you probably want to do is create a plugin, or shared library.
You can make an sbt project with a build like follows:
build.sbt
sbtPlugin := true
organization := "you"
name := "common-build"
version := "1.0"
Then create in src/main/scala your abstract class "MyBuildBase". Release this project as an sbt plugin.
Then in your other projects, you can use this as a library/plugin. In project/plugins.sbt add:
addSbtPlugin("you" % "common-build" % "1.0")
And this will resolve your common build library when building your build.
If you need more information, look up more about sbt plugins and ignore the part about making something that extends a Plugin. Plugins are just libraries versioned with sbt's version number and your own. You should be able to put whatever code you want in there to share between builds.
Note: in 2016, Build.scala is deprecated for Build.sbt.
Here is the new (Dec. 2016) multi-module with App Scala sbt template by Michael Lewis.
Usage
sbt new lewismj/sbt-template.g8
You can then run:
sbt compile
sbt publish-local
sbt assembly
It is based on Scala SBT template (Library)
This giter8 template will write SBT build files for a Scala library.

Compile scala files from a sbt plugin

I am developing a sbt plugin. In this plugin I generate some new scala sources packaged in a sbt project. Then I need to compile these new files programaticaly so that I could add the generated class in my classLoader.
I do not find any way to compile programaticaly sources from a given sbt project path (and eventually from a classLoader) in the sbt API, something as simple as the sbt command (sbt compile) line would be very convenient, something like:
XXX.compile(path/to/sbt/project)
Thanks
I suggest you have a look at sbt-boilerplate which is an sbt plugin that generates code, works well and is really simple.
Here's a link to the file that you probably want to take a look at

UnmanagedJars in sbt plugin

I am creating a sbt plugin. One of its features is to display a dependency graph of a given scala project (the one invoking this plugin). To do so, I use scalafx, which is still depending on a javafx jar. So I need to add in my plugin build.sbt the following command:
unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_ORACLE") + "/jre/lib/jfxrt.jar"))
It compiles and works well. But not when I use it as a plugin from another sbt project (with the addSbtPlugin command in the project/plugins.sbt). When I invoke the plugin, I get the following error:
java.lang.NoClassDefFoundError: javafx/event/EventTarget
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:787)
The javafx classes are not found in the classLoader. I tried the assembly plugin - but it is not packaged yet for scala 2.10 that I use.
Does anyone know how I can render my javafx jar available at runtime when it is invoked by my plugin ?
Thanks
I'm facing the same problem (with a different .jar file) and I found a workaround. I know it's not what we are looking for (A way for the plugin to automatically have that .jar file in its classpath when being used by another project), but it works.
Add the line
unmanagedJars in Compile += {
Attributed.blank(file(System.getenv("JAVA_ORACLE") + "/jre/lib/jfxrt.jar"))
}
to the file yourMainProject/project/plugin.sbt. The same file where you placed the line addSbtPlugin(...) with you plugin.
Hope it works. If you get to find a way to solve it in the nice way, let me know.
Also check this answer, it may be helpful How to generate sources in an sbt plugin?

Tell SBT to collect all my dependencies together

When building a web application SBT is able to collect all my jar dependencies into the WAR file.
Is this possible to have SBT put all the jars I depend on in my non-web application into a directory so I can easily put them onto my class path when running the app?
Yes, you can put something like this in your project definition class:
val libraryJarPath = outputPath / "lib"
def collectJarsTask = {
val jars = mainDependencies.libraries +++ mainDependencies.scalaJars
FileUtilities.copyFlat(jars.get, libraryJarPath, log)
}
lazy val collectJars = task { collectJarsTask; None } dependsOn(compile)
and run the task via collect-jars in your SBT console. This will copy the scala-library.jar and the jars used for compilation in a directory called lib in the same directory as your classes directory.
In my honest opinion don't bother with sbt-assembly. I'm new with scala but I'm quite technology agnostic, I handle a lot of technologies and sbt-assembly it's not clean. Just an opinion.
I would recommend you sbt-pack. Awesome piece of work. It will give you the runnable scripts as well, for both.. WINDOWS AND LINUX.
https://github.com/xerial/sbt-pack
You can use sbt-assembly to make a fat jar with all dependencies: https://github.com/sbt/sbt-assembly