• 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

Problm with -d

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic