I trying to bring a jruby application over to glassfishv3 and am a bit confused on classloaders. In Glassfish, when a jar is added to the domain/lib directory, that jar is on the classpath for applications on that domain. I was originally expecting that I wouldn't need to do a require for Jruby to access those classes. However, it seems like I do. When I do a require, I think I'm having a double loading problem. My situation: mylib points to log4j. When I tell jruby to require both mylib and log4j, i have casting problems (it appears that log4j is doubly loaded as a subclass fails to be cast to the base class). When I tell jruby only to load mylib (which depends on log4j--which should be on classpath), I get a failure to link. Clearly, I'm don't have the right model for how classpaths/loaders work in Jruby and Glassfish. Can someone point me to a good overview? Thanks, Jacques Currently running on java6u16/jruby1.4/glassfishv3ga
on 2010-03-09 01:29
on 2010-03-09 08:15
Did you place your libraries in domain_dir/lib/ or in domain_dir/lib/ext ? How are you deploying in Glassfish? When you deploy a war file, you can put your libraries in your rails_dir/lib and warbler will put them in the WEB-INF/lib folder in the war file. These libs are automatically loaded. kind regards, marco Jacques schrieb: > as a subclass fails to be cast to the base class). When I tell jruby > Currently running on java6u16/jruby1.4/glassfishv3ga --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-09 18:14
I placed the libraries in domain_dir/lib. It is my understanding that ext should be used only for libraries loaded before the glassfish environment. I'm using an exploded deployment to glassfish so the WEB_INF/lib directory is not involved. Does jruby inherit the domain level classpath? FYI, I already have an EE app running on this domain which has no problems interacting with the libraries in domain_dir/lib. In Jruby, it is my understanding that a require command is only needed if the classes are not already on the classpath. Is this correct? Thanks, Jacques
on 2010-03-10 08:23
Hi, Jacques schrieb: > I placed the libraries in domain_dir/lib. It is my understanding that > ext should be used only for libraries loaded before the glassfish > environment. I'm using an exploded deployment to glassfish so the > WEB_INF/lib directory is not involved. What is your way to deploy? The domain_dir/lib directory is global. An application server with many apps will switch to per-app usage of libraries. > > Does jruby inherit the domain level classpath? FYI, I already have an > EE app running on this domain which has no problems interacting with > the libraries in domain_dir/lib. > > In Jruby, it is my understanding that a require command is only needed > if the classes are not already on the classpath. Is this correct? This is basically correct. The classes have to be imported like in Java. This is not working for you? Usually glassfish resolves libraries which are already loaded. kind regards, marco > you can put your libraries in your rails_dir/lib and warbler will > am a bit confused on classloaders. > classpath), I get a failure to link. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-10 18:25
I built a very simple example to show the problem. The example has the following construction: a. Four library jars for deployment to the domain_dir/lib directory. "examplelogger.jar" is the one I want to be able to call directly from Jruby. b. A simple rails application. So that the error is easiest to see, the rails application utilizes environment.rb file to work with example logger. The current state has us requiring all four required libraries. This is the only change from a stock rails generated app. c. I've also included the java source in an eclipse project. You can find the example at: http://whsaddins.com/jruby/railsproblem.zip The pertinent code are the following lines: require 'java' libdir = "C:/glassfishv3/glassfish/domains/domain1/lib/" require libdir+"log4j-1.2.15" require libdir+"slf4j-log4j12-1.5.8" require libdir+"slf4j-api-1.5.8" require libdir+"examplelogger" ET = Java::ComExampleJrubydoubleload::ExampleTool I'm deploying to Glassfish v3 using the exploded/native deployment option. Java 6u16/Jruby 1.4.0. To deploy I'm using the simple deployment command "asadmin deploy --properties jruby.rackEnv=development ." in the base rails directory. The outcomes I receive for various configurations are as follows. Which is the right format or are they all wrong? 1. Include no require lines for specific jars. (My original expected approach given that I expected that jars to be on the classpath.) Outcome: "C:/var/apps/jruby/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb:45:in `const_missing': cannot load Java class" 2. Include only primary jar using fully qualified filename. Outcome: "C:/var/apps/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require': IO error" 3. Include all required references using fully qualified filename. Outcome: "java.lang.ClassCastException: org.apache.log4j.net.SocketAppender cannot be cast to org.apache.log4j.Appender". This is surely a classloader issue since SocketAppender is a subclass fo Appender. So what am I doing wrong here? Thanks, Jacques
on 2010-03-11 12:52
Hi Jacques, with the native deployment option (Ruby Container) in Glassfish v3 I had similar problems. Did you try building a war file with warbler? I am very interested in a solution of this problem. I also contacted Arun Gupta, a guy which is involved in the development of glassfish, but I didn't get an answer yet. Sorry, I have no hints any more... kind regards, marco Jacques schrieb: > generated app. > require libdir+"slf4j-api-1.5.8" > > 3. Include all required references using fully qualified filename. > > Jacques schrieb: > > Java. This is not working for you? > On Mon, Mar 8, 2010 at 11:14 PM, Marco Dohnke <dohnke@bfpi.de > automatically loaded. > In Glassfish, when a jar is added to the domain/lib > tell jruby to require both mylib and log4j, i have casting > > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-15 17:53
On Tue, Mar 9, 2010 at 11:12 AM, Jacques <whshub@gmail.com> wrote: > I placed the libraries in domain_dir/lib. Â It is my understanding that ext > should be used only for libraries loaded before the glassfish environment. > Â I'm using an exploded deployment to glassfish so the WEB_INF/lib directory > is not involved. > Does jruby inherit the domain level classpath? Â FYI, I already have an EE > app running on this domain which has no problems interacting with the > libraries in domain_dir/lib. My guess would be that the "embedded" deploy of GF V3 is not propagating the domain_dir/lib libraries to the deployed JRuby application, since you can't see any of those classes from within your jruby app. It's not really anything JRuby is doing special; we just have an additional URLClassLoader to which we add require'd jar files, and then we do all our lookups through that classloader. Ideally, it would pick up the libraries from domain_dir/lib even if you re-required them. If you're having a problem with a base class not matching, I'm guessing that while GF is not providing the libraries in domain_dir/lib to JRuby, it's still providing some objects using those libraries, and so you have multiple log4j objects floating around. Can you provide more information here, like the exceptions you're getting, and perhaps a simple application that shows the problem? This seems more like a GF issue, but hopefully talking through it here will help get a simple case for them to fix. > In Jruby, it is my understanding that a require command is only needed if > the classes are not already on the classpath. Â Is this correct? Correct. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-16 22:09
I built an example of the problem here: http://whsaddins.com/jruby/railsproblem.zip <http://whsaddins.com/jruby/railsproblem.zip>I'm not using the embedded GF install like Marco, but rather a full GF install. You can see my original post here: http://markmail.org/message/rijm3cjnrysj4tab which gives the behaviors. Basically, the Jruby classloader doesn't see the libs even though my other (non jruby) gf apps see the libs just fine. Thanks for taking a look at this, Jacques On Mon, Mar 15, 2010 at 9:53 AM, Charles Oliver Nutter
on 2010-03-16 22:14
I built an example of the problem here: http://whsaddins.com/jruby/railsproblem.zip <http://whsaddins.com/jruby/railsproblem.zip>I'm not using the embedded GF install like Marco, but rather a full GF install. You can see my original post here: http://markmail.org/message/rijm3cjnrysj4tab which gives the behaviors. Basically, the Jruby classloader doesn't see the libs even though my other (non jruby) gf apps see the libs just fine. Thanks for taking a look at this, Jacques On Mon, Mar 15, 2010 at 9:53 AM, Charles Oliver Nutter
on 2010-03-17 22:06
On Tue, Mar 16, 2010 at 2:56 PM, Jacques <whshub@gmail.com> wrote: > I built an example of the problem > here:Â http://whsaddins.com/jruby/railsproblem.zip > I'm not using the embedded GF install like Marco, but rather a full GF > install. By this do you mean you're deploying as a WAR file, or using asadmin to deploy a Rails directory directly? The latter is what I mean by "embedded"...i.e. any deployment into a full GF server that doesn't use a WAR file is the embedded deploy. There's also the separate GF gem, which is yet another deployment option. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-17 23:08
I am deploying using a directory as opposed to a war file. (What you call embedded.) The reason I said before that I wasn't using embedded is because Glassfish can also be run in Embedded mode (which is where it can run inside another java application -- https://embedded-glassfish.dev.java.net/) I believe what you are calling embedded is what the Glassfish team calls "jruby native deployment". But I can see how you would consider that "embedded". Whatever the word, yes, the directory based deployment (where I'm not using a packaged war) is where this problem occurs. Thanks, Jacques On Wed, Mar 17, 2010 at 2:05 PM, Charles Oliver Nutter
on 2010-03-17 23:21
On Wed, Mar 17, 2010 at 4:07 PM, Jacques <whshub@gmail.com> wrote: > Whatever the word, yes, the directory based deployment (where I'm not using > a packaged war) is where this problem occurs. Ok, that helps :) So you said your other non-JRuby apps can see those libraries. Are they also being directory-deployed? Are that WAR-like (i.e. directory deploys of something with a WEB-INF + web.xml)? This still feels like a bug in GF directory deploy for JRuby, like it's not launching it under the proper classloader structure to see those libraries. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-17 23:37
I'm using directory (exploded) deployment across the board and it works fine for other exploded wars, jars, etc. I have the same feeling that this is a GF bug. Do you have a contact over there that could confirm? Thanks, Jacques On Wed, Mar 17, 2010 at 3:20 PM, Charles Oliver Nutter
on 2010-03-18 03:38
The folks I know that are familiar with the directory deployment for JRuby are Vivek Pandey (no longer with Sun/Oracle), Jacob Kessler (no longer with Sun/Oracle) and Arun Gupta (evangelist...may or may not be able to help directly). Now, if you're familiar with Java code, it's probably something you might be able to investigate yourself. It took some poking around, but here's one page with instructions on building GF: http://wiki.glassfish.java.net/Wiki.jsp?page=V3FullBuildInstructions I was able to check GF out from SVN, but I had to log in; I'm not sure whether that simply means you need a java.net ID, or whether you need specific access to their repository (I think I was added as a committer at one point). Let me know if you're able to get in and maybe we can find the problem together. On Wed, Mar 17, 2010 at 4:36 PM, Jacques <whshub@gmail.com> wrote: >> > Whatever the word, yes, the directory based deployment (where I'm not >> it's not launching it under the proper classloader structure to see > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-18 04:00
Actually it looks like the important bit is in here: https://svn.dev.java.net/svn/glassfish-scripting/trunk On Wed, Mar 17, 2010 at 8:38 PM, Charles Oliver Nutter <headius@headius.com> wrote: > >> I have the same feeling that this is a GF bug. Â Do you have a contact over >>> >>> - Charlie >>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> Â Â http://xircles.codehaus.org/manage_email >>> >>> >> >> > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 2010-03-18 04:17
Under the glassfish-scripting project...
grizzly/jruby/src/main/java/com/sun/grizzly/jruby/rack/JRubyRuntime.java
line 74:
iconfig.setLoader(JRubyRuntime.class.getClassLoader());
Given that JRubyRuntime is probably being loaded from the base
server--a classloader almost certainly lower than the user-provided
libraries--this seems incorrect. We use the classloader set into the
config as the base for the JRubyClassLoader which we use to find Java
libraries. If this were set to a higher-level classloader, we'd
probably be able to see the libraries you're looking for.
Just a quick theory from my 5-minute investigation.
A couple other resources come to mind: Takai Naoto, who originally
wrote the Grizzly-JRuby support, Jerome Dochez, whose name is all over
the scripting stuff, and of course there's the GF mailing lists.
- Charlie
On Wed, Mar 17, 2010 at 8:59 PM, Charles Oliver Nutter
<headius@headius.com> wrote:
>>
>>
>>> wrote:
>>>> deploys of something with a WEB-INF + web.xml)?
>>>> Â Â http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>
>>>
>>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
on 2010-03-18 06:39
Thanks for the help. I'll take a look at the code. Now the big question is whether to start playing in gf code or use an entirely different approach. Thanks again, Jacques On Wed, Mar 17, 2010 at 8:16 PM, Charles Oliver Nutter
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.