buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ijonas Kisselbach <ijonas.kisselb...@gmail.com>
Subject Re: problem loading Java classes in extension
Date Mon, 28 Sep 2009 23:03:26 GMT
Thanks Daniel,

Your suggestion worked. Moved the Java.classpath to just after the  
module declaration and Buildr began downloading the artifact

My extension now looks like this:
module DDLExporter
   include Extension

   Java.classpath << "org.hibernate:hibernate-tools:jar:3.2.3.GA"

   first_time do
.....

Regards,
Ijonas.

On 28 Sep 2009, at 23:30, Daniel Spiewak wrote:

> I *think* your treatment of Java.classpath is just fine, but to be  
> safe you
> could wrap each artifact String in artifact(...).invoke  Probably  
> isn't
> necessary though...
>
> The problem is actually that you haven't invoked Java.load.  More
> importantly, even if you did perform the invocation, it has probably  
> been
> invoked previous to that point in the code (when the task is  
> executed),
> meaning that your classpath additions will not be recognized.  Try  
> sticking
> the Java.classpath mutations somewhere in the static scope.  They  
> should be
> executed when your extension is *loaded*.  Then, invoke Java.load  
> within the
> task just before you call the Hibernate class.
>
> Rule of thumb: add to classpath as *early* as possible, invoke load  
> as *late
> * as possible.
>
> Daniel
>
> On Mon, Sep 28, 2009 at 5:25 PM, Ijonas Kisselbach <
> ijonas.kisselbach@gmail.com> wrote:
>
>> Hi,
>>
>> I'm trying to write a extension that exports DDLs using HIbernate's
>> schemaexport tool. Although I've added the hibernate-tools  
>> dependency to the
>> Java.classpath I don't see it downloading the jar and my .m2/ 
>> repository
>> remains empty of the Hibernate Tools jars.
>>
>> I've got the following fragment of code in my extension which does  
>> all the
>> heavy lifting:
>>
>>   Rake::Task.define_task 'ddl' do |task|
>>     puts "classpath 1: #{Java.classpath}"
>>     Java.classpath << "org.hibernate:hibernate-tools:jar:3.2.3.GA"
>>     puts "classpath 2: #{Java.classpath}"
>>     Java.load
>>     puts "classpath 3: #{Java.classpath}"
>>     puts Java.java.lang.String.new("hello there")
>>     config_file = Java.java.io.File.new(config_file_path)
>>     puts config_file.canonicalPath
>>     config = Java.org.hibernate.cfg.Configuration.configure 
>> (config_file)
>>
>>     # config = nil
>>     schema_export =
>> Java.org.hibernate.tool.hbm2ddl.SchemaExport.new(config)
>>     schema_export.outputFile = output_filename
>>     schema_export.execute(true, true, false, false)
>>   end
>>
>> Producing the following output
>>
>> ** Execute ContentMigrator:ddl
>> classpath 1:
>> org.apache.ant:ant:jar:1.7.1org.apache.ant:ant-launcher:jar: 
>> 1.7.1org.apache.ant:ant-trax:jar:1.7.1/Users/ijonas/java/ 
>> jruby-1.3.1/lib/ruby/gems/1.8/gems/buildr-1.3.4-java/lib/buildr/java
>> classpath 2:
>> org.apache.ant:ant:jar:1.7.1org.apache.ant:ant-launcher:jar: 
>> 1.7.1org.apache.ant:ant-trax:jar:1.7.1/Users/ijonas/java/ 
>> jruby-1.3.1/lib/ruby/gems/1.8/gems/buildr-1.3.4-java/lib/buildr/ 
>> javaorg.hibernate:hibernate-tools:jar:
>> 3.2.3.GA
>> classpath 3:
>> org.apache.ant:ant:jar:1.7.1org.apache.ant:ant-launcher:jar: 
>> 1.7.1org.apache.ant:ant-trax:jar:1.7.1/Users/ijonas/java/ 
>> jruby-1.3.1/lib/ruby/gems/1.8/gems/buildr-1.3.4-java/lib/buildr/ 
>> javaorg.hibernate:hibernate-tools:jar:
>> 3.2.3.GA
>> hello there
>>
>> /Users/ijonas/code/v3branch-rails/src/test/resources/ 
>> testMysql5InnoDBApplicationContext.xml
>> Buildr aborted!
>> cannot load Java class org.hibernate.cfg.Configuration
>> /Users/ijonas/java/jruby-1.3.1/lib/ruby/gems/1.8/gems/rake-0.8.4/ 
>> lib/rake.rb:472:in
>> `get_proxy_or_package_under_package'
>> /Users/ijonas/java/jruby-1.3.1/lib/ruby/site_ruby/1.8/builtin/ 
>> javasupport/java.rb:51:in
>> `method_missing'
>> ddlexporter.rb:42:in `ddl'
>> /Users/ijonas/java/jruby-1.3.1/lib/ruby/gems/1.8/gems/rake-0.8.4/ 
>> lib/rake.rb:615:in
>> `call'
>>
>> The classpath isn't resolved properly by the looks of things and  
>> hence the
>> build fails.
>>
>> Is Java.classpath << "org.hibernate:hibernate-tools:jar:3.2.3.GA" the
>> right way of adding a dependency for my extension ? If so, what am  
>> I doing
>> wrong ?
>>
>> Many thanks,
>> Ijonas.
>>
>>


Mime
View raw message