• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java classpath

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Desktop
|
|
foo
|
|
test
|
|
xcom
|
|--Test.java
|
|--Test.class
|
|--Testing.java
|
|--Testing.class







C:\Documents and Settings\himalay\Desktop\foo>java test\xcom\Testing foo\test\xcom\Test --> works fine

But..when I use the classpath option..it fails

C:\Documents and Settings\himalay\Desktop\foo>java -classpath .;test\xcom\Testing foo\test\xcom\Test--> fails

How should I use the java -classpath command properly
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


C:\Documents and Settings\himalay\Desktop\foo>java test\xcom\Testing foo\test\xcom\Test --> works fine



What do you do here ? Here you are executing Testing.class passing "foo\test\xcom\Test" as argument to Testing class . is it what intended to do ?



C:\Documents and Settings\himalay\Desktop\foo>java -classpath .;test\xcom\Testing foo\test\xcom\Test--> fails

How should I use the java -classpath command properly



Classpath should point to the top-level of the package . so "." should be enough. The syntax to call is
java -classpath . test.xcom.Testing
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Balu.. Yeah.I messed up myself with the syntax here.

While working with javac -classpath..the package name is appended in the search class path.
I want to check if the same happens when we use java -classpath.....

C:\Documents and Settings\himalay\Desktop\foo>java -classpath Testing test\xcom\Test

// Am expecting Testing.class will be searched after appending its path and Test.class will be executed as I have provided the complete path.
but...
Exception in thread "main" java.lang.NoClassDefFoundError: test\xcom\Test
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himalay Majumdar wrote:Thanks Balu.. Yeah.I messed up myself with the syntax here.

While working with javac -classpath..the package name is appended in the search class path.
I want to check if the same happens when we use java -classpath.....

C:\Documents and Settings\himalay\Desktop\foo>java -classpath Testing test\xcom\Test

// Am expecting Testing.class will be searched after appending its path and Test.class will be executed as I have provided the complete path.
but...
Exception in thread "main" java.lang.NoClassDefFoundError: test\xcom\Test



if you provide -classpath in your java ot javac , you are overriding the default classpath. At any case you should execute javac or java at top level of the package.

When using java , the classname should be provided with complete package name and not by directory name
java -classpath . test.xcom.Test // see use of package name as "." and not "/"

Testing class need not be included in -classpath as already "." covers the current directory. Any class from different package needs to be provided if Test ot Testing class refers it.

HTH

(i have edited the previous post)

 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[quote=Balu Sadhasivam
When using java , the classname should be provided with complete package name and not by directory name


Forgetting about classpath for a moment..if I execute the following

package test.xcom;

class Test {

public static void main(String args[])
{
System.out.println("test");

}

}

C:\Documents and Settings\himalay\Desktop\foo>java test.xcom.Test is working

When I make my current directory test it executes..

C:\Documents and Settings\himalay\Desktop\foo\test>java xcom.Test

so does that mean the complete package name is not required ?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himalay Majumdar wrote:

When I make my current directory test it executes..

C:\Documents and Settings\himalay\Desktop\foo\test>java xcom.Test

so does that mean the complete package name is not required ?



NO this will not execute. please be sure that there is no other class Test with xcom.Test as package in the CLASSPATH
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it. Thanks for the timely response Balu
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic