Packages
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: Packages
You need to set the classpath to the root of your package structure. If you work with a file, say com\infogain\util\File.java, make sure the classpath is set to the directory in which the com directory resides, and compile com\infogain\util\File.java from there (I think the path must be specified along with the filename).
Hope this helps.
Hope this helps.
Re: Packages
Also be sure to add "." to your classpath. That means whatever classes are in the current directory, where you happen to be when you run the java/javac command, are automatically recognized.
:' )
Jeff
http://www.jeffyjeffy.com/textpad
:' )
Jeff
http://www.jeffyjeffy.com/textpad
Re: Packages - use workspaces to help
A fancier way is to make use of workspaces.
I have a java project and use a workspace file, this file lives in the root of the java project's directory structure.
eg d:\dev\foo\src is where my code starts
with a Workspace file called d:\dev\foo\src\foo.tws
I compile using jikes (javac will be similar) with the following for the Parameters
+E +P -classpath D:\LIB\JDK1.3\JRE\LIB\RT.JAR;D:\lib\xerces-1_3_1\xerces.jar;D:\lib\xalan-j_1_2_1\xalan.jar;$WspDir $File
The $WspDir gets substituted for the classpath of the project, magic.
It means you can work on lots of packages without needing a huge classpath.
The downside is adding all the other things you need to this classpath.
cheers
gareth
I have a java project and use a workspace file, this file lives in the root of the java project's directory structure.
eg d:\dev\foo\src is where my code starts
with a Workspace file called d:\dev\foo\src\foo.tws
I compile using jikes (javac will be similar) with the following for the Parameters
+E +P -classpath D:\LIB\JDK1.3\JRE\LIB\RT.JAR;D:\lib\xerces-1_3_1\xerces.jar;D:\lib\xalan-j_1_2_1\xalan.jar;$WspDir $File
The $WspDir gets substituted for the classpath of the project, magic.
It means you can work on lots of packages without needing a huge classpath.
The downside is adding all the other things you need to this classpath.
cheers
gareth
Re: Packages - use workspaces to help
There is a simple way. Open your Autoexec.bat file and make sure you have a parameter telling it where your packages are stored.
set CLASSPATH .;C:\jdk1.3.0_02\bin;C:\jdk1.3.0_02\lib;C:\Packages
Like someone mentioned, make sure you have the . (period) right after CLASSPATH and then the jdk stuff and then at the end just add the location of where your packages are. I have some in C:\Packages, but you could put them anywhere as long as you specify it in the CLASSPATH.
Mine happens to say jdk1.3.0_02 'cause that is the newest jdk from Sun. Just to avoid confusion...
Hope this helps.
Greg
set CLASSPATH .;C:\jdk1.3.0_02\bin;C:\jdk1.3.0_02\lib;C:\Packages
Like someone mentioned, make sure you have the . (period) right after CLASSPATH and then the jdk stuff and then at the end just add the location of where your packages are. I have some in C:\Packages, but you could put them anywhere as long as you specify it in the CLASSPATH.
Mine happens to say jdk1.3.0_02 'cause that is the newest jdk from Sun. Just to avoid confusion...
Hope this helps.
Greg
Even simpler way
I found that the way I work, I don't usually have a specific folder where I keep my packages. Thus, I made some changes to how I run the compiler.
First, I made a small batch file that I call instead of javac.exe itself:
@echo off
%~d1
if "%2" == "" goto oneparm
cd %~p1
javac %2
goto end
:oneparm
cd \
javac %~pnx1
:end
What it basically does is:
* When one parameter is supplied, it assumes it's the full path to compiled file.
* When two parameters are suppied, the first one becomes working directory (usually the package root), and the second becomes path to compiled file (usually package path)
Second, I run this batch instead of javac.exe, and I have "prompt for parameters" checked.
Now, if I don't make any complex project, I just press Enter when parameter prompt appears, and it runs the batch with one parameter - file full path.
If I do have a complex project, then, when prompted by parameters, I simply put a space in the file path at the project root, like that:
c:\java\projects\com\wombat\foo.java -> c:\java\projects\ com\wombat\foo.java
so that it splits to working directory and package path! Now it runs as two-parameter batch! And the only work I did was to type a space!
Now I can have my projects reside anywhere, and they still compile without any extra work. Note: and of course I have CLASSPATH variable defined at system level, and it includes current folder (.) as well as any classes I might need (like Oracle JDBC or XML parser)
First, I made a small batch file that I call instead of javac.exe itself:
@echo off
%~d1
if "%2" == "" goto oneparm
cd %~p1
javac %2
goto end
:oneparm
cd \
javac %~pnx1
:end
What it basically does is:
* When one parameter is supplied, it assumes it's the full path to compiled file.
* When two parameters are suppied, the first one becomes working directory (usually the package root), and the second becomes path to compiled file (usually package path)
Second, I run this batch instead of javac.exe, and I have "prompt for parameters" checked.
Now, if I don't make any complex project, I just press Enter when parameter prompt appears, and it runs the batch with one parameter - file full path.
If I do have a complex project, then, when prompted by parameters, I simply put a space in the file path at the project root, like that:
c:\java\projects\com\wombat\foo.java -> c:\java\projects\ com\wombat\foo.java
so that it splits to working directory and package path! Now it runs as two-parameter batch! And the only work I did was to type a space!
Now I can have my projects reside anywhere, and they still compile without any extra work. Note: and of course I have CLASSPATH variable defined at system level, and it includes current folder (.) as well as any classes I might need (like Oracle JDBC or XML parser)