Re: Help needed with importing
Clarence wrote:
As always with a new system, I seem to have more trouble with the
needed infrastructure rather than the expression of my desires in
code. With Java, I am unable to get one class to use another.
I have this simple class, compiled and ready in a .class file:
$ cat CensusData.java
package cg;
public class CensusData
{
public int population;
public int houses;
public int returns;
public int agi_avg;
public int refunds;
public int refund_avg;
}
and a desirous user of it (with irrelevancies elided)
$ head CountyAgi.java
import cg.CensusData;
public class CountyAgi extends Configured implements Tool
{
public static class Map
extends Mapper<LongWritable, Text, Text, CensusData>
{
private CensusData cd = new cg.CensusData();
But compiling this claims that
package cg does not exist
and
symbol CensusData does not exist
Everything being in the same directory, I thought the package was not
But 'CountyAgi' does not have a 'package' directive! The only way that
classes don't need fully-qualified names (FQNs) or equivalent 'import'
directives is if they're in the same package.
even necessary and originally did not have it. I added it just to try
to get it to compile, with no good effect. The current configuration
seems to match what the tutorial at oracle.com shows. I think perhaps
my problem is in the compiler invocation rather than the program
structure.
No, the program structure is wrong, too.
]
javac -classpath /usr/lib/hadoop/hadoop-core-0.20.2+320.jar:/usr/lib/
hadoop/hadoop-mapred-0.20.2+320.jar:/usr/lib/hadoop/hadoop-
hdfd-0.20.2+320.jar -d . CountyAgi.java
You omitted "." from the classpath and did not include the directory for
'CountyAgi.java'.
I've tried adding CensusData.class to the command line, and putting
What do you mean you added "CensusData.class to the command line"?
Which command line, the "javac" command? You never specify class files to
"javac" or "java", you specify classes and classpaths.
CensusData in a jar and adding that, but nothing works.
Can you help a neophyte?
javac \
-classpath
/usr/lib/hadoop/hadoop-core-0.20.2+320.jar:/usr/lib/hadoop/hadoop-mapred-0.20.2+320.jar:/usr/lib/hadoop/hadoop-hdfd-0.20.2+320.jar:.
\
-d . cg/*.java
--
Lew