• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

import libraries

 
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to add two libraries to classpath. one is zip file and another is jar file. how m i supposed to do it? java5 and im not using any IDE.
 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Noopur Kore wrote:i want to add two libraries to classpath. one is zip file and another is jar file. how m i supposed to do it?


-cp classpath
Specify a list of directories, JAR archives, and ZIP archives to search for class files. Class path entries are separated by semicolons (;). Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable.
If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.).
hope this helps
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Noopur Kore wrote:i want to add two libraries to classpath. one is zip file and another is jar file. how m i supposed to do it? java5 and im not using any IDE.


While running your code (by using 'java' command), you can provide those libraries by either -cp or -classpath command line argument.
You can also check the help message of java executable.

On a side-note, any specific reason for using a Java version which is deprecated long time back(Java 5)?
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:Class path entries are separated by semicolons (;).


On Windows. On *nix based systems it's a colon (:)
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just want to add what naved said, if you specify -cp or -classpath switch it will override any values you set either through environement variable or through command prompt. also it will override the default value of classpth which is current directory. so if you want to include the current directory in your classpath then you should include the current directory in the classpath . here is a sample for you

java -cp c:/Projects;d:/test;d:/test/My.jar HelloWorld



Also keep in mind that if you have organized your classes into packages, then the classpath should contain the directory WHICH IS THE PARENT OF THE PACKAGE ROOT. for e.g suppose you have a classfile like com.aladeen.Test . also consider the following file system hierarchy Guru>com>aladeen>Test. then you have to include the Guru directory in your classpath, since Guru directory is the parent of the package root(i.e com). i know it is confusing. if you get it,well and good , if not then post it, will post in a much better way.
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:java -cp c:/Projects;d:/test;d:/test/My.jar HelloWorld


On Windows you really need to use \ in paths. Java code (with java.io.File) is lenient enough to let you use /, but the command line definitely isn't. So: java -cp c:\Projects;d:\test;d:\test\My.jar HelloWorld.
 
Nandita Tiwari
Ranch Hand
Posts: 77
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where should i giive the -cp or -classpath command??
java 5 becoz im using oracle 10g and it library supports java 1.5.. so i thot i better use older version inspite of having the new one..
 
lowercase baba
Posts: 13081
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Noopur Kore wrote:where should i giive the -cp or -classpath command??


Did you read Rob's post? He very clearly shows you where to put it.

Not that it is not a COMMAND, but an argument/flag given to the java program.
 
Rancher
Posts: 1043
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:
On Windows you really need to use \ in paths. Java code (with java.io.File) is lenient enough to let you use /, but the command line definitely isn't.



Isn't it definitely? Windows XP's cmd.exe seems to handle them the same way. The invoked class is found with both was of setting the class path:

>java15 -cp build\WEB-INF\classes hu.khb.szep.common.CommonTool
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at hu.khb.szep.common.CommonTool.<clinit>(CommonTool.java:11)

>java15 -cp build/WEB-INF/classes hu.khb.szep.common.CommonTool
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at hu.khb.szep.common.CommonTool.<clinit>(CommonTool.java:11)
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic