Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596188
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:57:20+00:00 2026-05-18T19:57:20+00:00

I run Buildr in two different environments (Windows XP and Linux) and therefore I

  • 0

I run Buildr in two different environments (Windows XP and Linux) and therefore I have local Java and Scala installations in different locations. I have the following practice to check that the environment variables are set:

require 'buildr/scala'
# Can I put these checks on a function ? How ?
ENV['JAVA_HOME'] ||= Buildr.settings.user['java_home']
if ENV['JAVA_HOME'].nil? then
  puts "Required environment variable JAVA_HOME was not set. Value can also be set in personal settings."
  Process.exit 1
end
puts 'JAVA_HOME = ' + ENV['JAVA_HOME']

ENV['SCALA_HOME'] ||= Buildr.settings.user['scala_home']
if ENV['SCALA_HOME'].nil? then
  puts "Required environment variable SCALA_HOME was not set. Value can also be set in personal settings."
  Process.exit 1
end
puts 'SCALA_HOME = ' + ENV['SCALA_HOME']

puts 'Scala version: ' + Scala.version

define "HelloWorld" do
  puts 'Hello World !'
end

But how do I exit Buildr so that it exits with this kind of message:

Buildr aborted!
RuntimeError : Scala compiler crashed:
#<NullPointerException: unknown exception>
(See full trace by running task with --trace)

Should I throw an exception (if yes, how to do that in Ruby) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:57:21+00:00Added an answer on May 18, 2026 at 7:57 pm

    Try fail:

    if ENV['SCALA_HOME'].nil? then
      fail "Required environment variable SCALA_HOME was not set. Value can also be set in personal settings."
    end
    

    fail throws an exception in ruby. You might also see it called raise; they’re equivalent. If you don’t specify a type, the exception type will be RuntimeError as in your “compiler crashed” example.

    Bonus answer: If you want to put these checks in a function (as your comment on the first one suggests), you can create a directory called tasks at the top level of your project, then put a file with a .rake extension in it. Define your functions there. Buildr will load all such files before evaluating your buildfile.

    For example, you could have a file named tasks/helpers.rake with these contents:

    def initialize_environment
      ENV['JAVA_HOME'] ||= Buildr.settings.user['java_home']
      unless ENV['JAVA_HOME']
        fail "Required environment variable JAVA_HOME was not set. Value can also be set in personal settings."
      end
      puts "JAVA_HOME = #{ENV['JAVA_HOME']}"
      # etc.
    end
    

    (Note: I changed a couple of other details — unless, string interpolation — to be more ruby-idomatic. The way you had it was fine, too, if you prefer that.)

    Then at the top of your buildfile you could have this:

    require 'buildr/scala'
    initialize_environment
    # etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run Buildr in two different environments (Windows XP and Linux) and therefore I
I have two different java projects (I'll call them project 1 and Project 2
I have two batch files which is used to run a large C++ build,
I'm building a Flex application that will need run under two different deployment scenarios:
If I run the following program, which parses two date strings referencing times 1
I have an app that I want to be able to build two different
I would like to accomplish two things during my build process: Run unit tests
If I run a Maven build in NetBeans which starts a long-running Java process
I have the same source files (C and Obj-C) being compiled into two targets:
We currently run two separate webapps (WARs) deployed in one single EAR containing additional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.