English 中文(简体)
Compile Scala 2.8.x code with Apache Buildr
原标题:
  • 时间:2009-12-30 02:59:23
  •  标签:
  • scala
  • buildr

I have been struggling to get Buildr to compile my Scala 2.8 project and I was hoping someone might have figured this out already.

Currently I have the standard HelloWorld application with a buildfile like the following:

ENV[ JAVA_HOME ] =  C:Program Files (x86)Javajdk1.6.0_17 
ENV[ SCALA_HOME ] =  C:scala-2.8.0.Beta1-RC6 

define "HelloWorld" do

  #artifact_ns[ Buildr::Compiler::Scalac ].library =  2.8.0 
  require  buildr/scala 

  puts Scala.version

end

When I run buildr I get the following output:

(in C:/Users/Travis/eclipse_ws/HelloWorld, development)
2.7.5
Building HelloWorld
Compiling HelloWorld into C:/Users/Travis/eclipse_ws/HelloWorld/target/classes
Buildr aborted!
←[31mScala compiler crashed:
#←[0m

The first problem is the NoClassDefFoundError - it cannot find the scala compiler s main class. The second problem is that Scala.version is printing out 2.7.5. This is incorrect because the SCALA_HOME path is pointing to a 2.8 release.

Finally, using the --trace flag shows me that Buildr is generating a somewhat correct scalac command and when I run that command manually everything compiles. I say it s somewhat correct only because some cp entries are duplicated. See the following:

scalac -classpath C:/scala-2.8.0.Beta1-RC6/lib/scala-library.jar;C:/scala-2.8.0.Beta1-RC6/lib/scala-compiler.jar;C:/scala-2.8.0.Beta1-RC6/lib/scala-library.jar;C:/scala-2.8.0.Beta1-RC6/lib/scala-compiler.jar -sourcepath C:/Users/Travis/eclipse_ws/HelloWorld/src/main/scala -d C:/Users/Travis/eclipse_ws/HelloWorld/target/classes -verbose -g C:/Users/Travis/eclipse_ws/HelloWorld/src/main/scala/hw/HelloWorld.scala

One more thing I tried (but errored out builder) was setting the following (which I thought wasn t required w/ the presence of SCALA_HOME):

#artifact_ns[ Buildr::Compiler::Scalac ].library =  2.8.0 

So any ideas?

Here is a quick list of my system info: Win 7 64 bit JDK 6 32 bit set locally for buildr but JDK 6 64 bit system-wide Ruby 1.8.6 32 bit Buildr 1.3.5 32 bit Scala 2.8.0.Beta1-RC6

One more thing I m thinking of doing is reinstalling my 32 bit JDK and getting it out the the directory with the (x86) in the name. I ve found that screws with the Scala bat files although I m not sure if this is relevant to my current problems.

Thanks in advance!

最佳回答

Figured it out. Silly problem. In Buildr(or maybe more generically in Ruby?), the require method call must come at the top of the file (or at least not inside the define block).

require buildr/scala

So both the NoClassDefFoundError and the incorrect version displayed by puts Scala.version were corrected by this. The following is what my script should have looked like:

require  buildr/scala 

ENV[ JAVA_HOME ] =  C:Program Files (x86)Javajdk1.6.0_17 
ENV[ SCALA_HOME ] =  C:scala-2.8.0.Beta1-RC6 

define  HelloWorld  do

  puts Scala.version

end

BTW: Buildr seems to be pretty sweet (fast, concise, convention over config, etc.) once you figure what you are doing :-)

问题回答

With version 1.4, at the moment you can do

Buildr.settings.build[ scala.version ] = "2.8.0"
require  buildr/scala 

And it will use scala 2.8.

Buildr 1.4 has support for Scala 2.8 and 1.4.2 will use 2.8 by default.





相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签