sam / doubleshot

Build and Dependency Management for mixed Java/Ruby projects.
MIT License
19 stars 22 forks source link

Integrate Apache Commons JCI for Java Class Reloading #1

Closed sam closed 11 years ago

sam commented 12 years ago

Instead of using JRuby's built-in Ant support, as we do now, use Apache Commons JCI (which is already a dependency in the Jarfile) in conjunction with a file-watcher so that we can recompile on-the-fly and reload classes.

That would mean we don't have to restart our Java process for changes in the Java source.

sam commented 11 years ago

I don't think we're doing this after all. Unless perhaps we can get it to work by using the "eclipse" compiler shown in the usage examples?

I didn't try that previously since I assumed we needed the javac compiler, but since during searching the interwebs I ran across the -XX:-UseSplitVerifier issue mentioned in conjunction with Eclipse, it later occurred to me that the "eclipse" switch passed to the compiler factory might actually just be a set of alternative defaults for javac that avoid the issues we were having.

I'll experiment in irb real quick.

sam commented 11 years ago

Worked up the following script (after downloading the JCI JARs, and JCI-eclipse compiler):

#!/usr/bin/env jruby

require "pathname"
Pathname::glob("jars/jci/*.jar").each { |jar| require jar }

tmp = Pathname("tmp")
tmp.mkdir unless tmp.exist?

source = tmp + "java"
source.mkdir unless source.exist?

target = tmp + "target"
target.mkdir unless target.exist?

(source + "Cow.java").open("w+") do |cow|
  cow << <<-EOS
package org.sam.doubleshot;

public class Cow {
  public Cow() {}

  public String moo() {
    return "MOO!";
  }
}
EOS
end

compiler = org.apache.commons.jci.compilers.JavaCompilerFactory.new.create_compiler "eclipse"
result = compiler.compile(
  Pathname::glob(source + "**/*.java").map(&:to_s).to_java(:string),
  org.apache.commons.jci.readers.FileResourceReader.new(java.io.File.new(source.to_s)),
  org.apache.commons.jci.stores.FileResourceStore.new(java.io.File.new(target.to_s))
)

puts "#{result.errors.size} errors"
puts "#{result.warnings.size} warnings"

It still fails. On line 29 this time, so it can't even create_compiler "eclipse". Considering the code hasn't been updated in 5 years, I think this is just a dead-end.

Also, as far as I can tell, the ReloadingClassLoader doesn't do what I thought (reload classes on recompile), so we'd have to come up with another mechanism anyway.

Closing this ticket out. We'll need an alternative at some point.