Running it smooth and simple... in Eclipse? Plz fix me out

classic Classic list List threaded Threaded
14 messages Options
z4c
Reply | Threaded
Open this post in threaded view
|

Running it smooth and simple... in Eclipse? Plz fix me out

z4c
Hi folks, unfortunately this piece of code won`t work due to a weird namespace problem. I`m a total beginner when it comes to BeanShell.

________________________

import bsh.EvalError;
import bsh.Interpreter;


public class Nos {


        public static void main(String[] args) {
               
                Interpreter i = new Interpreter();
                System.out.println(i.getNameSpace().toString());
               
                try {
                       
                       i.eval("MyFrickinClass f = new MyFrickinClass();");

                        MyFrickinClass f=(MyFrickinClass)i.get("f");

                } catch (EvalError e) {
                        e.printStackTrace();
                }
                                       
        }

}

________________________

The necessary class is located in the same package as class Nos.

The output of this looks like this:

NameSpace: global (bsh.NameSpace@665753)
Sourced file: inline evaluation of: ``MyFrickinClass f = new MyFrickinClass();'' : Typed variable declaration : Class: MyFrickinClass not found in namespace : at Line: 1 : in file: inline evaluation of: ``MyFrickinClass f = new MyFrickinClass();'' : MyFrickinClass

        at bsh.BSHAmbiguousName.toClass(Unknown Source)
        at bsh.BSHType.getType(Unknown Source)
        at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at beanshell.my.crap.Nos.main(Nos.java:16)



So what`s the problem?
bsh-core-2.0b4.jar is available in the build path. How do I get this thing working for my Eclipse project? Sample code would be great. Thanks in advance and happy coding,

Z4C
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

Werner Schuster (murphee)
z4c wrote:
> The necessary class is located in the same package as class Nos.
>
> The output of this looks like this:
>
> NameSpace: global (bsh.NameSpace@665753)
> Sourced file: inline evaluation of: ``MyFrickinClass f = new
> MyFrickinClass();'' : Typed variable declaration : Class: MyFrickinClass not
> found in namespace : at Line: 1 : in file: inline evaluation of:
>  

Well... why don't you try giving the full name of MyFrickingClass? (I
mean: including the package name).
Either that, or evaluate a import statement for the class before using it.

murphee
--
Blog @ http://jroller.com/page/murphee 
Maintainer of EclipseShell @ http://eclipse-shell.sourceforge.net/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
z4c
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

z4c
Thanks for your fast response.
Well OK, the code looks like this now:

_______

import bsh.EvalError;
import bsh.Interpreter;


public class Nos {


        public static void main(String[] args) {
               
                Interpreter i = new Interpreter();
                System.out.println(i.getNameSpace().toString());
                try {
                        //i.eval("MyFrickinClass f = new MyFrickinClass();");
                        i.eval("beanshell.pack.MyFrickinClass f = new beanshell.pack.MyFrickinClass();");
                        MyFrickinClass f=(MyFrickinClass)i.get("f");
                } catch (EvalError e) {
                        e.printStackTrace();
                }
                                       
        }
}

Still doesn`t work, since I get the following exception:

Sourced file: inline evaluation of: ``beanshell.pack.MyFrickinClass f = new beanshell.pack.MyFrickinClass();'' : Typed variable declaration : Constructor error: We don't have permission to create an instance.Use setAccessibility(true) to enable access. : at Line: 1 : in file: inline evaluation of: ``beanshell.pack.MyFrickinClass f = new beanshell.pack.MyFrickinClass();'' : new beanshell .pack .MyFrickinClass ( )

        at bsh.BSHAllocationExpression.constructObject(Unknown Source)
        at bsh.BSHAllocationExpression.objectAllocation(Unknown Source)
        at bsh.BSHAllocationExpression.eval(Unknown Source)
        at bsh.BSHPrimaryExpression.eval(Unknown Source)
        at bsh.BSHPrimaryExpression.eval(Unknown Source)
        at bsh.BSHVariableDeclarator.eval(Unknown Source)
        at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at bsh.Interpreter.eval(Unknown Source)
        at beanshell.pack.Nos.main(Nos.java:16)


What`s meant by "Use setAccessibility(true)"? Which class are we talking about? How would I change the import settings to avoid such problems? Obviously, the general import statement (for the class Nos) won`t work with the Parser. Is there some Interpreter-option or something required to be set?

Thanks in advance,

Z4C
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

Werner Schuster (murphee)
z4c wrote:
> What`s meant by "Use setAccessibility(true)"? Which class are we talking
> about?
>  
Does the MyFrickingClass have a public Constructor?

You can also use

f = new beanshell.pack.MyFrickinClass();


Here are some old mailing list entries about his
http://sourceforge.net/mailarchive/forum.php?forum_id=6969&max_rows=25&style=nested&viewmonth=200012

murphee
-- Blog @ http://jroller.com/page/murphee Maintainer of EclipseShell @
http://eclipse-shell.sourceforge.net/



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
z4c
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

z4c
Thanks again... I Just don`t get it though... Here`s the class MyFrickinClass we are talking about which cannot be accessed for some weird reason:
_______

package beanshell.pack;

import java.lang.reflect.*;

 class MyFrickinClass {
         
         public MyFrickinClass(){
                 String firstWord = "Hello ";
              String secondWord = "everybody.";
              String bothWords = append(firstWord, secondWord);
              System.out.println(bothWords);
         }
   

   public static String append(String firstWord, String secondWord) {
      String result = null;
      Class c = String.class;
      Class[] parameterTypes = new Class[] {String.class};
      Method concatMethod;
      Object[] arguments = new Object[] {secondWord};
      try {
        concatMethod = c.getMethod("concat", parameterTypes);
        result = (String) concatMethod.invoke(firstWord, arguments);
      } catch (NoSuchMethodException e) {
          System.out.println(e);
      } catch (IllegalAccessException e) {
          System.out.println(e);
      } catch (InvocationTargetException e) {
          System.out.println(e);
      }
      return result;
   }
}

________


i.eval("f = new beanshell.pack.MyFrickinClass();"); won`t work either. I followed the link you provided but I still cannot figure out why those classes, located in the same package and without any "private" declaration, should not be able to access each other. Further help would be deeply appreciated.
 
Z4C
z4c
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

z4c
Update: Guess this one is solved.

The class declaration has to be public... That´s it. Oh well. Thank you for your advice.
z4c
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

z4c
In reply to this post by Werner Schuster (murphee)
Hi again. I wonder how one would do something like this:

___

package beanshell.pack;

import bsh.EvalError;
import bsh.Interpreter;


public class Nos {


        public static void main(String[] args) {
               
                Interpreter i = new Interpreter();
                System.out.println(i.getNameSpace().toString());
                try {
                        i.eval("f = new beanshell.pack.MyFrickinClass();");

                        MyFrickinClass c=new MyFrickinClass();

                        i.eval("f = "+c);

                } catch (EvalError e) {
                        e.printStackTrace();
                }
                                       
        }

}

___

Obviously, i.eval( " f = "+c) ; won`t work. How could my intention be accomplished?

Thanks,

Z4C
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

David Lee
 i.eval("f = new beanshell.pack.MyFrickinClass();");

 MyFrickinClass c=new MyFrickinClass();
i.set("c",c);

 i.eval("f = f+c");





>
> Hi again. I wonder how one would do something like this:
>
> ___
>
> package beanshell.pack;
>
> import bsh.EvalError;
> import bsh.Interpreter;
>
>
> public class Nos {
>
>
> public static void main(String[] args) {
>
> Interpreter i = new Interpreter();
> System.out.println(i.getNameSpace().toString());
> try {
> i.eval("f = new beanshell.pack.MyFrickinClass();");
>
> MyFrickinClass c=new MyFrickinClass();
>
> i.eval("f = "+c);
>
> } catch (EvalError e) {
> e.printStackTrace();
> }
>
> }
>
> }
>
> ___
>
> Obviously, i.eval( " f = "+c) ; won`t work. How could my intention be
> accomplished?
>
> Thanks,
>
> Z4C
> --
> View this message in context:
> http://www.nabble.com/Running-it-smooth-and-simple...-in-Eclipse--Plz-fix-me-out-tf1998271.html#a5499753
> Sent from the BeanShell - User forum at Nabble.com.
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

Brian Hawkins
In reply to this post by z4c
I have done this kind of thing.  Do the following:

Interpreter i = new Interpreter();
i.set("f", new Foo());
i.eval("f.callFooMethod();");

Brian

z4c wrote:

> Hi again. I wonder how one would do something like this:
>
> ___
>
> package beanshell.pack;
>
> import bsh.EvalError;
> import bsh.Interpreter;
>
>
> public class Nos {
>
>
> public static void main(String[] args) {
>
> Interpreter i = new Interpreter();
> System.out.println(i.getNameSpace().toString());
> try {
> i.eval("f = new beanshell.pack.MyFrickinClass();");
>
> MyFrickinClass c=new MyFrickinClass();
>
> i.eval("f = "+c);
>
> } catch (EvalError e) {
> e.printStackTrace();
> }
>
> }
>
> }
>
> ___
>
> Obviously, i.eval( " f = "+c) ; won`t work. How could my intention be
> accomplished?
>
> Thanks,
>
> Z4C
>  

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

Jesse Pavel
In reply to this post by z4c
You can use

  i.set("f", new MyFrickinClass());

~Jesse


On 7/26/06, z4c <[hidden email]> wrote:

>
> Hi again. I wonder how one would do something like this:
>
> ___
>
> package beanshell.pack;
>
> import bsh.EvalError;
> import bsh.Interpreter;
>
>
> public class Nos {
>
>
>         public static void main(String[] args) {
>
>                 Interpreter i = new Interpreter();
>                 System.out.println(i.getNameSpace().toString());
>                 try {
>                         i.eval("f = new beanshell.pack.MyFrickinClass();");
>
>                         MyFrickinClass c=new MyFrickinClass();
>
>                         i.eval("f = "+c);
>
>                 } catch (EvalError e) {
>                         e.printStackTrace();
>                 }
>
>         }
>
> }
>
> ___
>
> Obviously, i.eval( " f = "+c) ; won`t work. How could my intention be
> accomplished?
>
> Thanks,
>
> Z4C
> --
> View this message in context: http://www.nabble.com/Running-it-smooth-and-simple...-in-Eclipse--Plz-fix-me-out-tf1998271.html#a5499753
> Sent from the BeanShell - User forum at Nabble.com.
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

David Lee
In reply to this post by z4c
As mentioned before you need the make the entire class public.

public class MyFrickinClass {
...






----- Original Message -----
From: "z4c" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, July 26, 2006 1:45 AM
Subject: Re: [Beanshell-users] Running it smooth and simple... in Eclipse?
Plz fix me out


>
>
> Thanks again... I Just don`t get it though... Here`s the class
> MyFrickinClass we are talking about which cannot be accessed for some
> weird
> reason:
> _______
>
> package beanshell.pack;
>
> import java.lang.reflect.*;
>
> class MyFrickinClass {
>
> public MyFrickinClass(){
> String firstWord = "Hello ";
>       String secondWord = "everybody.";
>       String bothWords = append(firstWord, secondWord);
>       System.out.println(bothWords);
> }
>
>
>   public static String append(String firstWord, String secondWord) {
>      String result = null;
>      Class c = String.class;
>      Class[] parameterTypes = new Class[] {String.class};
>      Method concatMethod;
>      Object[] arguments = new Object[] {secondWord};
>      try {
>        concatMethod = c.getMethod("concat", parameterTypes);
>        result = (String) concatMethod.invoke(firstWord, arguments);
>      } catch (NoSuchMethodException e) {
>          System.out.println(e);
>      } catch (IllegalAccessException e) {
>          System.out.println(e);
>      } catch (InvocationTargetException e) {
>          System.out.println(e);
>      }
>      return result;
>   }
> }
>
> ________
>
>
> i.eval("f = new beanshell.pack.MyFrickinClass();"); won`t work either. I
> followed the link you provided but I still cannot figure out why those
> classes, located in the same package and not without any "private"
> declaration, should not be able to access each other. Further help would
> be
> deeply appreciated.
>
> Z4C
> --
> View this message in context:
> http://www.nabble.com/Running-it-smooth-and-simple...-in-Eclipse--Plz-fix-me-out-tf1998271.html#a5498512
> Sent from the BeanShell - User forum at Nabble.com.
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

Wade Chandler-6
--- David Lee <[hidden email]> wrote:
> As mentioned before you need the make the entire
> class public.
>
> public class MyFrickinClass {
> ...
>

Just to add ... not giving a protection level (public,
protected, or private) automatically defaults to
package protected.

Wade

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse? Plz fix me out

Alexey Zinger
Wade Chandler <[hidden email]> wrote:
--- David Lee wrote:
> As mentioned before you need the make the entire
> class public.
>
> public class MyFrickinClass {
> ...
>

Just to add ... not giving a protection level (public,
protected, or private) automatically defaults to
package protected.

Wade

That said, however, the package scope protection does not work as expected when 2 classes are loaded by different class loaders, which I believe happened here.  When 2 class loaders load even the same class, the objects they produce will be considered of 2 different classes.  Similarly, if 2 class loaders load things from the same package, package-scope access will not work between the objects they produce.


Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net


Want to be your own boss? Learn how on Yahoo! Small Business.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: Running it smooth and simple... in Eclipse?Plz fix me out

David Lee
thats why you need to delcare the class itself public.
Beanshell is not running under the protection scheme of its caller.
Its like its "external" ...
----- Original Message -----
Sent: Monday, July 31, 2006 10:00 AM
Subject: Re: [Beanshell-users] Running it smooth and simple... in Eclipse?Plz fix me out

Wade Chandler <[hidden email]> wrote:
--- David Lee wrote:
> As mentioned before you need the make the entire
> class public.
>
> public class MyFrickinClass {
> ...
>

Just to add ... not giving a protection level (public,
protected, or private) automatically defaults to
package protected.

Wade

That said, however, the package scope protection does not work as expected when 2 classes are loaded by different class loaders, which I believe happened here.  When 2 class loaders load even the same class, the objects they produce will be considered of 2 different classes.  Similarly, if 2 class loaders load things from the same package, package-scope access will not work between the objects they produce.


Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net


Want to be your own boss? Learn how on Yahoo! Small Business.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users