Issue with importing Custom Scala Jar - eclipse

I have few Scala projects which uses some common functionalities.
So for better maintenance, I have create a common project P1 with all the common functionalities and created the jar.
Then I have added the jar as external dependency to my all other projects.
After importing the necessary classes from the jar, in my class, I see no error in eclipse.
But when I am trying to build the Jar for these other projects, it throws error saying : class/object that I am trying to import not found.
Surprisingly, when I am pointing the mouse to the functions that I am using from that external jar, it shows me the function signature accurately.
But somehow, the jar building is failing.
Any help?
I am using Eclipse Luna for Scala, Scala 2.11.8 in Windows 7 .

Related

Link to library for Scala parser combinators in Eclipse

I created an Eclipse project using parser combinators using Scala 2.10. Recently I upgraded the Scala IDE plugin in Eclipse to version 3.0.4, which includes Scala 2.11. This new version of Scala has removed the scala.util.parsing.combinator package from the core Scala library. As a consequence, my upgraded Eclipse project has a plethora of "not found" errors.
The Scala website has some instructions for adding Maven and SBT dependencies for parser combinators. However, I can't find any instructions on scala-lang.org or scala-ide.org for linking to parser combinators. The full download of Scala (http://www.scala-lang.org/download/) includes a JAR for parser combinators, but I can't find the source attachment JAR for debugging. The Scala Eclipse plugin lacks the parser library (even though it includes other spun-out libraries like Scala Swing). I don't want to use Maven or SBT.
What is the easiest way to add Scala parser combinators (including source attachment) to an Eclipse project?
The easiest way is to use Sbt or Maven. Otherwise you need to manually download the jar file and corresponding sources from here.
You can add the scala-parser-combinators.jar to your build path (Project Properties -> Java Build Path), and then go to Libraries, click on Add External Jar. Once you have the jar, navigate to Source Attachment under the jar name and double-click to attach sources.
Please take my example projects as a starting point. They are using sbt so you can import them into Eclipse.
The 1st is a relatively simple expression parser https://github.com/scala-szeged/top-calc-dsl
The 2nd is a complete example language interpreter in 200 lines handling nested if, while, int, bool, array and variables https://github.com/scala-szeged/hrank-while-language

Code not compiling (Eclipse Scala IDE)

If I create a new Scala project in the Eclipse Scala IDE, my code compiles and runs. However, when I import an existing project, my code doesn't compile (no class files are generated) and I get a NoClassDefFoundError in the console. Any ideas what could cause this? Do I need additional software?
As mentioned in comments, this is often the symptom of missing dependencies in your imported project, either jars or other projects (which should be imported and buildable in the IDE).

How to build a scala application that was created in eclipse scala plugin FROM THE CL

I have developed a scala application for the first time, but I have to deploy it with a "one-click" type script that can run and build the scala application from source WITHOUT ECLIPSE.
Since I'm completely new to scala I don't know how to tell it where all my source files are etc... to get it to build my app from the command line. I also have 2 3rd party .jar libraries that I need to tell the scala compiler to link to...
Any documentation on this? Or example command lines? My project hierarchy is:
src/packagename: contains all .scala
bin/packagename: contains all.class files
libs/ -> contains 2 .jar files I will need to import somehow
I'm working on debian linux
EDIT: I found this ability to export in eclipse so I created a .java file and called my main scala object from it. Then I exported as a runnable jar. However, when I go to run the new runnable jar "sudo java runnable.jar" it says "class not found exception: runnable.jar"
You should take a look at https://github.com/harrah/xsbt/wiki which is the common way to build a Scala project. Run through the tutorial in the wiki to learn how you should organise your directory structure, so that everything may run fine.
If you want to combine it with eclipse, checkout this plugin: https://github.com/typesafehub/sbteclipse

The war file generated by maven does not contain scala libraries

I have got a maven project created which contains a JAX-RS web service written using Scala. However, I found that the war file generated does not contain any scala libraries.
After I deployed it to Jboss and run, errors show that Scala libraries could not be found.
I assume maven will automatically pack any relevant libraries to WEB-INF\lib but scala is not the case.
Is there any specific configurations I need to add in order for the scala library to be packed?
Or shall I place scala to anywhere local to the JBoss AS?
Many thanks!
Update:
I actually have found out why the scala libraries are not included in the war. It was because I defined a "provided" scope for the scala dependency.
However, if I include scala in the war, the deployment will fail with an illegal argument exception.
I brief remember I used to config jboss to use local copy of scala library, but I forgot how to do this.
Does anyone have any idea about this?
Many thanks

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.