Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

.jar files (question from a java newbie)

Options
  • 05-11-2007 12:54am
    #1
    Registered Users Posts: 96 ✭✭


    Hey guys,

    I just started a course in DCU in computer applications (beginning with java in the programming side of things), and while I was away in New York for four days, the class moved onto programs utilising graphics.jar. Now, while I have this .jar file, for some reason the javac command in cmd is telling me there's no such thing in response to my "import graphics*;" instruction in my program. I've tried everything I can think of, including putting my code and the .jar into the same folder, and nothing has worked. I'm in imminent danger of falling behind if I can't sort this so I thought you guys would be the people to ask.

    So, how do I get the compiler to see graphics.jar shining brightly on my hard drive?

    Any help is much, much appreciated, I'm getting very worried at this stage after two days of fruitless internet searching...


Comments

  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    What version of Java?
    Is it an application or applet?

    1. Removed - refer to post below (See also: javadoc / API on java.sun.com). Also: http://en.wikipedia.org/wiki/Java_package
    2. http://www.freshsources.com/Sep99.html - pay particular attention to the section re: classpath and http://en.wikipedia.org/wiki/Classpath_%28Java%29


  • Registered Users Posts: 11,980 ✭✭✭✭Giblet


    Open the jar file with winrar. There is probably a folder called com inside it. (it might not be, it can be anything, paste whats inside it here if you're stuck). If you want to use the library you have to know how it's stored inside that folder.
    So you may have to go import com.graphics.*;


  • Registered Users Posts: 96 ✭✭Wizoom


    OK, inside are two folders: graphics and META-INF

    Inside graphics are all the .class files. The enigmatic META-INF contains only MANIFEST.MF

    I tried the java -jar graphics.jar command as outlined in one of the wikipedia links, but got the following error, which makes me think something is wrong with this .jar?

    "Failed to load Main-Class manifest attribute from graphics.jar"

    Should I try re-downloading the .jar? Or is this a fairly standard error and I'm just grabbing the wrong end of the stick...?


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    you do something like.

    java -cp graphics.jar [insert class to run here]


  • Registered Users Posts: 96 ✭✭Wizoom


    Hobbes wrote: »
    you do something like.

    java -cp graphics.jar [insert class to run here]

    Thanks for that, but I tried it and no dice. I presume you meant classpath by cp? If so it still didn't work. It says it can't find it or something along those lines. It's like the computer just is not recognising this .jar at all. I'd say it must be a bad file, but all my classmates have it from the exact same source and didn't have to do a thing to make it work - it just did!


  • Advertisement
  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    Wizoom wrote: »
    Hey guys,

    I just started a course in DCU in computer applications (beginning with java in the programming side of things), and while I was away in New York for four days, the class moved onto programs utilising graphics.jar. Now, while I have this .jar file, for some reason the javac command in cmd is telling me there's no such thing in response to my "import graphics*;" instruction in my program. I've tried everything I can think of, including putting my code and the .jar into the same folder, and nothing has worked. I'm in imminent danger of falling behind if I can't sort this so I thought you guys would be the people to ask.

    So, how do I get the compiler to see graphics.jar shining brightly on my hard drive?

    Any help is much, much appreciated, I'm getting very worried at this stage after two days of fruitless internet searching...

    Not sure if this is just a post typo or not but "import graphics*;" should be "import graphics.*;" The dot is very important :)
    Wizoom wrote: »
    OK, inside are two folders: graphics and META-INF

    Inside graphics are all the .class files. The enigmatic META-INF contains only MANIFEST.MF

    I tried the java -jar graphics.jar command as outlined in one of the wikipedia links, but got the following error, which makes me think something is wrong with this .jar?

    "Failed to load Main-Class manifest attribute from graphics.jar"

    Should I try re-downloading the .jar? Or is this a fairly standard error and I'm just grabbing the wrong end of the stick...?

    No need to re-download the jar, if it was corrupt then Winzip would not have been able to open it to view the folders inside.

    The reason for the error "Failed to load Main-Class manifest attribute from graphics.jar", is that if a jar file is meant to be executable, in the META-INF/MANIFEST.MF file contained within the jar it will have a Main-Class: attribute declared. This tells the JVM which class in the jar file contains the main() method used to run the application. This would be of the the form Main-Class:com.package.mainclass.

    As there is no such attributes in the graphics.jar file (the author did not intend it to be directly executable), it implies that it is only a library jar file. That is to say that it is not an application you can run, but rather contains helper classes that you can use to build your own application (I assume from the name it contains classes like square, circle etc).

    As you know, to compile your own class you would have to include the graphics jar in the classpath (assumes you are in the same directory as MyClass.java):

    javac -classpath .;<PATH>\graphics.jar MyClass.java (PATH is the full path to the folder containing the jar, the "." in the classpath tells the compiller to look in the current directory for classes as well, so it will be able to find the MyClass.java source file).


Advertisement