Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

java packages

Thread view: 
frank - 20 Jun 2005 16:02 GMT
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
Andrew Thompson - 20 Jun 2005 16:43 GMT
> 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

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

frank - 20 Jun 2005 20:34 GMT
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

>>trying to make a java application to use packages now and having lots of
>>problems and i don't know why.
[quoted text clipped - 54 lines]
>
> HTH
Andrew Thompson - 20 Jun 2005 21:00 GMT
(Please refrain from top-posting - I find it most confusing)
See further comments below, 'in-line with trim'.
<http://www.physci.org/codes/javafaq.jsp#netiquette>

>>>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;

>>>It's complaining about the package line in each case.  Now if I use a
>>>normal javac compile ..

>> .. what is the *exact* command you are uing to compile the
>> .java source files ..

> set
> PROD_CLASSPATH=%CLASSPATH%;.;....
>
> javac -classpath %PROD_CLASSPATH% JBFSAUtility.java
....
> javac -classpath %PROD_CLASSPATH% XSSDP.java

>> ...and from which directory?

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

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

frank - 21 Jun 2005 02:14 GMT
Yes I am doing it in that directory.  Do I need to do it above that
directory?

> ..it seems from the commands above that you are doing
> this from inside the 'DBS_Intercept' directory itself -
> can you confirm that?
Andrew Thompson - 21 Jun 2005 06:03 GMT
> Yes I am doing it in that directory.  Do I need to do it above that
> directory?
>>
>> ..it seems from the commands above that you are doing
>> this from inside the 'DBS_Intercept' directory itself -
>> can you confirm that?

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.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Raymond DeCampo - 21 Jun 2005 14:01 GMT
>>Yes I am doing it in that directory.  Do I need to do it above that
>>directory?
[quoted text clipped - 16 lines]
> 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

Signature

XML is the programmer's duct tape.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.