JAVA Question - adding a library

wizzz

Senior member
Jul 20, 2000
267
0
0
Anybody know how to add a library of classes in Java?

For example, suppose I have a bunch of classes that I want to reuse everytime in all my programs.
How can I add it into Java so that I can always do " import myclasses.*; "

 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
copy the .class files to your class path

thats it. if you are using J++ make sure you copy the .pdb files as well so you can get the nice debugging features enabled too.
 

wizzz

Senior member
Jul 20, 2000
267
0
0

How do I copy the .class files to the class path?

I don't know how to do it... Could you give me an example?

 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
compile your .java files into .class files

then find on your system where all the other class files are and copy yours into that same directory.
 

wizzz

Senior member
Jul 20, 2000
267
0
0
actually I was thinking more of like setting the classpath

for example, >set classpath=myclass;

I'm trying to do this and it's not working...
Thanks for the reply though.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: wizzz
actually I was thinking more of like setting the classpath

for example, >set classpath=myclass;

I'm trying to do this and it's not working...
Thanks for the reply though.

are you on a windows machine?
 

FeathersMcGraw

Diamond Member
Oct 17, 2001
4,041
1
0
Originally posted by: wizzz
How do I copy the .class files to the class path?

I don't know how to do it... Could you give me an example?

Several ways to do this:

1) include the archive file (typically, something ending in .jar) in your class path. This can be specified either as an environment variable (in Windows, CLASSPATH) or as a command-line argument to the Java compiler/virtual machine.

2) copy the individual class files into the appropriate directory with your class files. Thus, if your library was in package com.foo and your code was in com.bar, you'd want to have a directory structure which had a com directory with subdirectories foo and bar (each one of which contained their respective class files).

3) assuming you're using a Java 1.2 or later environment, copy the archive file into the subdirectory jre/lib/ext in your Java SDK.