File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problm with -d Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problm with -d" Watch "Problm with -d" New topic
Author

Problm with -d

Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
package com.wickedlySmart;

import java.lang.*;

public class MyClass
{
public static void main(String args[])
{
System.out.println("my class");
}}

It a simple code, which compiling fine but not running ,Class NOt found Error

I have code in Source Directory ,compiled and .class in Clsses Directory under same root directory.

I complied with javac -d Classes Source/com/wickedlySmart/MyClass.java
It worked

For running ,i tried many combinations but error

Java Classes/MyClass
Java Classes/com/wickedlySamrt/MyClass
....

How wud it run ...
THan you.
christian combarel
Ranch Hand

Joined: Aug 04, 2007
Posts: 47
Hello,

As your class is defined into a package, you have to tell it to the JVM in your classpath.

From the Classes directory, the command is :
java -cp . com.wickedlySamrt.MyClass

The -cp . option tell the JVM to look for the package from the current directory.
Then, you have to use the fully qualified name of the class where the dot (.) is the separator (not the / or \ !) :
com.wickedlySamrt.MyClass



-------------
Chris
Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
Got it
But ihave 2 more doubts now..

1.how can we runn it without CDing into Classes Directory.

2.Myclass is in Pkngs com.wickedlySmart While Running,DO we always have to write or prefx pacakge name, or if we set classpath to packages ,we wd be able to run it .

Thank you
christian combarel
Ranch Hand

Joined: Aug 04, 2007
Posts: 47
1.how can we runn it without CDing into Classes Directory.

2.Myclass is in Pkngs com.wickedlySmart While Running,DO we always have to write or prefx pacakge name, or if we set classpath to packages ,we wd be able to run it .

1.In fact you can run from the directory of your choice. I've just given you an example.
What you have to do is put the root directory of your package in your classpath. The path can be absolute or relative to the current directory.

2.Yes when you want to execute a class from a package, you always have to use the fully qualified name. Remember that the classpath just tell the JVM where to start looking for the package but don't tell what package to use.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problm with -d
 
Similar Threads
Clarification on classpaths
please help me for this package question
compiling with -d option
knb page# 793 doubt.
NoClassDefFoundError