This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 14074
    
  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: 38045
    
  22
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: 14074
    
  16

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

Joined: Oct 13, 2005
Posts: 38045
    
  22
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: 38045
    
  22
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java JAR file - Can I view .java classes
 
Similar Threads
How to create a jar file of a java project that uses Derby database
how to pass the arguments to the main class ...
running from .jar file has missing classes
how to make a jar pop-up console ?
How to eliminiate the background ms-dos window