[scala-ide-user] Creating a .jar file including scala-library.jar

2,009 views
Skip to first unread message

Alexey Romanov

unread,
May 25, 2010, 8:38:04 AM5/25/10
to Scala IDE User
Running File > Export > JAR File on a Scala project does produce
a .jar file, but it doesn't include scala-library.jar. So when I try
to reference this file in a Java project, I get this error:

> The type scala.ScalaObject cannot be resolved. It is indirectly referenced from required .class files

File > Export > Runnable JAR File lets the user include required
libraries into the .jar, but you need to select a Java application to
launch, which my project (a Scala library) doesn't have.

So it would be quite nice if there was a simple way to create a .jar
which includes the Scala Library. Or maybe there already is, and I
missed it?

Miles Sabin

unread,
May 25, 2010, 8:57:58 AM5/25/10
to scala-i...@googlegroups.com
Interesting.

I can see that there could be uses for creating a runnable jar file
which included the Scala runtime (or a minimal subset of it).

But I'm not convinced that it makes sense to do this for a library
which is itself intended to be linked to an application: suppose you
had two or more of these, all linked into a single app ... you'd end
up with multiple copies of the Scala runtime (possibly different
versions) on the classpath ... not a good thing.

Why is it a problem to say that applications wishing to link with your
library should also link with the corresponding Scala runtime?

Cheers,


Miles

--
Miles Sabin
tel: +44 7813 944 528
gtalk: mi...@milessabin.com
skype: milessabin
http://www.chuusai.com/
http://twitter.com/milessabin

Kevin Wright

unread,
May 25, 2010, 9:08:05 AM5/25/10
to scala-i...@googlegroups.com
If you seriously have a good use-case for this

(i.e. multiple deployed apps all using a different snapshot version of scala, or an embedded environment such as android)

Then you probably want to be looking at something like proguard.
--
Kevin Wright

mail/google talk: kev.lee...@googlemail.com
wave: kev.lee...@googlewave.com
skype: kev.lee.wright
twitter: @thecoda

Alexey Romanov

unread,
May 25, 2010, 9:31:07 AM5/25/10
to scala-i...@googlegroups.com
On Tue, May 25, 2010 at 4:57 PM, Miles Sabin <mi...@milessabin.com> wrote:
> On Tue, May 25, 2010 at 1:38 PM, Alexey Romanov
> <alexey.v...@gmail.com> wrote:
>> Running File > Export > JAR File on a Scala project does produce
>> a .jar file, but it doesn't include scala-library.jar. So when I try
>> to reference this file in a Java project, I get this error:
>>
>>> The type scala.ScalaObject cannot be resolved. It is indirectly referenced from required .class files
>>
>> File > Export > Runnable JAR File lets the user include required
>> libraries into the .jar, but you need to select a Java application to
>> launch, which my project (a Scala library) doesn't have.
>>
>> So it would be quite nice if there was a simple way to create a .jar
>> which includes the Scala Library. Or maybe there already is, and I
>> missed it?
>
> Interesting.
>
> I can see that there could be uses for creating a runnable jar file
> which included the Scala runtime (or a minimal subset of it).
>
> But I'm not convinced that it makes sense to do this for a library
> which is itself intended to be linked to an application: suppose you
> had two or more of these, all linked into a single app ... you'd end
> up with multiple copies of the Scala runtime (possibly different
> versions) on the classpath ... not a good thing.

A good point.

> Why is it a problem to say that applications wishing to link with your
> library should also link with the corresponding Scala runtime?

Probably not much of a problem.

We still need to solve this for Scala applications. It seems easiest
to make the "Runnable JAR File" export wizard know about "Scala
application" launch configurations.

Miles Sabin

unread,
May 25, 2010, 9:37:21 AM5/25/10
to scala-i...@googlegroups.com
On Tue, May 25, 2010 at 2:31 PM, Alexey Romanov
<alexey.v...@gmail.com> wrote:
> We still need to solve this for Scala applications. It seems easiest
> to make the "Runnable JAR File" export wizard know about "Scala
> application" launch configurations.

Yes, that's a good idea ... would you mind creating an enhancement
ticket for it in Assembla so that it doesn't get forgotten about.

Alexey Romanov

unread,
May 25, 2010, 10:35:44 AM5/25/10
to scala-i...@googlegroups.com

Luc Bourlier

unread,
Nov 27, 2012, 1:05:24 PM11/27/12
to scala-i...@googlegroups.com
Interesting question.

To run a Scala application, the more straight forward way is to install Scala on the system. It works about the same way as Java.

Just follow the step by step guide [1] to install it (the guide is targeting Windows users, but the idea is the same on all systems). Then use "scala" to launch your application [2] [3] locally.
When you want to distribute your application, you should create a jar file of the compiled data. It can be done on the command line using "jar" [4], sbt [5] or maven [6]. Or from Scala IDE, using File > Export > Java / Jar File [7].

And to answer your last question: yes, most Scala users already know what to do. Traditionally, users were using Scala from the command line first before using an IDE, so they already knew this. But it is changing, so it makes sense that we need to create some documentation.

Creating a Jar from inside Scala IDE is a feature which is not used a lot. Please file a ticket if it fails in some ways.

HTH,
Luc


On Tuesday, November 27, 2012 5:43:24 PM UTC+1, Mohamed Lrhazi wrote:
am newbie to all of scala, scala-ide and eclipse, and even Java really.

How do you deploy a HelloWorld scala application you just created using this IDE?

I can see that I could just ship my few lines long helloworld.scala... but what when the application is more than one file, like a bit more useful application?

I don't see anything about "deploying" in the documentation.... How do people do this? and why is this not in the FAQ? is it that scala users just already know what to do?

Thanks a lot,
Mohamed.

Mohamed Lrhazi

unread,
Nov 27, 2012, 9:23:43 PM11/27/12
to scala-i...@googlegroups.com
Thanks a lot Luc. "exporting to jar" and "runnable jar" sounds like the closest to "package my app, please".

It does not seem obvious at all to me right now, how to actually make eclipse do it for me, while in my HellowWorl scala project.... I'll read those links and try to figure it out.

It would be great if someone who knows how, could do and show how to do exactly that: Create a fresh HelloWorld scala project, then export it to a Runnable jar.

Thanks a lot,
Mohamed.
Reply all
Reply to author
Forward
0 new messages