简体   繁体   中英

jruby cannot load java class from jar

I'm trying to wrap the amazon-merchant-web-service-java-sdk in jruby for a jruby-on-rails project.

In my test, I am able to instantiate some classes ....

require 'java'
require 'lib/MaWSJavaClientLibrary-1.1.jar'

module MWS
  include_package 'com.amazonaws.mws'
  include_package 'com.amazonaws.mws.model'
end

config = MWS::MarketplaceWebServiceConfig.new  #this works!!

... but not others

client = MWS::MarketplaceWebServiceClient.new  #this does NOT work!!!
NameError: MarketplaceWebServiceClient not found in packages com.amazonaws.mws, com.amazonaws.mws.model; last error: cannot load Java class com.amazonaws.mws.model.MarketplaceWebServiceClient
const_missing at file:/Users/...

Why is it not found? Could it be because, it's an implementation of an interface :

public  class MarketplaceWebServiceClient implements MarketplaceWebService

Interesting that I can instantiate the interface but not the implementation:

service = MWS::MarketplaceWebService.new # does not throw an error

That doesn't make sense since the the interface doesn't have a constructor. The implementation has 3 constructors having different arguments. But how do I invoke them?

What would be the jRuby equivalent of java's Interface variable = new Implementation() , ie:

MarketplaceWebService service = new MarketplaceWebServiceClient(
            accessKeyId, secretAccessKey, appName, appVersion, config);

Or is this just an import issue and I haven't correctly made the class available? Any advice is appreciated. Thanks.

EDIT: The java sdk, at the time of this writing can be found at: https://developer.amazonservices.com/doc/bde/feeds/v20090901/java.html/182-0022359-5036344

The jar is contained within the zip, along with the java source code.

It seems that wrapping your Java class in a module supressed a more detailed error message. I was able to debug by making this call instead:

client = Java::ComAmazonawsMws::MarketplaceWebServiceClient.new  

It seems you're missing some dependencies. Try adding these to the top:

require 'third-party/httpcore-4.2/httpcore-4.2.jar'
require 'third-party/httpclient-4.2/httpclient-4.2.jar'
require 'third-party/commons-httpclient-3.0.1/commons-httpclient-3.0.1.jar'
require 'third-party/commons-logging-1.1/commons-logging-1.1.jar'

I've started the work to create a simple JRuby GEM for MWS access. You can see what I've done at https://github.com/integrallis/jruby-amazon-mws

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM