This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Jar Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Jar Question" Watch "Jar Question" New topic
Author

Jar Question

Jana Smith
Greenhorn

Joined: Aug 24, 2003
Posts: 16
How do you open a jar file? Is it through javaw for the command line? If you do open it through javaw, and it comes up saying that it couldn't find
main class, what does that mean? That it lacks the main statement? Why would you jar a file that lacks it then, since it can't be opened.
How do you import it through Eclipse? TIA for any help. I'm really really confused........and any input would be really really helpful... Can anyone recommend a really basic book on Eclipse?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Originally posted by Jana Smith:
How do you open a jar file? Is it through javaw for the command line? If you do open it through javaw, and it comes up saying that it couldn't find main class, what does that mean? That it lacks the main statement? Why would you jar a file that lacks it then, since it can't be opened.


To see what is inside a jar file you can use Winzip or Pkunzip or the command line command: jar -xvf {jarfile}.jar

javaw is used to run an executable jar file. I think that is not what you are trying to do. You cannot run just any old jar file that way. It has to be jarred with an extra file in it telling the javaw which class contains the main() method. Apparently the jar file you're looking at doesn't have that extra file in it, so javaw doesn't know which class to start with. Hence the error message.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Originally posted by Jana Smith:
How do you import it through Eclipse? TIA for any help. I'm really really confused........and any input would be really really helpful... Can anyone recommend a really basic book on Eclipse?


I can't help with the Eclipse part of your question. But I'm sure if you go down to the "IDE's and other tools" forum and poke around a little (you could even use the search link and search for "Eclipse book" -- without the quotes), you'd find lots of useful information on how to use Eclipse.
Jana Smith
Greenhorn

Joined: Aug 24, 2003
Posts: 16
I looked at the program that I was trying to open, and it is an executable jar file. When I right-click it, and the properties open up, it says that it can be opened with javaw, hence the reason why I thought it could be opened with it. Otherwise, I have no clue what to do at all. Is javaw even a command line statement? I think the error message states, according to where I put it, that it can't find the main file in it. So it seems to expect the main file every time I try to open it. I hope this makes some sense to you because I have no clue what I'm even saying now. I'm sorry. If anyone can figure out this........I would be so mega grateful.
Otherwise to simplify this whole thing, how do you simply open a executable jar file?
TIA.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30


I looked at the program that I was trying to open, and it is an executable jar file. When I right-click it, and the properties open up, it says that it can be opened with javaw, hence the reason why I thought it could be opened with it.

What you've described is just the fact that Windows is set up to believe that all jar files should be opened by launching with javaw. This is not really true, but Windows doesn't have enough knowledge of jar files to understand that some are meant to be used as applications, and some are just meant as Java libraries (kind of like the difference between .exe and .dll files; in Java, they both have the same extension.)
A jar file is actually just a ZIP file, and as has been pointed out, can be examined with winzip. Inside the jar file is a META-INF directory, and in there is a MANIFEST.MF file. Inside the MANIFEST.MF, there may or may not be a line like
Main-Class: com.something.SomeClass
If there's a line like that, then the jar is meant to be executable, otherwise, it's not. In your case, it sounds like it's not.
OK, so, Eclipse books: Joe Pluta's Eclipse: Step by Step is as basic as they come, and a really great guide to getting started.


[Jess in Action][AskingGoodQuestions]
Jana Smith
Greenhorn

Joined: Aug 24, 2003
Posts: 16
Ok. I opened it with winzip. There was no META-INF, and I don't understand the significance of that. What is it anyway? There was a Manifest.MF file through, but it's not something that I can read. As for the classes in the file, there were several and I was able to read them all through Notepad.
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
Hi,
as fars as META-INF is concerned.. those are there in JAR failes only when it is an EJB JAR.. in that META-INF we have Deployment descriptors for EJB.. and for adding jars in eclipse.. u need to do simple thing..
(I am assuming that you have added a project space in eclipse...)
1. right click on eclipse project that you have added
2. select properties
3. then in the pop-up select Java Build Path
4. then click on libraries tag
5. there you get a button as Add Jars
now locate the file and you are done..
i hope i am clear.. if still in doubt .. please revert back
Thanks


****************************<br />In 24 hrs Earth rotates once on its Axis.
Jana Smith
Greenhorn

Joined: Aug 24, 2003
Posts: 16
Ok, I did what you suggested, adding a project, right-clicking it to add the external jar file. But, when I see the files in Eclipse, I only see the methods and variables and the getters and setters. However, I can't see the code in the file. How do I see that? Thanks for the help that I have received already. I really appreciate it.
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
hi...
do u mean u want to see the codes of the files in jar???
if it is so... then u have to keep in mind that normally we put only class files in Jar and not java files (but many people put both.)
so to open a jar file you need to just open the jar with the halp of winzip or pkzip or similar utility.. and then if there are any java files then you can open in any standard text editor.. but if they are class files then opening those files in any editor won't be of any help.. you need to open those files with the help of java decompiler..
but make sure u r not violating any copyright rules by using the decompiler..
thnx..
Amit
Jana Smith
Greenhorn

Joined: Aug 24, 2003
Posts: 16
Sorry for the confusion. I actually meant the class files. I did everything as you suggested, and only saw as what I already stated, the variables, methods, etc.. I didn't see the class files itself. I know there are there, because as I said earlier, I read them in Notepad. I just wanted to read them in Eclipse as well know how to open it in Eclipse. Does that make sense? Thanks for the help. I'm sorry if my questions are dumb.....I really don't know all this...
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
hiii again..
there is no way u can open and see a code in eclipse.. atleast i don't know any way to do it.. but if you want to do it anyay..
then u have to open the jar through the winzip kind of utility.save the files in class file format and then use a Java Decompiler
its a freeware and you can get it on
Java Decompiler Download
i hope that will be useful to you..
Thanks
Amit
Jana Smith
Greenhorn

Joined: Aug 24, 2003
Posts: 16
Thank you. That is interesting. Anyway, I learned something new today. Thanks to all of you who helped me through this mini-jar journey....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar Question
 
Similar Threads
Jar executible file
Netbeans Experts...
could not find the main class
DOS window still coming when I run the Application using javaw
jar runs on desktop but not laptop