How to add package to project?

B

Borneq

I am beginner in Java and I want to compile first substantial project, not
only my small test. In http://www.antlr2.org/grammar/pascal *.java files - I
copy this files to my project directory.
During compilation appears a problem: files have "import antlr.CommonAST;"
(sorry for my English) -> I should point to package.
In AntLR exists files antlr-3.1.1.jar, antlr-3.1.jar,
antlr-3.1.1-runtime.jar and older.
I set CLASSPATH environment variable to directory antlt*.jar are stored,
but how to tell to use this package? It is depend to IDE - Eclipse, NetBeans
or VisualStudio ?
 
D

Donkey Hottie

I am beginner in Java and I want to compile first substantial project,
not only my small test. In http://www.antlr2.org/grammar/pascal *.java
files - I copy this files to my project directory.
During compilation appears a problem: files have "import
antlr.CommonAST;" (sorry for my English) -> I should point to package.
In AntLR exists files antlr-3.1.1.jar, antlr-3.1.jar,
antlr-3.1.1-runtime.jar and older.
I set CLASSPATH environment variable to directory antlt*.jar are
stored, but how to tell to use this package? It is depend to IDE -
Eclipse, NetBeans or VisualStudio ?

CLASSPATH must contain the jar-file itself, not the folder it resides.

In an IDE you can usually "add library/jar" to the project, that puts it
into the classpath of the project.
 
L

Lew

Donkey said:
CLASSPATH must contain the jar-file itself, not the folder it resides.

Unless you are using a current javac, in which case you can use
wildcards to indicate all JARs in a directory.

<http://java.sun.com/javase/6/docs/technotes/tools/solaris/
classpath.html>
<http://java.sun.com/javase/6/docs/technotes/tools/windows/
classpath.html>
Class path entries can contain the basename wildcard character *,
which is considered equivalent to specifying a list of all the files
in the directory with the extension .jar or .JAR.

Among the pearls there:
Using the -classpath option is preferred over setting CLASSPATH environment variable
because you can set it individually for each application without affecting other
applications and without other applications modifying its value.

Donkey said:
In an IDE you can usually "add library/jar" to the project, that puts it
into the classpath of the project.

There also is an Ant task to set classpaths.
<http://ant.apache.org/manual/index.html>
 
B

Borneq

U¿ytkownik "Donkey Hottie said:
CLASSPATH must contain the jar-file itself, not the folder it resides.

Not works..
Where I can find sample project with project files, not only *.java ?
 
M

Mark Space

Borneq said:
Not works..
Where I can find sample project with project files, not only *.java ?

Which IDE are you using? The IDEs ignore the CLASSPATH. You have to:

1. Right click on the project
2. Choose Add Lib/Jar (This is under Properties -> Libraries for NetBeans)
3. Then browse to the .jar you want to use.
 
B

Borneq

U¿ytkownik "Mark Space said:
1. Right click on the project
2. Choose Add Lib/Jar (This is under Properties -> Libraries for NetBeans)
3. Then browse to the .jar you want to use.

Thanks, in NetBeans works! I add .jar to Libraries
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top