How to use jar file within Scala app

471 views
Skip to first unread message

mkaz

unread,
Jul 14, 2010, 3:00:39 PM7/14/10
to play-framework
I've built a jar for scala-redis which works for connection scala to
redis.
Where do I put this jar so I can import and use within the
application.

I've tried putting the jar in the lib/ directory and then tried
def test() = {
import com.redis._
val r = new Redis("localhost", 6739)
val bob = r.get("bob")
<h1>My Test: {bob}</h1>
}

The import surprising does not fail, but then trying the Redis
constructor gives type not found.
This same code works on the scala command-line if I do a classpath
load of the same jar

Do I need to specify the jar in a config somewhere, or will it auto-
load?

Guillaume Bort

unread,
Jul 15, 2010, 9:37:14 AM7/15/10
to play-fr...@googlegroups.com
Hum it should work. There is nothing to do. Try the 'play classpath'
to check that the generated classpath is ok.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

mkaz

unread,
Jul 15, 2010, 10:55:28 AM7/15/10
to play-framework
Hi Guillaume,

When I run "play classpath" the jar is there, it is the third item.
I tested with another jar (that I did not build myself) and that did
work.
So it might be with the jar I created, though it looks right. I'll
tinker some more.

In a side note, I just found the ability to run Jobs, its great! I was
writing a separate daemon service and doing all sorts of copying to
build it. The jobs made that so much easier.
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> write guillaume.b...@gmail.com

Matt Hildebrand

unread,
Jul 15, 2010, 11:42:52 AM7/15/10
to play-fr...@googlegroups.com
Hello Marcus,

When I run "play classpath" the jar is there, it is the third item.
I tested with another jar (that I did not build myself) and that did
work.
So it might be with the jar I created, though it looks right. I'll
tinker some more.

This is just a guess, but it may be a version mismatch problem.  In general, the Scala compiler you're using to build your JAR and the Scala compiler that's embedded within the Play Scala module must be the same version.  One version of the Scala compiler frequently cannot use bytecode produced by a different version of the Scala compiler; even between different release candidates for Scala 2.8.0 there are incompatibilities.

Fortunately, Scala 2.8.0 was just released yesterday, and the Scala development team has committed to maintaining binary compatibility from 2.8.0 onwards, so such version mismatch hassles will disappear as everyone migrates to the new release.

Hope this helps...

-Matt

mkaz

unread,
Jul 15, 2010, 12:25:10 PM7/15/10
to play-framework
Bingo, that was it. Thanks Matt!

I switched my build script to reference the scala-compiler and scala-
library that is within the play modules and it is now all working.

The other jar I tested out was a Java jar, which wouldn't have that
compatibility issue.
Thanks again!
Reply all
Reply to author
Forward
0 new messages