Method: Java.load

Defined in:
lib/buildr/java/rjb.rb,
lib/buildr/java/jruby.rb

.loadObject

Loads the JVM and all the libraries listed on the classpath. Call this method before accessing any Java class, but only call it from methods used in the build, giving the Buildfile a chance to load all extensions that append to the classpath and specify which remote repositories to use.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/buildr/java/rjb.rb', line 126

def load
  return self if @loaded
  classpath << tools_jar if tools_jar

  classpath.map! { |path| Proc === path ? path.call : path }
  cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
  java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split

  # Prepend the JDK bin directory to the path under windows as RJB can have issues if it picks
  # up jvm dependencies from other products installed on the system
  if Buildr::Util.win_os?
    ENV["PATH"] = "#{ENV['JAVA_HOME']}#{File::SEPARATOR}bin#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
  end
  ::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts

  props = ::Rjb.import('java.lang.System').getProperties
  enum = props.propertyNames
  while enum.hasMoreElements
    name = enum.nextElement.toString
    ENV_JAVA[name] = props.getProperty(name)
  end
  @loaded = true
  self
end