• 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

please help me for this package question

 
Greenhorn
Posts: 14
Oracle Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My directory structure:




I have a source file in source/com/wickedlysmart
coded as:

I stored .class file in classes/com/wickedlysmart using -d option.

I changed my current directory to classes/com/wickedlysmart

then tried to run it using
%java Klass

I got error as shown:



please help me why it is so...
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make the parent of source and classes your current working directory, and try this: java -cp classes com.wickedlysmart.Klass
 
Prady Kural
Greenhorn
Posts: 14
Oracle Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankyou
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prady Kural wrote:My directory structure:

Myproject::
:::--classes::
::: :::com::
::: :::wickedlysmart
:::
:::
:::--source::
:::com::
:::wickedlysmart


I have a source file in source/com/wickedlysmart
coded as:

package com.wickedlysmart;
public class Klass{
public static void main(String arg[]){
System.out.println("hi");
}
}



I stored .class file in classes/com/wickedlysmart using -d option.

I changed my current directory to classes/com/wickedlysmart

then tried to run it using
%java Klass

I got error as shown:



please help me why it is so...



Hello Prady...Change your directory to "classes" and STOP there! DO NOT INCLUDE(/com/wickedlysmart)
Let us assume that "classes" is in the C:\file directory, the first thing you do is:
cd C:\file\classes

AND then invoke the java command as follows:

%java com.wickedlysmart.Klass

OR

%java -cp . com.wickedlysmart.Klass

This is because when you declare your class in a package, java recognises your class AND package names as "ATOMIC"...(com.wickedlysmart.Klass)
NOTE: When using the -cp flag, the .(dot) between -cp AND com.wickedlysmart.Klass simply tells java to search the current directory(classes)...You are simply telling java "check the current directory (classes) for a class called com.wickedlysmart.Klass".

 
reply
    Bookmark Topic Watch Topic
  • New Topic