This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 13875
    
  10

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: 36486
    
  16
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: 13875
    
  10

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

Joined: Oct 13, 2005
Posts: 36486
    
  16
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: 36486
    
  16
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java JAR file - Can I view .java classes
 
Similar Threads
running from .jar file has missing classes
how to make a jar pop-up console ?
how to pass the arguments to the main class ...
How to eliminiate the background ms-dos window
How to create a jar file of a java project that uses Derby database