javaidewid

Why is method added to .java file not present in .class file after a build, or accessible after package is imported?


I have a project I am working on in WebSphere Integration Developer 7.0 where I am trying to reference a public method I just wrote from a different package. I have an import statement included for the class my new method is in.

When I create an instance of my class and try to call my new method, I get a standard "method 'x' is undefined for the type 'y'" compiler error, indicating my new method isn't being recognized.

What's really peculiar to me is that when I press F3 to open the declaration of my class instance, I'm taken to the class declaration in the .class file rather than the .java file. I tried calling several other non-static methods from my class instance, which were recognized and also took me to the .class file when I opened their declarations. I have my .class and .java files for this class in the same directory.

I have cleaned and rebuilt the project to see if that would have any affect, but still see the same behavior.

So my question is, why would my IDE open the class and method declarations in the .class file rather than the .java file? I've never seen that before - could that be expected behavior within WID in this case, or does that suggest a problem with my environment?


Solution

  • Why the IDE opens the .class file

    Because, that is what the IDE finds listed in the build path.

    It is very common behaviour.

    For example, lets say we have 2 projects - project F and project B.

    Project `F` - front end
    Project `B` - back end
    

    Now, F depends on B for its compilation but B can be compiled independently.

    So, in order to build F, we first build B and then copy the artifacts generated as part of the build in the build path of F or if we don't want to do copy/ paste, we just make F's build path point to the artifact generated by B's build.

    Now, we can build F. Here, what F actually points to are a bunch of class files not the source.

    And, now if we try to access any files of B from F - IDE will intelligently open the .class file(s) for us.