New to Java, Confused about jar files and packages.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: New to Java, Confused about jar files and packages.

  1. #1
    Join Date
    Oct 2010
    Posts
    18

    Lightbulb New to Java, Confused about jar files and packages.

    I have a file by name MSWord.java:

    Class name MSWord

    package org.jinterop.dcom.test;

    This file is located at C:\Documents and Settings\xxxx\Desktop\Java Files New

    Environment Variable: Value:

    CLASSPATH .;C:\Program Files\QuickTime\QTSystem\QTJava.zip;C:\Documents and Settings\xxxx\Desktop\j-Interop\lib\j-interop.jar;C:\Documents and Settings\xxxx\Desktop\j-Interop\lib\jcifs-1.2.19.jar;C:\Documents and Settings\xxxx\Desktop\j-Interop\lib\j-interopdeps.jar;C:\Documents and Settings\xxxx\Desktop\j-Interop\lib\progIdVsClsidDB.properties;C:\glassfishv3\jdk\bin;C:\glassfishv3\jdk\lib;

    JAVA_HOME C:\glassfishv3\jdk\

    Path %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\gwt-2.1.0;%ANT_HOME%\bin;C:\Program Files\Java\jre6\bin;C:\glassfishv3\jdk\bin;C:\glassfishv3\jdk\lib;

    when i execute the file in command prompt

    C:\Documents and Settings\xxxx\Desktop\Java Files New>java 0rg.jinterop.dcom.test.MSWord

    it has executed without any error and everything is working fine.

    Now i copied MSWord,java and replaced MSWord class with CSFT class. I have rewritten all the methods with respect my new class and saved the file as CSFT.java.

    now while executing the new file

    C:\Documents and Settings\xxxx\Desktop\Java Files New>java 0rg.jinterop.dcom.test.CSFT

    it throws an error saying

    C:\Documents and Settings\kumar\Desktop\Java Files New>java org.jinterop.dcom.test.CSFT

    Exception in thread "main" java.lang.NoClassDefFoundError: org/jinterop/dcom/tes
    t/CSFT
    Caused by: java.lang.ClassNotFoundException: org.jinterop.dcom.test.CSFT
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: org.jinterop.dcom.test.ControlSoft. Program will
    exit.

    I dont understand where is the realtion for the package and the classpath etc. Why am i getting the error and what should i do to execute my new file.

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: New to Java, Confused about jar files and packages.

    The Java command doesn't run the .java file it runs the .class file which must be in a directory structure based on the package name. Therefore, somewhere on the classpath there is a a directory structure of org.jinterop.dcom.test which contains the class file MSWord.class.

    You need to do something similar with your CSFT.class file
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Oct 2010
    Posts
    18

    Lightbulb Re: New to Java, Confused about jar files and packages.

    Thanks for the quick response, you were right the directory structure

    org/jinterop/dcom/test/MSWord.class is present in j-Interop.jar which is present in the classpath.

    Now how do i get my new class here, do i have to generate a new jar file. j-Interop.jar is located at C:\Documents and Settings\xxxx\Desktop\j-Interop. But MSWord.java is not present anywhere in the directory of j-interop.jar, an execute.bat file of MSWord.java is present in the directory of j-interop.


    Can you please help me further.

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: New to Java, Confused about jar files and packages.

    You shouldn't try to put your class file in jar file that isn't under your control. For a start it may be signed in which case adding your file will break the jar.

    You can solve your problem by creating the directory structure on your hard disk and putting the class file in 'test' directory. The root of this directory structure, the 'org' directory must be in a directory that is on the classpath.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Oct 2010
    Posts
    18

    Re: New to Java, Confused about jar files and packages.

    Cool, created a directory like you said, compiled a produced the class file and now i was able to execute it.

    If i need any more help will ask you here.

    Thanks alot for the information.

  6. #6
    Join Date
    Dec 2010
    Posts
    2

    Thumbs up Re: New to Java, Confused about jar files and packages.

    Quote Originally Posted by keang View Post
    The Java command doesn't run the .java file it runs the .class file which must be in a directory structure based on the package name. Therefore, somewhere on the classpath there is a a directory structure of org.jinterop.dcom.test which contains the class file MSWord.class.

    You need to do something similar with your CSFT.class file
    Right.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center