java packages

Discussion in 'Java' started by frank, Jun 20, 2005.

  1. frank

    frank Guest

    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
    frank, Jun 20, 2005
    #1
    1. Advertising

  2. On Mon, 20 Jun 2005 11:02:31 -0400, frank wrote:

    > 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

    --
    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
    Andrew Thompson, Jun 20, 2005
    #2
    1. Advertising

  3. frank

    frank Guest

    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 Thompson wrote:
    > On Mon, 20 Jun 2005 11:02:31 -0400, frank wrote:
    >
    >
    >>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
    >
    frank, Jun 20, 2005
    #3
  4. On Mon, 20 Jun 2005 15:34:41 -0400, frank wrote:
    > Andrew Thompson wrote:
    >> On Mon, 20 Jun 2005 11:02:31 -0400, frank wrote:


    (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?

    --
    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
    Andrew Thompson, Jun 20, 2005
    #4
  5. frank

    frank Guest

    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?
    >
    frank, Jun 21, 2005
    #5
  6. On Mon, 20 Jun 2005 21:14:25 -0400, frank wrote:

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

    --
    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
    Andrew Thompson, Jun 21, 2005
    #6
  7. Andrew Thompson wrote:
    > On Mon, 20 Jun 2005 21:14:25 -0400, frank wrote:
    >
    >
    >>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.
    >


    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

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Jun 21, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Silvere Martin-Michiellot

    Java Math packages

    Silvere Martin-Michiellot, Oct 5, 2003, in forum: Java
    Replies:
    3
    Views:
    772
    Randy Poe
    Oct 6, 2003
  2. Silvère Martin-Michiellot

    Java Math packages

    Silvère Martin-Michiellot, Oct 7, 2003, in forum: Java
    Replies:
    1
    Views:
    1,760
    alphah
    Jun 14, 2010
  3. Paul  Smith
    Replies:
    0
    Views:
    717
    Paul Smith
    Nov 18, 2003
  4. David Lyon
    Replies:
    19
    Views:
    554
    David Lyon
    Apr 24, 2009
  5. Ian
    Replies:
    3
    Views:
    155
Loading...

Share This Page