1

I have a finished program which compiled successfully and works just fine. Out of interest, I wanted to see the bytecode in the project folder in eclipse (under the bin folder). I accidentally saved it as a .txt rather than a .class and now the jar file won't work! It's not an issue, i've fixed it but why does this happen?

TheSporech
  • 17
  • 5

1 Answers1

0

I presume it's simply because you changed the file extension, Eclipse couldn't find the .class file, and so it considered the .jar corrupt.

The output of a Java compiler is not executable code, but is actually bytecode. If Eclipse can't find this bytecode, it cannot execute your code.

I've found another answer that shows a plugin that will allow you to view bytecode using Eclipse in the future.

Community
  • 1
  • 1
DagdA
  • 484
  • 1
  • 7
  • 25
  • but won't a jar run standalone with just the JRE? If so why would the project folder have anything to do with the finished jar? – TheSporech Nov 24 '15 at 21:17
  • I misunderstood what you were asking. Am I right in saying you exported your Java Project as a .jar and then changed the file extension of a class file in the project? – DagdA Nov 24 '15 at 21:30
  • I must have done something i guess, tell me if i'm wrong. – TheSporech Nov 24 '15 at 22:33
  • You're right. That is odd. Was it a runnable jar file or just a library? – DagdA Nov 24 '15 at 22:36