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
Related
How do I access Scala docs in IntelliJ? The other answers in SO are for earlier versions. I added the scala doc jar file, but still I am unable to link scala docs with IntelliJ.
I do get the Quick Documentation as shown:
But I want the complete doc as here
Also, clicking on the Actor hyperlink shows me this code, but not the API doc. There are the download and Attach sources link and I dont understand what they are.
What do you mean by "link scala docs"? You can get documentation for a symbol (class, method) by pressing Ctrl-Q (or menu View > Quick Documentation). This seems to work at least with sbt based projects, even if in Project Structure > Project Settings > Libraries > SBT: org.scala-lang:scala-library:2.12.1:jar there is only classes and sources, and no explicit pointer to javadocs (I guess IntelliJ might extract them directly from the sources).
Also, are you using the latest version of IntelliIJ and the Scala plugin? For me, if I create a global Scala SDK (which you don't actually need when you use sbt build projects), IntelliJ by default does not have javadocs checked, but sources, and again I think it will extract the documentation from the sources. This is how it looks here with IntelliJ IDEA 2016.3.1 and Scala plugin 2016.3.5:
I added this:
to make it work. From the +, choose Scala SDK, select the version that matches your project and then add it to the module of your choice.
I know there are Scala specific tools to create OSGi bundles, but I'm quite happy with bndtools, I just would like to write Scala alongside or instead of Java.
Assuming that bndtools and Scala IDE installed in eclipse (you find them the Eclipse Marketplace).
Create a new Bndtools OSGi project as you normally would (i.e. from the File menu, select New -> Bndtools OSGi Project)
Add the Scala nature to the project: Right click on the project in the Package Explorer view, and in the context menu select Configure → Add Scala Nature. (See http://scala-ide.org/docs/user/faq.html)
That's all for the eclipse side of things, you can now add Scala classes and everything will work the same way as it does with java.
To make sure things also work on the command line and on your CI Server some more steps are needed.
to the file build.gradle add the line:
apply plugin: 'scala'
to file gradle.properties add: scara.srcDirs=[projectDir/src]
UPDATE:
The above isn't quite enough, additional a build.bnd file has to be added to any submodule containing scala files. The following isn't elegant as it duplicates a dependency already in the bnd file, but so far the only solution I've found: https://github.com/fusepoolP3/p3-entry-resource/blob/0df0bc35311c8a361f95d8e72f91c5e0df929245/build.gradle
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
I get the following Eclipse error when browsing a binary scala jar dependency :
Source not found
The source attachment does not contain the source for the file Http.class
You can change the source attachment by clicking Change Attached Source below
The source attachment is a jar file containing the .scala source files, and clicking the button and re-navigating to the jar does nothing. Is there a way to get it to work?
Incidentally, this is a dependency brought in by using the SBT eclipse plugin, using the withSources() dependency
You should make sure to match your package structure with your directory structure as required in java.
Make sure that you have installed scala IDE for Eclipse Source Feature.And then you can
attach sources to scala-library in eclipse for scala projects
install scala IDE for Eclipse Source Feature
I am trying to use IntelliJ Idea Scala plugin, but it says it wants scala-library-src.jar, scala-swing-src.jar, scala-dbc-src.jar. Where can I download these files? I use Scala 2.8.
Get them from the Scala Maven repo at https://oss.sonatype.org/content/groups/scala-tools/.
In particular, https://oss.sonatype.org/content/groups/scala-tools/org/scala-lang/ has all the Scala library jars.
Go to http://scala-lang.org/files/archive/ and find the version you want that ends in .zip. Get that and extract it.
If you get the msi file then it doesn't install the src dir, but the zip does contain src.