-
December 3rd, 2010, 11:12 AM
#1
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.
-
December 3rd, 2010, 11:26 AM
#2
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
-
December 3rd, 2010, 11:50 AM
#3
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.
-
December 3rd, 2010, 12:04 PM
#4
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.
-
December 3rd, 2010, 12:22 PM
#5
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.
-
December 4th, 2010, 02:13 AM
#6
Re: New to Java, Confused about jar files and packages.
Originally Posted by keang
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|