• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

packaging problem

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am facing problem in packaging .
I have file testClass.java as

package java.first;
public class TestClass {
public void testShow(String str)
{ System.out.println (str);
}
}
and PackageTest file as
package MyPrgs.java;
import java.first.*;
public class PackageTest{

public static void main(String arg[])
{
System.out.println("Before calling Test funcion");
TestClass tc =new TestClass();
tc.testShow( "Testing from main");
System.out.println("After calling Test funcion");

}
}
TestClass.java file is compliling .But PackageTest.java file is giving err at
import java.first.*; as package java.first not found.
I do have correct directory structure.
Where am I wroung ?
Thanks
padmashree

[This message has been edited by padmshree Patil (edited April 17, 2001).]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Padmshree,
I bet you don't have the correct directory structure!
Let's say you place all your java into the following directory for compiling and running:
c:\java\source\
Compile your TestClass file and place it in the following place:
c:\java\source\java\first
This is very important!! It you don't have the directory structure "java\first" relative to where you are going to compile the PackageTest file then you will get the error you are getting!
Compile your PackageTest file from the "c:\java\source" directory and you should have no problem. It worked correctly for me ...
Regards,
Manfred.
 
Author
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or could be a CLASSPATH problem -- what's your environment?
------------------
Fred Hosch
Author of:
An Introduction to Software Construction with Java
 
padmshree Patil
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have set path to javahome. It's strange that if I copy PacakegeTest.java to root dir (c:\)
and then try to compile it works .It also runs.
I just comented package statement.
// package Myprgs.java;
import Myprgs.java.first.*;

class PackageTest{

public static void main(String arg[])
{
System.out.println("Before calling Test funcion");
TestClass tc =new TestClass();
tc.testShow( "Testing from main");
System.out.println("After calling Test funcion");

}
}

same file if I move to c:/Myprgs/java dir ,then uncoment package statement and try to compile it from c:/Myprgs/java dir gives err !!
TestClass.java is in
c:/Myprgs/java/first/ dir
What's wroung with this ???
Thanks,
padmashree
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gather that your base directory is C:\, right? That's where you execute the javac command from? We'll assume "yes" for the rest of this discussion...
You seem to have changed your package names around. Is "Myprgs" part of the package name, or not? In your first post, TestClass was supposedly in package java.first, indicating that it should be defined in a file located at C:\java\first\TestClass.java. (Not "testClass.java" as you indicated. CAPITALIZATION IS IMPORTANT.) But in your last post, TestClass is apparently in the package Myprgs.java.first - so I would expect it to be defined in C:\Myprgs\java\first\TestClass.java, with a correct package statement inside the file. You also seem to have changed MyPrgs to Myprgs - Windows may not care about the difference, but Java usually does. Pick names for your packages and classes, and use them consistently. When you change them around, we can't guess what you're talking about, and neither can your compiler.
 
Everybody's invited. Except this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic