Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problm with -d

 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic