Thursday, April 14, 2011

Eclipse opens .class instead of .java

One neat feature of Eclipse (and other IDEs) is that you can hold CTRL and click on a function or variable to go to its definition.

A problem which may occur in Eclipse is that it opens the .class file (the compiled file) instead of opening the .java file when you do this. This is probably caused by the order of the entries in the .classpath file.

Go to your project directory and open the .classpath file. Move all entires of type classpathentry with attribute kind="src" to the top of the file (or at least above any entries with kind "output").

Restart Eclipse and the problem should be fixed.


  1. It's not working, all my scr kind entries is on the top. :(

  2. @SaNNyO: Difficult to say why it might not work, here are some ideas:

    1. Are you sure you are editing the correct file? Make sure it's the one in the project you are looking at. :)
    You can apparently also do these changes by right-clicking your project in Eclipse, select Properties, select Java Build Path, select the Order and Export tab, and then move the folders to the top using the 'Up' button.

    2. A restart of Eclipse should catch any changes you do, but you might want to try to refresh the project too. Right-click the project and select 'Refresh'.

    3. Maybe you don't have the source for the class/method you are trying to open. This could happen if it is an added library (JAR) or part of Java Core. Check out to see if you can add the source to your JARs.

    Also see

  3. you can make it using eclipse it self without restarting
    right click on your project -> java build path -> order and export ->(select the type src) -> top ->ok

    1. @Shrif your're right, that should do it. I've noticed however that sometimes Eclipse needs a good restart to pick up on the changes you do.

      Your way keeps one from having to mess around in the file system and find the correct lines in the classpath file.

      Notice that in the Order and Export dialog in Eclipse, the source items will have folder icons just like in the project tree itself in Eclipse. Makes it easier to find the source items.

  4. Java file was opening properly previously and I have not made any changes then why it is opening class file. what is actual reason behind this?

  5. I’m really impressed with your blog article, such great & useful knowledge you mentioned here..Get more Java Training in Marathahalli
    Python Training in Marathahalli

  6. fter reading this blog I am very strong in this topics and this blog is really helpful to all.. Explanation are very clear so it is easy to understand.. Thanks for sharing this blog…

    White Label Website Builder

  7. Pretty nice post. I just stumbled upon your weblog and wanted to say that I have really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon! Gujarat Ration Card Status