*
The moose likes Beginning Java and the fly likes Java JAR file - Can I view .java classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java JAR file - Can I view .java classes" Watch "Java JAR file - Can I view .java classes" New topic
Author

Java JAR file - Can I view .java classes

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Hello,

I have just been given the task of extending an existing java application. The current application is run by executing a jar file.

My question is - can I get my hands on the .java files and add functionality just by doing something to the .jar file?


OCPJP 6, OCMJD
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14118
    
  16

Normally not, the jar file will just contain the compiled code, not the *.java source files. You'll have to find out where to get the source code of the application.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
A .jar has the same format as a .zip (plus a manifest file). So you can easily unzip it. The Java™ Tutorials section has a subsection about "extracting", which should help you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14118
    
  16

Yes, but it will normally not contain the source files of the program.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Yes, I missed that bit. Best to contact the original supplier to request the code.
But you ought to be able to extend classes without seeing their source code. You only need to read their documentation, created with the javadoc tool.
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Thats what I suspected but didnt want to look the fool in front of my new employers. Thanks guys!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java JAR file - Can I view .java classes