Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 14324
321
  • 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".

 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic