• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jar Question

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Jana Smith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jana Smith
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. That is interesting. Anyway, I learned something new today. Thanks to all of you who helped me through this mini-jar journey....
 
reply
    Bookmark Topic Watch Topic
  • New Topic