Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2007

Tip: Looking for answers? Try searching our database.

Newbie: -classpath option of java does not load the content of the jar file

Thread view: 
Guy - 26 Jun 2007 21:42 GMT
I have the following command:
 java j -classpath ojdbc14.jar

The file "ojdbc14.jar" is in my current directory. If I use the
verbose mode, I can see that the odbc package is not getting loaded.

If I un-jar the content of ojdbc14.jar in my current directory and run
in verbose mode, I can see it is being loaded:

Start...
[Loaded java.lang.Package from C:\Program Files\Java\jre1.5.0_10\lib
\rt.jar]
[Loaded java.sql.Driver from C:\Program Files\Java\jre1.5.0_10\lib
\rt.jar]
[Loaded oracle.jdbc.driver.OracleDriver from file:/C:/_t/Java/

Why do I need to un-jar the package ?

Thanks
Andrew Thompson - 27 Jun 2007 03:45 GMT
>I have the following command:
>  java j -classpath ojdbc14.jar

'j' is a class name?  When posting asking for
technical advice, it pays to use meaningful
names, even if the most meaning you can
think up is 'FirstTestDBAccess'.  Not that
the member name j suggests either a
(poorly named) method or attribute from the
nomenclature, and is easily confused with an
option to Java when used as above.

In any case, I suspect you need this..

rem: put the options *first*
java -classpath ojdbc14.jar j

...
>Why do I need to un-jar the package ?

Try not jumping to conclusions - it will waste
a lot of time.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Roedy Green - 27 Jun 2007 07:18 GMT
>I have the following command:
>  java j -classpath ojdbc14.jar

see http://mindprod.com/jgloss/classpath.html

It processes the line left to right, so needs to know the classpath
before it can process the class file.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Guy - 27 Jun 2007 13:28 GMT
That does not work either:
  C:\_t\Java> java -classpath ojdbc14.jar j
  Exception in thread "main" java.lang.NoClassDefFoundError: j

The "j" class is just a quick stub I use to test Java things (I
program mostly in Delphi), then I import the result into my real Java
app:

import java.util.*;
import java.io.*;

import java.sql.*;
import oracle.jdbc.driver.OracleDriver;

public class j
{
   public static String OracleDriverName =
       "oracle.jdbc.driver.OracleDriver";

   public static void main(String args[])
   {

     System.out.println("Start...");
       LoadOracleDriver();
     System.out.println("End...");

   }

 public static boolean LoadOracleDriver ()
 {
     boolean bStatus = true;

     try
     {
         Class.forName(OracleDriverName);
     }
     catch ( ClassNotFoundException ex )
     {
         System.out.println(ex);
         bStatus = false;
     }

     return bStatus;
   }
}
Andrew Thompson - 27 Jun 2007 14:28 GMT
...
>   C:\_t\Java> java -classpath ojdbc14.jar j
>   Exception in thread "main" java.lang.NoClassDefFoundError: j

OK, so you are saying the files ojdbc14.jar
& j.class are located at..

C:\_t\Java\ojdbc14.jar
&
C:\_t\Java\j.class

..respectively?

Or is j.class located in the ojdbc14.jar?

Also note that the mindprod site has a page
devoted to many of the most common compilation
and runtime errors.  Or rather, two pages, that
provide *links* to the page containing the
information on each problem - it is far too
much info. to put all the answers on one
page!

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Guy - 27 Jun 2007 15:59 GMT
Yes everything is located in the same directory:

 j.class
 j.java
 ojdbc14.jar
 META-INF
 oracle

Your web site has been blocked by our MIS departement. Dont know why.
printdude1968@gmail.com - 27 Jun 2007 16:21 GMT
> Yes everything is located in the same directory:
>
[quoted text clipped - 5 lines]
>
> Your web site has been blocked by our MIS departement. Dont know why.

If everything is in the same directory, then you need to specify the
path of the directory when you are specifying the classpath.
Otherwise, I think, java will look on your platform path or
classpath.  Since it would appear that you have everything in the same
space, why not just say -cp ./  and be done with it?
Nigel Wade - 27 Jun 2007 17:03 GMT
>> Yes everything is located in the same directory:
>>
[quoted text clipped - 11 lines]
> classpath.  Since it would appear that you have everything in the same
> space, why not just say -cp ./  and be done with it?

That wouldn't look in jar files in ".", only class files.

What is required in the classpath is both "." and the jar-file. The arguments to
the java command must precede the main class as everything on the command line
following the main class is passed to the main class in the args array.

java -classpath .:ojdbc14.jar j

should work, although Windows command shell may require some quotes around the
argument.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Guy - 27 Jun 2007 17:50 GMT
Works!

Using this form:
 java -classpath .;.\ojdbc14.jar j

Thanks!

Ref:
http://groups.google.com/group/comp.lang.java.help/browse_thread/thread/a9110381
760eb49f/822340483e8b7fd9?lnk=st&q=java+windows+classpath&rnum=3&hl=en#822340483
e8b7fd9

printdude1968@gmail.com - 27 Jun 2007 18:21 GMT
> Works!
>
[quoted text clipped - 4 lines]
>
> Ref:http://groups.google.com/group/comp.lang.java.help/browse_thread/thre...

And *nix would be java -classpath .:./ojdbc14.jar j ?
Roedy Green - 28 Jun 2007 14:51 GMT
>lso note that the mindprod site has a page
>devoted to many of the most common compilation
[quoted text clipped - 3 lines]
>much info. to put all the answers on one
>page!

How would you suggest smashing that up?  I suppose the alpha index for
run time and compile time can each stay on one page.  Should each
error get its own page and master index entry?  Is there some logical
way to group errors on pages?

I have written a utility called SPLIT that takes this sort of work
less painful.  http://mindprod.com/products.html#SPLIT
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.