Friday, September 11, 2015

Newbie Scala build intro

1. Install Java 8
If you forget to do this you will probably see all sorts of unexplained bugs.

2. Download the Intellij IDE
https://www.jetbrains.com/idea/download/

or the scala-ide based on Eclipse
http://scala-ide.org

Check out the plugins for Intellij
https://www.jetbrains.com/idea/plugins/

Install the JetBrains official Scala plugin

3. Create a directory structure (optionally first create your revision control repo structure and cd to it e.g. git...) using this handy script which has some optional sections commented out.
http://alvinalexander.com/sbtmkdirs

http://grosdim.blogspot.com/2013/01/quick-sbt-tutorial.html

http://www.scala-sbt.org/0.13/tutorial/index.html

4. Optionally install sbteclipse so you can generate an eclipse project if you use scala-ide
https://github.com/typesafehub/sbteclipse/
https://github.com/typesafehub/sbteclipse/wiki/Installing-sbteclipse
emacs ~/.sbt/0.13/plugins/plugins.sbt
(~/.sbt/0.13/plugins probably does not exist and either use emacs to make it or mkdir ~/.sbt/0.13/plugins and then use your favorite editor)

add
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
"After adding the sbteclipse plugin like this, you should either start sbt or, if it was already started, reload the current session by executing the reload command. If everything worked, you should have the new command eclipse available. Now read on about how to use sbteclipse."

$ sbt
Use of ~/.sbtconfig is deprecated, please migrate global settings to /usr/local/etc/sbtopts
[info] Loading global plugins from /Users/depappas/.sbt/0.13/plugins
[info] Updating {file:/Users/depappas/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] downloading https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.10/sbt_0.13/2.5.0/jars/sbteclipse-plugin.jar ...
[info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-plugin;2.5.0!sbteclipse-plugin.jar (1808ms)
[info] downloading https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-core/scala_2.10/sbt_0.13/2.5.0/jars/sbteclipse-core.jar ...
[info] [SUCCESSFUL ] com.typesafe.sbteclipse#sbteclipse-core;2.5.0!sbteclipse-core.jar (2512ms)
[info] Done updating.
[info] Set current project to html_product_website_generator (in build file:/Users/depappas/scala_test/html_product_website_generator/)
> eclipse
[info] About to create Eclipse project files for your project(s).
[info] Updating {file:/Users/depappas/scala_test/html_product_website_generator/}html_product_website_generator...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Successfully created Eclipse project files for project(s):
[info] html_product_website_generator


5. Configure scala-ide
http://scala-ide.org/docs/user/gettingstarted.html


5. Open up the set project in Intellij
File->Open
select the project

Or in Eclipse

Once you have installed and generated the Eclipse project files using one of the above plug-ins, start Eclipse. Use File  Import  General/Existing Project into Workspace. Select the directory containing your project as root directory, select the project and hit Finish. And Voila.

6. If you want to use scala.xml and get compile errors try this:

Add this line to the build.sbt file

libraryDependencies += "org.scala-lang.modules" % "scala-xml_2.11" % "1.0.5"                                                                                    
$ sbt
> update
> eclipse
Go to Eclipse and refresh the project
The compile errors in Eclipse should be gone.
If you get this error:
  UNRESOLVED DEPENDENCIES         ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-lang#scala-library;2.11.7 : not found

Then find the right scala.xml version:


Lets find the right version of the scala.xml to add to the build.sb file.


Now lets add it to the build.sbt file.



Lets check in the cache dir:  ~/.ivy2/cache 
for the missing libs





Thursday, September 10, 2015

Upgrading to the Java 8 SDK on a Mac

Things seem to be getting simpler...

Download and install the dmg from Oracle

  • http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


Read the post installation docs

  • http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#CHDBADCG


Update the system to use Java 8
$ /usr/libexec/java_home -v 1.8.0_60 --exec javac -version
javac 1.8.0_60

$ which java

/usr/bin/java

Friday, July 31, 2015

Using emacs to paste multiple lines into a rectangle-this does not seem to work in Eclipse block mode

Lets say you have several lines that you want to paste into a rectangle so that the lines are inserted into each block.

case ACCESSORIES           : { }    
case AVAILABILITY          : { } 
case BRANDLOGO             : { } 
case BRANDNAME             : { } 
case BRANDPARTNUMBER       : { } 
case BRANDPRODUCTPAGE      : { } 
case BRANDSUGGESTEDPRICE   : { } 
case BRANDSUPPORTPHONE     : { } 
case BRANDWEBSITE          : { } 


Copy the code to paste into the empty braces, 

Availability schema = SchemaRegistry.getSchemaByClass(Availability.class);
String schemaName = schema.getName();

return schemaName;

Now you want to paste in the following code into each set of braces.
This paste operation does not seem to work in Eclipse. However, in Emacs use insert rectangle (cantle x-r-t) to paste the lines into each set of braces. Use control-space and the arrow keys to select the rectangle inside of the braces. Then use control-Y or command-v on the Mac to paste the contents into the mini buffer and hit return. the multiple lines of text are pasted into each set of braces



case ACCESSORIES           : {
Accessories schema = SchemaRegistry.getSchemaByClass(Accessories.class);
String schemaName = schema.getName();
return schemaName;
 }    
case AVAILABILITY          : {
Accessories schema = SchemaRegistry.getSchemaByClass(Accessories.class);
String schemaName = schema.getName();
return schemaName;
 } 
case BRANDLOGO             : {
Accessories schema = SchemaRegistry.getSchemaByClass(Accessories.class);
String schemaName = schema.getName();
return schemaName;
 } 
case BRANDNAME             : {
Accessories schema = SchemaRegistry.getSchemaByClass(Accessories.class);
String schemaName = schema.getName();
return schemaName;
 } 
case BRANDPARTNUMBER       : {
Accessories schema = SchemaRegistry.getSchemaByClass(Accessories.class);
String schemaName = schema.getName();
return schemaName;
 } 
case BRANDPRODUCTPAGE      : {
Accessories schema = SchemaRegistry.getSchemaByClass(Accessories.class);
String schemaName = schema.getName();
return schemaName;
 } 
}