Cris
Cris

Reputation: 2021

Java importing packages

I have a program in my desktop that I want to run (structure in the url), but when I do compile, with \code\nlp\assignments\parsing\javac PCFGParserTester.java I get:

PCFGParserTester.java:6: error: package nlp.io does not exist
import nlp.io.PennTreebankReader;
         ^
PCFGParserTester.java:7: error: package nlp.ling does not exist
import nlp.ling.Tree;
           ^
PCFGParserTester.java:8: error: package nlp.ling does not exist
import nlp.ling.Trees;
           ^
PCFGParserTester.java:9: error: package nlp.parser does not exist
import nlp.parser.EnglishPennTreebankParseEvaluator;

how do I get my program to correctly import my packages?

enter image description here

Upvotes: 0

Views: 162

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499800

You want to be in the \code directory and compile with:

javac nlp\assignments\parsing\PCFGParserTest.java

(And you should have a package declaration of package nlp.assignments.parsing; to match the position in the directory structure.)

That way javac will look for the other classes appropriately.

Alternatively, and rather more simply, you could use an IDE such as Eclipse or NetBeans, and it would take care of all this for you - you'd just specify the code directory as a source directory, and all would be well.

Upvotes: 2

Related Questions