Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: class not found in packages #2891

Closed
ArthurUbuntu opened this issue Apr 29, 2015 · 5 comments
Closed

NameError: class not found in packages #2891

ArthurUbuntu opened this issue Apr 29, 2015 · 5 comments

Comments

@ArthurUbuntu
Copy link

I have in BaseClass.java file the following class and while I create a
class object in a Ruby file it gets into an error if I have not
commented the instantiating of 'webDriver' ( see below ).
With the commented 'webDriver' I can call func1() and func2() Java
methods from Ruby code ( jruby test.rb ===> calling Java methods from
test.rb )

Please note that Java compilation passes with no errors and I create
then put the classes JAR file in $CLASSPATH in my Ruby file ( $CLASSPATH
<< "the_classes_jar_file" )

Without commented the 'webDriver' I am getting the following error.
This is a linking issue in Jruby ( probably a bug in Jruby ), cause the
same code works while I build and run from Eclipse.

....

: NameError: BaseClass not found in packages p1; last error: cannot link
Java class p1.BaseClass,probable missing dependency:
org/openqa/selenium/WebDriver

....

Here is the Java class:

package p1;

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.;
import org.openqa.selenium.chrome.
;
import org.openqa.selenium.ie.*;

public class BaseClass
{
protected static WebDriver webDriver = null;
protected static String firefoxProfileDir = "";

public void configureParameters( String firefoxProfileDir )
{
   this.firefoxProfileDir = firefoxProfileDir;
   java.io.File profilefile = new File(this.firefoxProfileDir);
   FirefoxProfile profile = new FirefoxProfile(profilefile);
   profile.setAcceptUntrustedCertificates(false);
   //webDriver = new FirefoxDriver(profile);
}

public void func1()
{
System.out.println("calling func1 from BaseClass");
}

public void func2()
{
System.out.println("calling func2 from BaseClass");
}
}

and here is the Jruby code ( test.rb ) calling the Java class method:

require 'java'
include Java

module TheMainClasses
include_package "p1"
end

obj_base = TheMainClasses::BaseClass.new()
obj_base.func1()
obj_base.func2()

@ArthurUbuntu
Copy link
Author

C:>java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)

C:\jruby-9.0.0.0.pre1\bin\jruby.exe

selenium-server-standalone-2.45.0.jar was located in projec_directory

Here is the Java compile command:
$comp_cmd = "javac -cp ".;#{$project_directory}/;" #{$project_directory}/p1/*.java"
system("#{$comp_cmd}")

@mkristian
Copy link
Member

please try the 9.0.0.0.pre2 since there are some changes on the classloader hierarchy of jruby.

@ArthurUbuntu
Copy link
Author

ok, I'll try that and update the bug details.

you also can try at your end.
Here is the Jruby script file:

require 'java'
include Java

$CLASSPATH << 'selenium-server-standalone-2.45.0.jar'

module TheMainClasses
include_package "p1"
end

puts "classpath = #{$CLASSPATH}"
obj_base = TheMainClasses::BaseClass.new()
obj_base.func1()
obj_base.func2()

and here is what I get with commented string:
C:\jruby-9.0.0.0.pre1\bin\jruby.exe --1.8 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/bug_in_jruby/calling_java.rb
warning: --1.8 ignored
classpath = ["file:C:/bug_in_jruby/selenium-server-standalone-2.45.0.jar"]
calling func1 from BaseClass
calling func2 from BaseClass

Process finished with exit code 0

and here is what I get if I remove the comments:
C:\jruby-9.0.0.0.pre1\bin\jruby.exe --1.8 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/bug_in_jruby/calling_java.rb
warning: --1.8 ignored
classpath = ["file:C:/bug_in_jruby/selenium-server-standalone-2.45.0.jar"]
NameError: BaseClass not found in packages p1; last error: cannot link Java class p1.BaseClass, probable missing dependency: org/openqa/selenium/WebDriver
const_missing at file:/C:/jruby-9.0.0.0.pre1/lib/jruby.jar!/jruby/java/core_ext/module.rb:42
(root) at C:/bug_in_jruby/calling_java.rb:12
load at org/jruby/RubyKernel.java:969
script at -e:1

Process finished with exit code 1

@ArthurUbuntu
Copy link
Author

C:\jruby-9.0.0.0.pre2\bin\jruby.exe --1.8 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/bug_in_jruby/calling_java.rb
warning: --1.8 ignored
classpath = ["file:C:/bug_in_jruby/selenium-server-standalone-2.45.0.jar", "file:C:/bug_in_jruby/classes.jar"]
NameError: BaseClass not found in packages p1; last error: cannot link Java class p1.BaseClass, probable missing dependency: org/openqa/selenium/WebDriver
const_missing at uri:classloader:/jruby/java/core_ext/module.rb:42
at C:/bug_in_jruby/calling_java.rb:13
load at org/jruby/RubyKernel.java:984
at -e:1

Process finished with exit code 1

@ArthurUbuntu
Copy link
Author

It worked !

C:\jruby-9.0.0.0.pre1\bin\jruby.exe --1.8 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/bug_in_jruby/calling_java.rb
warning: --1.8 ignored
classpath = ["file:C:/bug_in_jruby/selenium-server-standalone-2.45.0.jar", "file:C:/bug_in_jruby/classes.jar"]
calling func1 from BaseClass
calling func2 from BaseClass

Process finished with exit code 0

@headius headius added this to the JRuby 9.0.0.0.pre2 milestone May 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants