facebook

Java Class Reflex getMethods not Work on MyEclipse

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #351205 Reply

    eugenejsn
    Participant

    This snippet:

    public final static void test(Object bean…{

    Class beanClass = bean.getClass();
    try {
    Method[] beanMethods = beanClass.getMethods();

    actually worked on IBM RAD 8/Websphere 8.

    Now I migrated it over to MyEclipse Blue 2014/JBoss AS 7.1.1. The line

    Method[] beanMethods = beanClass.getMethods();

    silently failed.

    Do I miss some libraries? or else?

    Thanks

    Eugene

    #351208 Reply

    support-tony
    Keymaster

    Eugene,

    I’m afraid I couldn’t replicate the problem. I used that code snippet in a simple Web application, running on JBoss 7.1 and got the output I expected.

    Please answer some questions:

    1. How, exactly are you running the snippet?
    2. When you say that it fails silently, what do you mean? That it returns null or that it doesn’t return what you expect?
    3. Could you attach a simple project that shows the problem?
    4. When you say it worked with RAD and WebSphere, do you mean that the same project ran successfully on WebSphere when launched from RAD, but failed on JBoss when launched from MyEclipse?
    #351212 Reply

    eugenejsn
    Participant

    –When you say it worked with RAD and WebSphere, do you mean that the same project ran successfully on WebSphere when launched from RAD, but failed on JBoss when launched from MyEclipse?

    –Yes.

    Here is the layout of my projects.

    WebApp
    L (contains the WebContent root, WEB-INF, src, etc)

    WebApp/src/TestController.java

    TestObj obj = new TestObj(); //This is a POJO
    Class beanClass = obj.getClass();
    Method[] beanMethods = beanClass.getMethods();

    The above snippet will work, IF I place the TestObj in the WebApp/src/.

    In reality, I have another project inside the workspace, called ClassDomain which contains the java classes.

    Now I move the TestObj.java to ClassDomain/src/, i.e.,

    ClassDomain/src/TestObj.java

    Then backto WebApp/src/TestController.java

    import domain_path_here.TestObj;

    TestObj obj = new TestObj(); //This is a POJO
    Class beanClass = obj.getClass();
    Method[] beanMethods = beanClass.getMethods();

    This line Method[] beanMethods = beanClass.getMethods();
    will fail for no specific reason. (I do not get any message back, it simply faied). I used the debugger to trace it, it always failed at this line. But no message.

    Now the WebApp project setting:

    Project Reference: ClassDomain
    Libraries: Web App Libraries
    EAR LIbraries
    JBoss & Runtime
    Java EE 7 Generic Lib
    ClassDomain
    JRE System Lib

    MyEclipse/Deployment Assembly
    L /src (WEB-INF/classes)
    /WebContent (/)

    ClassDomain project setting:

    Project Reference:
    Libraries: Web App Libraries
    EAR LIbraries
    JBoss & Runtime
    Java EE 7 Generic Lib
    ClassDomain
    JRE System Lib

    MyEclipse/Deployment Assembly
    L /src (/)

    This looks like a project reference issue. But import domain_path_here.TestObj; indicate no error.

    I believe somehow I did not set the project reference properly. For instance, I create another java project TestDomain inside the same workspace, then create a simple class Test.java and reference this project from the WebApp project. Go to the TestController.java and tries to import this class Test.java, it indicates that the Test is undefined even if I tries the Importing.

    If respond to me by end of Friday, would be appreciated so that I can continue working on it on the weekend.

    Thanks

    Eugene

    #351214 Reply

    support-tony
    Keymaster

    Eugene,

    I’m looking at this outside normal work hours so haven’t got time to investigate it in more detail, sorry. But i just want to ask again what you mean by “fail”. If you are stepping through with the debugger, what happens when you step over the beanClass.getMethods call? Is there an exception? Does it return null or an empty array? The statement that it fails doesn’t really tell me very much to be able to investigate this, though I’ll try to replicate your set up when I get back to work.

    If you can set up a couple of simple projects to replicate the issue and attach them, that might help.

    #351215 Reply

    boby147
    Member

    This line Method[] beanMethods = beanClass.getMethods();
    will fail for no specific reason. (I do not get any message back, it simply faied). I used the debugger to trace it, it always failed at this line. But no message.

    #351216 Reply

    eugenejsn
    Participant

    Thanks Tony for the hard work.

    If you put an Oracle

    private BLOB imgFile;

    on the TestObj as I mentioned earlier.

    Then the reflection lookup from the controller class will fail the getMethods function for no specific reason.

    Thanks

    #351220 Reply

    support-tony
    Keymaster

    Eugene,

    Just checking in on this topic, will try to do more on Monday. I’m confused about what is meant by “fail” when you say the getMethods call is failing. You seem to say that there is no exception, no message, but then how do you know that the method call fails? During execution, a failure is indicated by some exception or the return of a value that you know cannot possibly be correct (though one has to be careful there) or the program suddenly ending at the point of the call, though, even there, there would likely be some core dump.

    So how do you know that the call is failing?

    #351221 Reply

    eugenejsn
    Participant

    Hi Tony,

    Once again, thanks for your good effort.

    At this point I decide to close this issue. It could be a complex issue. I’ll find some workaround for this.

    I have two high priority issues which I posted on the forum. One is the JSP debugging does not stop at the break point, though I follow the normal procedure to set it up (https://www.genuitec.com/forums/topic/debug-does-not-stop-on-jsp/).

    The second issue is Output A Java Project’s Classes to WEB-INF/classes (https://www.genuitec.com/forums/topic/output-a-java-project-s-classes-to-web-inf-classes/).

    Thanks

    Eugene

    #351227 Reply

    support-tony
    Keymaster

    Euguene,

    Was just about to start looking at this again but I’ll close it as requested. However, I’m still confused by the term “fail”, for the reasons I mentioned. If you can expand on how you know the call fails, please PM me.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: Java Class Reflex getMethods not Work on MyEclipse

This topic is marked as closed to new replies, however your posting capabilities still allow you to do so.

You must be logged in to post in the forum log in