• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Question on packages

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to execute a java file using packages...but i am not successful in doing that..

I created a folder name (world) in C drive.. and the file name is Hello.java
The code in Hello.java is as follows

//Program starts from here

package world;
import java.io.*;
// package world;
public class Hello{
public static void main(String args[]){
System.out.println("Hello WOrld");

}
}

C:\> set CLASSPATH=.;C:\;
C:\>cd world
C:\world> java world.Hello

i dont know what wrong i was doing here..I am new to this concept..can u check this
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Udai,

Try to execute your class from within C:\ instead of C:\word\ as follows :

c:\> java -classpath . word.Hello

When using packages, the directory entry existing in your classpath must be the parent directory of the root directory in your package structure.

The way you are using to run your class would work fine if your class was located in default package.

Hope that helps.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic