40

I have some .class files that I need to convert to .java so I did:

javap -c ClassName.class

and all the time I have the same error

ERROR:Could not find ClassName.class

Do you guys have any idea of what might be the cause? I did man javap and as far as I know, the syntax is correct. If there is another way to convert it to a .java file, I am more than willing to try.

fabricemarcelin
  • 1,719
  • 6
  • 25
  • 34
  • 2
    possible duplicate of [How do I "decompile" Java class files?](http://stackoverflow.com/questions/272535/how-do-i-decompile-java-class-files) – user Sep 19 '13 at 02:45
  • Try below online tool. It also seems good: **www.showmycode.com/** – Anu Jul 25 '17 at 04:07

5 Answers5

50

Invoking javap to read the bytecode

The javap command takes class-names without the .class extension. Try

javap -c ClassName

Converting .class files back to .java files

javap will however not give you the implementations of the methods in java-syntax. It will at most give it to you in JVM bytecode format.

To actually decompile (i.e., do the reverse of javac) you will have to use proper decompiler. See for instance the following related question:

Community
  • 1
  • 1
aioobe
  • 413,195
  • 112
  • 811
  • 826
  • 7
    I strongly disagree that `javap -c Classname` is a correct answer. You don't use `javap` to decompile files (translate the binary into source code). `javap` is merely a disassembler. This does not produce Java source code for you. You need a proper java decompiler such as jad or the likes. Maybe I'm not understanding something about `javap` after all these years, but I believe all the answers pointing it, are simply incorrect. – carlspring Feb 27 '13 at 18:38
  • 3
    Did you read the question? Did you read the part that says *"I have the same error `ERROR:Could not find ClassName.class` Do you guys have any idea of what might be the cause?"* Also, did you read the part of my answer which addresses how to actually decompile .class-files? Could you please clarify what you find incorrect about my answer? – aioobe Feb 27 '13 at 18:49
1

I'm guessing that either the class name is wrong - be sure to use the fully-resolved class name, with all packages - or it's not in the CLASSPATH so javap can't find it.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • 2
    `javap` takes arguments without the `.class` extension. (If you provide the `.class` extension it will yield that exact error message.) (And actually, it accepts non-fully qualified class names as long as it can find the .class file in the current directory) – aioobe Jun 03 '11 at 09:58
0

I used the http://www.javadecompilers.com but in some classes it gives you the message "could not load this classes..."

INSTEAD download Android Studio, navigate to the folder containing the java class file and double click it. The code will show in the right pane and I guess you can copy it an save it as a java file from there

0

Step 1: If your class file is inside a jar, rename the .jar extension to .zip and extract the zip folder Step 2: Using the below online decompiler, upload your .class file and read the contents http://www.javadecompilers.com/

Shiva
  • 31
  • 2
-1

This is for Mac users:

first of all you have to clarify where the class file is... so for example, in 'Terminal' (A Mac Application) you would type:

cd

then wherever you file is e.g:

cd /Users/CollarBlast/Desktop/JavaFiles/

then you would hit enter. After that you would do the command. e.g:

cd /Users/CollarBlast/Desktop/JavaFiles/ (then i would press enter...)

Then i would type the command:

javap -c JavaTestClassFile.class (then i would press enter again...)

and hopefully it should work!

demongolem
  • 9,474
  • 36
  • 90
  • 105
  • 1
    The only thing you've added to OP is to make sure that he's in the correct directory. I sincerely hope that wasn't the original problem. And you don't address the actual problem: he needs to leave `.class` off the end. – Teepeemm Sep 02 '13 at 02:32