java packages

F

frank

trying to make a java application to use packages now and having lots of
problems and i don't know why.

Just added to the top of each source file

package DBS_Intercept;

Compiled and and got the followig errors from Jbuilder

"DBS.java": Package
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\DBS.java stated in source
DBS_Intercept does not match directory
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\DBS.java. at line 37, column 9
"XSS.java": Package
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\XSS.java stated in source
DBS_Intercept does not match directory
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\XSS.java. at line 14, column 9
"JBFSAUtility.java": Package
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\JBFSAUtility.java stated in
source DBS_Intercept does not match directory
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\JBFSAUtility.java. at line
13, column 9
"XSSDP.java": Package
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\XSSDP.java stated in source
DBS_Intercept does not match directory
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\XSSDP.java. at line 15,
column 9
"RunDBS.java": Package
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\RunDBS.java stated in
source DBS_Intercept does not match directory
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\RunDBS.java. at line 10,
column 9
"CSDSMsg.java": Package
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\CSDSMsg.java stated in
source DBS_Intercept does not match directory
C:\data\JBFSA\may_05_demo_code\DBS_Intercept\CSDSMsg.java. at line 16,
column 9


It's complaining about the package line in each case. Now if I use a
normal javac compile for each class it complains about not finding the
classes in each of the files (now because of the package statement).
Don't use packages it works fine. Never have a lot of luck with
packages I must be missing something fundamental here. The source and
class files are to all be in same directory DBS_Intercept

Any thoughts?

Thanks,

Frank
 
A

Andrew Thompson

trying to make a java application to use packages now and having lots of
problems and i don't know why.

Just added to the top of each source file

package DBS_Intercept;

Common Java package name nomenclature is to use all
lower case for package names, and no '_' characters.

[ Class names generally have EachWordStartUpperCase -
while methods and attributes are - firstWordLowerCase. ]

(snip JBuilder stuff)
...
It's complaining about the package line in each case. Now if I use a
normal javac compile ..

I suggest it is important to get that right first,
so let's have a look..
..for each class it complains about not finding the
classes in each of the files (now because of the package statement).
Don't use packages it works fine.

[ Unfortunately, you cannot get very far without using packages. ]
..Never have a lot of luck with
packages I must be missing something fundamental here. The source and
class files are to all be in same directory DBS_Intercept

... what is the *exact* command you are uing to compile the
..java source files and from which directory?

For example, often the developer compiles from 'the top'.
So if there is a package org.utils with source FileUtils.java
the source might be put in folder..

C:\Projects\Java\BasicTools\org\utils\

...which might be compiled from..

C:\Projects\Java\BasicTools\

...then Java source file FileTool.java (in package 'utils')
might be compiled by calling ..

C:\Projects\Java\BasicTools\>javac org/utils/FileTool.java

A class file with the correct package information should
now be inside C:\Projects\Java\BasicTools\org\utils\.

In closing, I will suggest that there is a better group
for sorting such problems..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH
 
F

frank

Using the following to compile manually. Not quite sure how to see how
Jbuilder is building it. All source in local directory

set
PROD_CLASSPATH=%CLASSPATH%;.;;C:\data\JBFSA\may_05_demo_code\lib;C:\tomcat-j
wsdp-1.4\jaxrpc\lib\jaxrpc-api.jar;%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discov
ery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB
%\log4j-1.2.8.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\wsdl4-1.5.1.jar;C:\xerces-2_6_2
\xercerImpl.jar;C:\data\JBFSA\may_05_demo_code\lib\soap.jar;C:\data\JBFSA\may_05
_demo_code\lib\xssrpc.jar;C:\xalan-j_2_6_0\bin\xalan.jar


javac -classpath %PROD_CLASSPATH% JBFSAUtility.java
javac -classpath %PROD_CLASSPATH% CSDSMsg.java
javac -classpath %PROD_CLASSPATH% DBS.java
javac -classpath %PROD_CLASSPATH% RunDBS.java
javac -classpath %PROD_CLASSPATH% XSS.java
javac -classpath %PROD_CLASSPATH% XSSDP.java

Andrew said:
trying to make a java application to use packages now and having lots of
problems and i don't know why.

Just added to the top of each source file

package DBS_Intercept;


Common Java package name nomenclature is to use all
lower case for package names, and no '_' characters.

[ Class names generally have EachWordStartUpperCase -
while methods and attributes are - firstWordLowerCase. ]

(snip JBuilder stuff)
..
It's complaining about the package line in each case. Now if I use a
normal javac compile ..


I suggest it is important to get that right first,
so let's have a look..

..for each class it complains about not finding the
classes in each of the files (now because of the package statement).
Don't use packages it works fine.


[ Unfortunately, you cannot get very far without using packages. ]

..Never have a lot of luck with
packages I must be missing something fundamental here. The source and
class files are to all be in same directory DBS_Intercept


.. what is the *exact* command you are uing to compile the
.java source files and from which directory?

For example, often the developer compiles from 'the top'.
So if there is a package org.utils with source FileUtils.java
the source might be put in folder..

C:\Projects\Java\BasicTools\org\utils\

..which might be compiled from..

C:\Projects\Java\BasicTools\

..then Java source file FileTool.java (in package 'utils')
might be compiled by calling ..

C:\Projects\Java\BasicTools\>javac org/utils/FileTool.java

A class file with the correct package information should
now be inside C:\Projects\Java\BasicTools\org\utils\.

In closing, I will suggest that there is a better group
for sorting such problems..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH
 
A

Andrew Thompson

(Please refrain from top-posting - I find it most confusing)
See further comments below, 'in-line with trim'.
set
PROD_CLASSPATH=%CLASSPATH%;.;....

javac -classpath %PROD_CLASSPATH% JBFSAUtility.java .....
javac -classpath %PROD_CLASSPATH% XSSDP.java

...it seems from the commands above that you are doing
this from inside the 'DBS_Intercept' directory itself -
can you confirm that?
 
A

Andrew Thompson

Yes I am doing it in that directory. Do I need to do it above that
directory?

It can be done from within the directory or above it, but I suspect
it makes sense to get *one* approach working, so I am trying to bring
you around to using the one I know best. Working out the variatian
that allows it to work from within the the package directory is more
of a DOS/Command Line thing.

In any case, if you go back to my original post, you will notice that
when compiling this package/JavaClass.java, I did it from the parent
directory but called the java files by their package/class names
(package/JavaClass.java).

This (is one way of) making sure the package statements are correctly
written in the resulting class files.
 
R

Raymond DeCampo

Andrew said:
It can be done from within the directory or above it, but I suspect
it makes sense to get *one* approach working, so I am trying to bring
you around to using the one I know best. Working out the variatian
that allows it to work from within the the package directory is more
of a DOS/Command Line thing.

In any case, if you go back to my original post, you will notice that
when compiling this package/JavaClass.java, I did it from the parent
directory but called the java files by their package/class names
(package/JavaClass.java).

This (is one way of) making sure the package statements are correctly
written in the resulting class files.

I think perhaps you meant something else by the above statement. The
package statements in the resulting class files are a function of the
package statements in the java source files and do not depend on the
directory structure.

I think you probably meant that the resulting class files and their
directory structure correspond to the package statements, making the
class files "usable".

Something that might help the OP here is to use the -d switch to javac,
which causes the compiler to place the class files in a separate
directory from the source files. I personally prefer to have the
compiled classes separate from the source code and I think it would be
an educational exercise in any case.

If this cause additional confusion, it may be something the OP wants to
try after getting things working.

HTH,
Ray
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top