Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: employing library jar from windows command line

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default employing library jar from windows command line

    I have never used a jar based library before. After having had problems getting javac to compile a .class properly, I got that figured out and got a successful compile with this batch file:


    C:\z\java\jdk1.6.0\bin\javac -classpath C:\z\marc4j\marc4j-2.4\lib\normalizer.ja
    r;C:\z\marc4j\marc4j-2.4\marc4j.jar %1.java

    To execute with java, I made this "run" batch file:

    C:\z\java\jdk1.6.0\bin\java -classpath C:\z\marc4j\marc4j-2.4\lib\normalizer.jar
    ;C:\z\marc4j\marc4j-2.4\marc4j.jar %1


    This produces the following response:

    Exception in thread "main" java.lang.NoClassDefFoundError: hw

    The source I'm compiling is called "hw.java" and looks like this:



    import org.marc4j.MarcReader;

    class hw
    {
    public static void main(String [] args)
    {
    System.out.println("It runs!");
    }
    }


    Everything seems ok to me, so where did I go wrong?


    TIA


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: employing library jar from windows command line

    C:\z\java\jdk1.6.0\bin\java -classpath C:\z\marc4j\marc4j-2.4\lib\normalizer.jar
    ;C:\z\marc4j\marc4j-2.4\marc4j.jar %1
    Did you jar up the file? YIf so, you have to specify the -jar option to the java command to run jars. If not, and this is just a .class file, remove the .jar extension when you try to run

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: employing library jar from windows command line

    Where is the hw.class file?

  4. #4
    Member
    Join Date
    Jul 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: employing library jar from windows command line

    Somebody else put it in a jar, I'm just trying to get it out. If I would have the source, I'd compile it the old fashioned way. Class files I'm pretty much used to, or at least they have worked until now. I will try -jar and see how it goes. Hmmm, so javac does not do it, but java does. Tricky. I appreciate the advice.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: employing library jar from windows command line

    javac does not do it, but java does
    What is the "do it" you refer to?

  6. #6
    Member
    Join Date
    Jul 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: employing library jar from windows command line

    Quote Originally Posted by Norm View Post
    Where is the hw.class file?
    After javac runs successfully, hw.class appears by magic. same as usual. Sorry, I did not provide dir output along the way.

  7. #7
    Member
    Join Date
    Jul 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: employing library jar from windows command line

    Have a -jar extension/argument. Sorry for the imprecision.

Similar Threads

  1. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  2. jre version in command line
    By major in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 14th, 2011, 06:55 AM
  3. specify native library in java command line
    By major in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 14th, 2011, 06:45 AM
  4. problem for writing to parallel port LPT1 on windows by RXTX library
    By sahar_m in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: April 20th, 2010, 04:31 AM
  5. [SOLVED] Command Line Argument Help
    By EmSaint in forum Loops & Control Statements
    Replies: 2
    Last Post: January 28th, 2010, 10:55 AM