How to access a new class from another ?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sathya_Sekar
Posted On:   Monday, February 25, 2002 01:38 AM

We have a full-fledged Java application project running. The source classes are saved under the com.project.src directory in different folders as per functioning. All the jar files used by these sources are placed in a seperate "jars" directory outside of the classes directory. During compilation, the CLASSPATH is set to include these jar files as : TOP_DIR=/home/userA JAR_DIR=$(TOP_DIR)/jars The CLASSPATH gets set as : CLASSPATH=../../jars/classes111.zip:../../jars/collections.jar:../../jars/sunxml.jar Now, I have a new class called "HelloWorld.java" :    More>>


We have a full-fledged Java application project running. The source classes are saved under the com.project.src directory in different folders as per functioning.




All the jar files used by these sources are placed in a seperate "jars" directory outside of the classes directory. During compilation, the CLASSPATH is set to include these jar files as :




TOP_DIR=/home/userA

JAR_DIR=$(TOP_DIR)/jars






The CLASSPATH gets set as :




CLASSPATH=../../jars/classes111.zip:../../jars/collections.jar:../../jars/sunxml.jar





Now, I have a new class called "HelloWorld.java" :




			
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World");
}

public static String getString(){
return "Hello";
}
}






This HelloWorld is successfully compiled and HelloWorld.class is placed into a new directory called CLASSES.


Now I need to access this from a class defined inside my project package :





			
package com.project.src.sql;

public class CallHelloWorld{
public static void main(String[] args){
System.out.println("HelloWorld says : " + HelloWorld.getString());
}
}






I include the HelloWorld.class in my classpath as :



CLASSPATH=../../jars/classes111.zip:../../jars/collections.jar:../../jars/sunxml.jar:../../OtherClasses





However, when I compile the package I receive the error :



			
CallHelloWorld.java:166: cannot resolve symbol
symbol : variable HelloWorld
location: class com.project.src.sql.CallHelloWorld
System.out.println(HelloWorld.getString());
^
1 error





I also tried placing HelloWorld.class in the same directory as CallHelloWorld.java but to no avail.
PLEASE PLEASE how do we resolve this issue ?



Thanks,

Sathya
   <<Less
About | Sitemap | Contact