How do I get Eclipse to see Scala sources in a jar? - eclipse

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

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 generating jar file from scala-io to include in eclipse

I am trying to use the library scala-io in my Eclipse environment, does anyone know how do I generate a jar file, or which folder to include in my eclipse so that I can have access to the scala-io library from my project ?
EDIT:
Q: How to incorporate an external library into scala IDE?
A: Two possibilities:
Leverage SBT to build your project; that is generating jar files and maintaining dependency
Including the generted jar files directory in the IDE, project -> Properties -> Java build paths.
hth.
EDIT #2:
I found this great plugin to generate all of your dependencies in one jar file sbt-assembly
http://jesseeichar.github.io/scala-io-doc/0.4.2/index.html#!/getting-started
shows how to start with sbt or maven or with prebuild jars provided by links.
You should try to get familiar with a build system like sbt. Its cumbersome to always manually add dependencies to eclipse, especially if you have dependency chains: scala-io needs scala-io-core and arm and file etc...

How to add external libraries in a Play2.1 scala project?

I want to use scala compiler library, and add it in Eclipse,
but when compiling the project again using eclipse, the library is deleted automatically by the compilation. What's wrong with that?
So the question is: if my play project want to use scala-compiler.jar, how to add that?
it does not work by using build path-> configure build path... in eclipse...
I also tried to put all the jar files to the lib/ folder, but when compiling again in the server using eclipse, it still gives out compiling errors because of not finding the jars.
Thanks in advance,
The most failure-proof way to add it is to use Play's configuration builder, not adding it explicitly with Eclipse. To build a correct Eclipse project, use:
$ play
[YourProject] $ eclipse
[info] About to create Eclipse project files for your project(s).
[info] Successfully created Eclipse project files for project(s):
Then you can import it from Eclipse under File/Import/General/Existing project… (see here for more).
Note that Play uses sbt, which is already configured to use some version of Scala.

scala sbt cache x eclipse build path

I'm added a dependence to my build.sbt (casbah). I did a sbt update, I did check my ~/.ivy2/cache directory and all jars are there. Do I have to add this ~/.ivy/cache directory to my Build Path and add the casbah as external Jar to my project? If no, probably no because I did try it, what should I do to be able to use this jar in my scala project?
EDIT
I found this instructions that helped me, but still a hack
Establish a simple project (general/project) named "IvyCache"
located at your ".ivy2/cache" folder just for library reference
purposes.
Establish a Scala project located at your "project" folder.
Add the following libraries to the Scala project by means of "Add
JARs" to the "Java Build Path":
3.a) All jars from "/IvyCashe/org.scala-tools.sbt" filterred by
"*2.9.1-0.11.2" or any other Scala/SBT version numbers.
3.b) A single sbinary_*.jar from "/IvyCache/org.scala-tools.sbinary".
3.c) A single test-interface*.jar from "/IvyCache/org.scala-
tools.testing".
Now your build files should compile within Eclipse.
The easiest way to manage this is to use the eclipse plugin for sbt. Then you can just say sbt eclipse on the command line any time you change the dependencies in build.sbt, and the Eclipse files will be automatically updated for you.
Doing it this way means that you will never have to manually configure your Eclipse build path. After all, sbt already knows how to construct the build path, so there's no reason you would have to do it manually.

Where can I download Scala source jars (scala-library-src.jar etc.)

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.