How to set packages and classpath

Hi,
I want to know about packages and classpath. I have these questions
1, If I put a class in a package(work.util) is it necessary to put the java file in the same directory/directory hierarchy as mentioned in the package declaration. I have to compile this class, run it from main method and must be able for other classes to import.
2. If a package have subpackages(work.util.db) do I have to set the classpath to subdirectory also to run that class.
3. If a class is in package is it possible to run the class without prefixing the package name. I need to do this in the text editor so that I can run any program by pressing a hot key.
rgds
Antony Paul

1, If I put a class in a package(work.util) is it
necessary to put the java file in the same
directory/directory hierarchy as mentioned in the
package declaration.Strictly speaking, this isn't covered by the spec - it depends on what compiler and ClassLoader you are using. If you're using Sun's JDK, then yes.
2. If a package have subpackages(work.util.db) do I
have to set the classpath to subdirectory also to run
that class. No. You should add the directory above work/util/db to your classpath. You should not add work, or work/util or work/util/db.
E.g., if your Java files are in C:/MyProject/JavaSrc/work/util/db, and the package name is work.util.db, then you should have C:/MyProject/JavaSrc on your classpath (or have "." (dot) on your classpath, and compile and run from that same directory).
3. If a class is in package is it possible to run the
class without prefixing the package name. I need to do
this in the text editor so that I can run any program
by pressing a hot key.If you mean "in order to run work.util.db.Main do I need to type java work.util.db.Main, or just java Main", then you do indeed need the fully qualified class name (otherwise, how would the runtime environment know which class you mean? - there could be any number of classes called Main in any class, and it would have to search every directory and subdirectory on your classpath to find them.

Similar Messages

  • Package and CLASSPATH

    Hi,
    I have a hard time understanding the package and CLASSPATH. I want to have a solid understanding of it. I read some tutorials online but didn't make me fully understand. How does declaring a package effect the CLASSPATH? Say I have following:
    (This is from one of the tutorial- http://home.cogeco.ca/~ve3ll/jatutor4.htm)
    C:\myclasses\world\moon\HelloMoon.java
    C:\myclasses\world\HelloWorld.java
    HelloMoon.java is defined as
    package world.moon;
    public class HelloMoon {
    private String holeName = "rabbit hole";
    public String getHoleName() {
    return holeName;
    public void setHole(String holeName) {
    this.holeName = holeName;
    public static void main(String[] args){
         HelloMoon moon = new HelloMoon();
         System.out.println(moon.getHoleName());
    HelloWorld is defined as
    package world;
    public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World");
    if the CLASSPATH is set : set CLASSPATH=.;C:\myclasses;
    Once the CLASSPATH has been set (and compiled .java file); it can be called using the following from any path of directory:
    java world.HelloWorld
    java world.moon.HelloMoon
    But it does not explain the details why it works this way. Also, if I want to run it without using "world" prefix to run HelloWorld, what do I need to set up?
    also for the HelloMoon?
    When I tried running those classes by going to an appropriate directory, I got the noClassDefFound (using command like "java HelloWorld" or java "HelloMoon").
    Thanks in advance...

    [Javapedia: Classpath|http://wiki.java.net/bin/view/Javapedia/ClassPath]
    [How Classes are Found|http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html]
    [Setting the class path (Windows)|http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]
    [Setting the class path (Solaris/Linux)|http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html]
    [Understanding the Java ClassLoader|http://www-106.ibm.com/developerworks/edu/j-dw-javaclass-i.html]
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • How to set-up and use FAMILY Sharing

    Can someone please explain to me in detail how to set-up and use FAMILY Sharing, none of the information I have so far found in the documentation helps at all, in fact it puts you in a constant loop giving the same information over and over again
    We have quite a few devices from ipads, iphones and ipods and I need to set-up Family Sharing.
    We have our main Apple ID which is linked to our Payment method, I have now got my son a new iPad, I have created his Apple ID and set-up a link via FAMILY Sharing to our main Apple ID.
    From what I read we should be able to share our purchased Apps between family members.
    So I figured I would be able to get the Apps now via iTunes that are part of the FAMILY Sharing, however when I go into ITunes (latest version downloaded yesterday) I can only see the Home sharing menu item not FAMILY Sharing, so I cannot work out in Itunes how to get Apps that are FAMILY shared.  So ok I will try and get Apps directly via the Ipad using the App Store.  To test it is working I look for a known paid for App, I then go to download it and it is now asking me to pay for it again. 
    Can someone please explain to me in detail how FAMILY Sharing is supposed to work and how I get it to work please.
    Thanks for your help
    Greg

    Hey GregWr,
    Thanks for the question. The following resources provides some of the best information regarding Family Sharing. Included, you’ll find information on making sure the accounts are set to "Share my purchases”, as well as information on downloading Family Member purchases from the iTunes Purchased section. Please note that some applications are not shareable.
    Sharing purchased content with Family Sharing - Apple Support
    http://support.apple.com/en-us/HT201085
    Which purchased content can I share using Family Sharing - Apple Support
    http://support.apple.com/en-us/HT203046
    If you don't see your family's shared content - Apple Support
    http://support.apple.com/en-us/HT201454
    Thanks,
    Matt M.

  • How to set up and configure AirPort Express for AirPlay and iTunes

    Saw somewhere that supposedly there were some apple written guidlines on the above topic. I have searched all over for them. Anyone know where I can get a copy to read through. Just trying to educate myself a bit and sety up another room with access to itunes, radio, etc with high quality speakers and amp off my express.

    Here you go ...
    How to set up and configure AirPort Express for AirPlay and iTunes

  • How to set up and use AirPlay

    How to set up and use AirPlay

    Welcome to the Apple Community.
    AirPlay; When watching suitable content on the iPad, tap the screen to bring up the controls, tap the AirPlay icon and select the Apple TV. The content will then stream to the Apple TV.
    Mirroring; Double tap the home screen button, swipe the application panel to the right, tap the AirPlay icon and choose the Apple TV. The iPad screen will then be streamed to the Apple TV.

  • How to set upper and lower limit for service notification in SPRO

    Hello everyone,
    Good morning....!!
    I am new to SAP PM and to SCN as well.
    I have a question on Service notification user status.
    I  have notification profile configured in SAP as below:
    Status no      Status          Short text              Lower limit          Upper limit
    5                  REGD          Registered                1                          70
    10                PCKS            Pack sent                  1                          70
    20                APRC            Application received  1                        70
    etc..
    I want the statusesto be set as  navigation should only allow to go back one by one...like from APRC -->PCKS not to REGD.From PCKS -->REGD etc..not vice versa.
    Can enayone explain me to how to set lower and upper limits for these according ot the above requirement.
    for more details please check my attachment.
    Thanks in advance..!!
    Regards,
    Sudha.

    Once you change the status to previous status, just save the order. Then again open the order & try to change the user status.
    Just I made replica of your profile. I could able to change (even without saving the order).

  • How to set date and time on apple tv

    how to set date and time on apple tv

    Assuming this is not the first time you have used your Apple TV
        1.    You might try restarting the Apple TV by removing ALL the cables for 30 seconds.
        2.    Also try restarting the router.
        3.    If the problem persists, try a restore, you may want to try the previous procedures several times before doing this.
    If this is a new Apple TV, it may also be that your network router is not allowing access to the timeserver, check that your router allows access over port 123.

  • How to set datapackage and  Idoc

    Hi
    could any body  tell me , How to set datapackage and Idoc in sap bw

    Hi Hari,
    There are 2 additional places to make these settings global:
    1) Transaction SBIW on BW for SAP Source systems:
    Data Transfer to the SAP Business Information Warehouse ->
    General Settings -->
    Maintain Control Parameters for Data Transfer
    2) Transaction SPRO on BW for non-SAP Source Systems:
    SAP Customizing Implementation Guide -->
    SAP NetWeaver -->
    SAP Business Information Warehouse -->
    Links to other systems -->
    Maintain Control Parameters for the data transfer
    Please note the paths are from a BW 3.5 system.
    Kind regards,
    Dorothy

  • How to go about Setting PATH and CLASSPATH?

    I have problems compling the helloworldwww in the core programming.the error was:
    Exception in thread "main"java.lang.NoSuchMethodError:main
    my java programs are in c:\program files\java\bin
    My path :
    PATH=C:\WINNT\system32;C:\WINNT;c:\program files\java\bin
    My classpath
    set CLASSPATH=C:\WINNT\system32;C:\WINNT;c:\program files\java\bin.jar;.
    is there any error in my paths, if yes how to i go about setting the path and classpath??Im running on winXP.j2sdk1.4.1_02.

    set CLASSPATH=.;c:\program files\java\bin.jar;c:\program files\java\bin

  • Help with packages and classpath

    Heya,
    first off, i use textpad to compile my java, i don't do it via the command line.
    my problem is faily simple, i think. i've got a main class and i'd like it to import a custom class from a subdir.
    Main class is in
    C:\Documents and Settings\David\Desktop\java\test_gen.java
    I would like it to import
    C:\Documents and Settings\David\Desktop\java\obj_data\objects.java
    I understand that I have to declare objects.java to be a part of a package, so i head the code with: package obj_data; as i understand it, the directory in which the package to be imported resides in will be named the same as the package.
    When i import my package into test_gen.java, i import obj_data as follows:
    import obj_data.*;
    this should import objects.class and any other classes in the same directory. also import obj_data.objects.*; could be used.
    Anyway, thats my understanding of how you set up the class and package; i also understand that when the java file compiles the compiler looks at the directoy(s) indicated in the class path for the classes to import. that in mind i tried to add:
    C:\Documents and Settings\David\Desktop\java\obj_data\
    to my classpath. i did this via dos, javac -classpath "C:\Documents and Settings\David\Desktop\java\obj_data\"
    i got no error messages, so i assume it worked. however when i try to compile the main java (test_gen) i get-
    package packages does not exist
    import packages.*;
    ^
    1 error
    Tool completed with exit code 1
    can anyone give me some help please?

    This is a minimal explanation of packages.
    Assume that your programs are part of a package named myapp, which is specified by this first line in each source file:
    package myapp;
    Also assume that directory (C:\java\work\) is listed in the CLASSPATH list of directories.
    Also assume that all your source files reside in this directory structure: C:\java\work\myapp\
    Then a statement to compile your source file named aProgram.java is:
    C:\java\work\>javac myapp\aProgram.java
    Explanation:
    Compiling
    A class is in a package if there is a package statement at the top of the class.
    The source file needs to be in a subdirectory structure. The subdirectory structure must match the package statement. The top subdirectory must be in the classpath directory.
    So, you generate a directory structure C:\java\work\myapp\ which is the [classpath directory + the package subdirectory structure], and place aProgram.java in it.
    Then from the classpath directory (C:\java\work\) use the command: javac myapp\aProgram.java
    Running
    Compiling creates a file, aProgram.class in the myapp directory.
    (The following is where people tend to get lost.)
    The correct name now, as far as java is concerned, is the combination of package name and class name: myapp.aProgram (note I omit the .class) If you don't use this name, java will complain that it can't find the class.
    To run a class that's NOT part of a package, you use the command: java SomeFile (assuming that SomeFile.class is in a directory that's listed in the classpath)
    To run a class that IS part of a package, you use the command java myapp.aProgram (Note that this is analogous to the command for a class not in a package, you just use the fully qualified name)

  • Set package in classpath?

    Hi, I am wondering how to set the jar file containing the package (org.ccil.cowan.sax.*) in my classpath ? Do I need to download anything first? HELP!!!!

    Setting the Classpath:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html
    [NOTE: always start your classpath with ".;" which means the current directory]
    How Classes are Found:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html
    Of course, the jar must exist somewhere in your computer file system; its location and name (ie, the full path spec) is what you use to create the classpath entry.

  • How to set thumbnailUrl and/or thumbnailLocation?

    Hi...
    I have now been struggling how to set the URL or location for the thumbnail, when packaging a book...
    PS. The thumbnail is already uploaded to a location I know the path to:
    This is my XML request (bolded text are examples):
    [thumbnailLocation attempt]:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
              <package xmlns="http://ns.adobe.com/adept">
              <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
                             <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">testTitle</dc:title>
                             <dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">testPublisher</dc:publisher>
                             <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">testCreator</dc:creator>
                             <dc:language xmlns:dc="http://purl.org/dc/elements/1.1/">da</dc:language>
                             <dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">testDescr</dc:description>
                             <dc:identifier xmlns:dc="http://purl.org/dc/elements/1.1/">urn:uuid:UUID</dc:identifier>
              </metadata>
              <thumbnailLocation>C:\path\to\thumbnail\00c6429e-ea9e-4656-acaf-4de3c37de8d3.jpg</thumbnailLocation>
              <dataPath>C:\path\to\book\00c6429e-ea9e-4656-acaf-4de3c37de8d3.epub</dataPath>
    </package>
    [thumbnailURL attempt]:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <package xmlns="http://ns.adobe.com/adept">
      <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
            <dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">testTitle</dc:title>
            <dc:publisher xmlns:dc="http://purl.org/dc/elements/1.1/">testPublisher</dc:publisher>
            <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">testCreator</dc:creator>
            <dc:language xmlns:dc="http://purl.org/dc/elements/1.1/">da</dc:language>
            <dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">testDescr</dc:description>
            <dc:identifier xmlns:dc="http://purl.org/dc/elements/1.1/">urn:uuid:UUID</dc:identifier>
            <thumbnailURL>C:\path\to\thumbnail\00c6429e-ea9e-4656-acaf-4de3c37de8d3.jpg</thumbnailURL>
      </metadata>
      <dataPath>C:\path\to\book\00c6429e-ea9e-4656-acaf-4de3c37de8d3.epub</dataPath>
    </package>
    In the response I can see that it completely ignores the thumbnailURL tag, but does not ignore thumbnailLocation - it merely just doesn't do anything with it.
    Any idea?

    Thanks for the answer!
    However, I have tried with both file://c/path/to/... and http://www.myserver.com/thumbnails/filename.jpg  for the <thumbnailLocation> tag, and same for the <thumbnailURL>.
    The packaging service still keeps ignoring those tags, and when I go look in the admin console (http://localhost:8080/admin/console) the book that was posted, has no thumbnail URL.
    I also tried using a base64 encoded image as <thumbnailData> together with <thumbnailLocation>... But in vain...
    PS. This Adobe Content Server has VERY LOUSY technical references. There's no code examples to find, and the tags / xml-requests/responses has very poor detailed explanation. Example:
    The detailed information about the thumbnailLocation tag is like this:
         thumbnailLocation - Upload location for the thumbnail
    Oh really...
    Long story short:
    When I package a book, I already have an uploaded thumbnail image on the server. All I want is to refer to that image, when I package a book... How hard can it be?

  • How to create package and import from jar file?

    Hi all,
    I am writing a software and I am not sure how to create a package for the classes.
    Say I have two classes in the same directory as follows:
    testA.java
    ==========
    package AB;
    public class testA
    public static void main(String[] args){
         testB myB = new testB();
         System.out.println("A test");
    testB.java
    ===========
    package AB;
    public class testB
    public testB(){
         System.out.println("B constructor");
    both file compile without the package heading;
    both file compile using: javac -classpath .\ *.java
    Question 1:
    I cannot run testA by: java -classpath .\ testA
    I think it is a syntax error. What is the correct one?
    If I run testA by: java testA
    The only output I get is: A test
    But I am expecting: B constructor /n A test
    What went wrong?
    Question 2:
    I need to use APIs of another software. I have downloaded a .jar file (xxx.jar) with all the classes in it. And I have put "import xxx.*;" in my source file. But the compiler complains about the importing. What is the right way to copmile it?
    I have read a couple of tutorials but they don't answer my question.
    (I am using windows2000 and don't have the classpath variable.)
    Hope some one can help.
    Thanks a lot

    Try moving testA out of the package and importing 'AB.*;'
    If you have:
    ./testA.class
    ./AB/testb.class
    Then to execute testA from ./ type: java -cp . testA

  • Set path and classpath in ANT

    by using ANT, how can set the JDK path and classpath..
    jdk version exists in the : C:\Program Files\Java\jdk1.6.0
    This is the build.xml that i need to modify!
    -Do i need to have a serperate JAVA_HOME variable?
    <?xml version="1.0"?>
    <!--
    Build file for 'Chat Client'
    Version: $Revision: 4.10 $ $Date: 2003/05/28 $
    Author:  Rajat Gupta
    -->
    <project name="Chat" default="jar" basedir=".">
       <!-- ================================================================== -->
       <!-- Initialization of all property settings                            -->
       <!-- ================================================================== -->
       <target name="init">
          <property name="appname"        value="chat"   />
          <property name="src.dir"        value="src"               />
          <property name="lib.dir"        value="lib"              />
          <property name="build.dir"      value="Chat"            />
          <property name="build.compiler" value="classic"          />
       </target>
       <!-- ================================================================== -->
       <!-- Makes sure the needed directory structure is in place              -->
       <!-- ================================================================== -->
       <target name="prepare" depends="init">
          <mkdir dir="${lib.dir}" />
          <mkdir dir="${lib.dir}/META-INF" />
          <mkdir dir="${build.dir}" />
       </target>
       <!-- ================================================================== -->
       <!-- Compilation of the web part of the application                     -->
       <!-- ================================================================== -->
       <target name="classes" depends="prepare">
          <javac srcdir="${src.dir}/oracle/otnsamples/oc4jjms"
                 destdir="${lib.dir}"
                 includes="**" />
       </target>
       <!-- ================================================================== -->
       <!-- Compilation of the complete J2EE application (both web and EJB)    -->
       <!-- ================================================================== -->
       <target name="j2ee-meta-inf" depends="classes, prepare">
          <copy file="${src.dir}/META-INF/application-client.xml"
                tofile="${lib.dir}/META-INF/application-client.xml" />
          <copy file="${src.dir}/images/oralogo.gif"
                tofile="${lib.dir}/oralogo.gif" />
       </target>
       <target name="jar" depends="j2ee-meta-inf">
       <jar jarfile="${build.dir}/${appname}.jar"
           basedir="${lib.dir}" manifest="${src.dir}/META-INF/MANIFEST.MF"/>
          <delete dir="${lib.dir}" />
       </target>
    </project>Message was edited by:
    jugp

    [url ='http://www.jguru.com/forums/home.jsp?topic=Ant']answer here

  • Need you help !!! -- How to set PACKAGE SIZE in CURSOR?

    Dear experts:
    Does anybody know how to set the package size if you use cursor in your abap program?
    My scenario is to select all the data from MARA table in which the data volumn is very big, and then process for some specific logic. When I try to select them into one internal table or use CURSOR without package, my abap program will abort after running for around 1 hour. So I was thinking if I can use cursor and set the PACKAGE SIZE like 10,000 and process the data by batch.
    Here is my sample code:
    OPEN CURSOR: CUR_MARA_TBL FOR
    SELECT * FROM MARA.
    DO.
    FETCH NEXT CURSOR CUR_MARA_TBL INTO CORRESPONDING FIELDS OF WA_MARA_TBL.
    IF sy-subrc = 0.
    ......Detail logic......
    ENDIF.
    ENDDO.
    I would appreciate if anybody can let me know how to set the package size based on the sample code above, or any webpage/article about that.
    Any reply would be appreciated and thank you all in advance!
    Best Regards.
    Tim
    Moderator message: please study F1 help for FETCH statement.
    locked by: Thomas Zloch on Sep 8, 2010 4:10 PM

    The Spark List's layout property has the requestedRowCount and requestedMinRowCount properties.
    You can either set a new layout property on your List like this:
    <s:List>
            <s:layout>
                <s:VerticalLayout requestedMinRowCount="1" />
            </s:layout>
        </s:List>
    or reskin the List and modify the VerticalLayout in your copy of ListSkin.
    Jason

Maybe you are looking for

  • Manipuilate joins dynamically.

    Hi All, I would need an help on the query. I have a table x and column a, b,c, y and z in them.I am joining this table with another table c IF the column y is not NULL and if z='M' THEN I have to join table c with d IF the column y is not NULL and if

  • Yoga 2 Pro - Broken in less than a year - A terrible experience with IdeaPads

    Hi guys! I'm hear to tell everyone about my pretty terrible experience with Lenovo and my Yoga 2 Pro IdeaPad. It's not a review or anything but more of a forewarning to those who are thinking of buying from Lenovo. I'm also here to help others out in

  • LIS Sales Reports

    Dear Friends When I am using stand Sales Reports in LIS (MCA,MC(A, MCA, MC+2 ) I am getting report when I have entered only Date but not with customer or Article.  I am getting Error that "No data exists for chosen selection" I have maintained Custom

  • Reformatting external HD with Disk Utility doesn't seem to work?

    I've got two external hard disks - one Samsung 250GB and one 40GB which were previously formatted for and used with a PC. I'm trying to erase them and reformat them for Mac, using the 'erase disk' option in Disk Utility, but each time I try, for each

  • Can Servlet embed flash??

    hi,all Recently,I've start write servlet code,and client UI which use flash application.But I have problem with write out page through servlet. I want to know can servlet embed flash (swf.file).Below I post some section of my code. protected void doG