1

Well, I had just finished coding a java project and went into testing it using eclipse. It was exporting fine and I went ahead and created a new file in src named "config.yml" and it all of a sudden removed all the .java files in my project!

Fortunately, I still have the .jar which contains all the .class files, but I seem to be unable to edit the code (i'm guessing this is to do with it being a .class instead of .java) so, is there any way I can transfer these .classes back to .java ?

btw, if you're recommending any software please note that i'm on a macbook so i'll be limited to what i can use..

Zong
  • 6,160
  • 5
  • 32
  • 46
user2993584
  • 139
  • 2
  • 5
  • 13
  • Maybe take a look at this question, right here http://stackoverflow.com/questions/6225537/convert-class-to-java – user4090 Mar 01 '14 at 23:38
  • Look in the src folder for the project and check if the files are still there. Decompiling Java (what you're asking for, going from compiled back to source code) is generally possible but has lots of pitfalls and potential problems. – OSborn Mar 01 '14 at 23:39
  • 3
    And let this be a lesson in why you should use version control such as git or svn. – indivisible Mar 01 '14 at 23:39
  • Be aware that java is particularly kind in this regard; most other programming languages and you would be having a very bad day right now – Richard Tingle May 07 '14 at 13:22

1 Answers1

2

Try this (JD-GUI). Have a Mac version and it's nice.

It will show to you the code from the class file.

Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
  • Thanks for the reply, downloaded and opened up my .jar with it, I can see that it's got the .java files back but how do I actually use them? o.o (in other words how do I actually get the .java files out?) – user2993584 Mar 01 '14 at 23:46
  • 1
    Try: `File -> Save all sources` (In Windows, could change in mac version but search for this).. Anyway remember you are reading `.class` files somethings are differents from original `.java` files. – Marco Acierno Mar 01 '14 at 23:48
  • Thanks so much! exactly what I was hoping for :) worked perfectly – user2993584 Mar 02 '14 at 00:02