The Dreaded Classpath & Packages

Hi,
I'm semi new to Java (I just finished my first intro class), and to my surprise the prof. did not go into detail regarding classpaths and how to use them, blasphemy, I know. He had everyone rely on an IDE for this�
I have three problems compiling with packages.
     1) I don�t use an IDE, but instead compile at the command line.
     2) I am fairly new to the Mac (OS X), and don�t quite understand what the root      directory is. I know on my windows machine it�s C:\, but on my Mac I�m not sure      if it is User/ or something else.
     3) In regards to #2, I don�t know where my import statement should start. At      Users/ , or somewhere else?
Lets say I have one package called Phone.java located here:
     Users/JohnSmith/JavaLibrary/packages/PhonePackage
Then I have the main program which references this package located here:
     Users/JohnSmith/JavaLibrary/applications/AddressBook/address.java
How do I get the main program to compile the Phone Package? I�ve tried everything but can�t get it to work. I am assuming it�s something like javac �classpath �enter path� address.java. But I don�t know what the root should be, which throws off my claspath and my import statements.
Any help would be greatly appreciated!!!
Kevin

You need to compile both the files (Phone.java and address.java). First compile Phone.java by going to the directory:
Users/JohnSmith/JavaLibrary/packages/PhonePackage
And type in:javac -classpath . Phone.javathen go to
Users/JohnSmith/JavaLibrary/applications/AddressBook/
and type in:javac -classpath Users/JohnSmith/JavaLibrary/packages:. address.javaTo run, type:java -classpath Users/JohnSmith/JavaLibrary/packages:Users/JohnSmith/JavaLibrary/applications AddressBook.addressAll this assumes that the class Phone (contained in Phone.java) is in a package called PhonePackage and that the class address (contained in address.java) is in a a package called AddressBook.
A little nitpick: it's convention to use all lowercase letters for packages and capitalize the initial letter of each word in the name of a class. Following that rule, PhonePackage should be phonepackage, AddressBook should be addressbook and address should be Address.
ps. Not sure whether the multiple path seperator is : or ; in mac osx but since it's unix based I'm guessing it's :
Good luck.

Similar Messages

  • How to correctly import the jUnit classpath into an Ant buildfile on OS X

    Hi,-
    I'm trying to automate compilation with Ant & jUnit which I run from command-line on my Mac OS X. My source files are in the /src folder, test classes are in the /test folder, the .class files go into the /build folder, and junit38.jar is in the /lib folder. The build.xml file looks like this:
    <?xml version="1.0"?>
    <project name="Money" default="build-source" basedir=".">
        <description>The Money project build file.</description>
        <property name="src" location="."/>
        <property name="build" location="build"/>
        <property name="junit" location="lib/junit38.jar"/>
        <path id="_classpath">
            <pathelement location="${junit}"/>
            <pathelement location="${build}"/>
        </path>
        <target name="prepare">
            <mkdir dir="${build}"/>
        </target>
        <target name="build-source" depends="prepare" description="compile the source ">
            <javac srcdir="${src}" destdir="${build}"/>
        </target>
        <target name="test" depends="build-source">
            <javac srcdir="${test}" destdir="${build}"/>
        </target>
    </project>When I try to import jUnit with these declarations:
    import org.junit.* ;
    import static org.junit.Assert.* ;
    public class MoneyTester {
    }it says "package org.junit does not exist" and I can't extend the TestCase class with my own test classes. Can anyone tell how to properly set the jUnit classpath?
    Much appreciated! Cheers, Vahagn

    I see what you mean. It now looks like this, but the error won't go away:
        <target name="build-source" depends="prepare" description="compile the source ">
            <javac srcdir="${src}" destdir="${build}">
                <classpath refid="_classpath"/>
            </javac>
        </target>
        <target name="test" depends="build-source">
            <javac srcdir="${test}" destdir="${build}">
                <classpath refid="_classpath"/>
            </javac>
        </target>Edited by: Vahagn on Aug 14, 2010 11:59 AM

  • Classpath & packages

    I've been struggling to set up my package structure properly. Here's the situation:
    C:\project\impl2 :contains the files in "package impl2"
    C:\project\impl :contains classes that import impl2.* (let's call these the "child classes")
    (OS is Win2000)
    When I set the CLASSPATH=C:\project or compile with "-classpath c:\project", the child classes can "import impl2.*" fine, but can't see each other?? :( and when I disable those options they can see each other normally but naturally can't see package impl2.
    Eg: when I say "can't see each other" I mean:
    Say class X has 'import impl2.*' and compiles OK, then class Y that also has 'import impl2.*' and uses an instance of class X compiles with the error "Cannot resolve suymbol: class X location class Y ...etc...".
    with class X & Y both in c:\project\impl
    Now evidently I'm doing something wrong here, but I dunno what. Any replies whould be most appreciated.

    So if i want classes at location A to use a package at location B i muts include both A and B in the classpath, even if I'm compiling from A. I see...
    According to the Java tutorial at http://java.sun.com/docs/books/tutorial/java/interpack/usepkgs.html :
    "For your convenience, the Java runtime system automatically imports three entire packages:
    The default package (the package with no name)
    The java.lang package
    The current package "
    It was my understanding that "the default package" meant the classes at A in my example, but I guess to import it you still have to have the right classpath ;)
    I did have a problem when I tried to include 2 paths in the classpath, should something like
    -classpath c:\project\impl; c:\project\impl2
    do the trick?

  • Missing classes from the javax.swing package?

    Can anyone throw any light on what appears to be a missing class from the javax.swing package?
    When CelsiusConverter.java from The Swing Tutorial (code fragment shown below) is compiled the JFrame class can't be found.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CelsiusConverter implements ActionListener {
        JFrame converterFrame;Despite the package javax.swing being imported, the compiler does not seem to be be able to find the JFrame class.
    CelsiusConverter.java:14: Class JFrame not found in type declaration.
        JFrame converterFrame;To attempt to solve this issue all the files in jdk1.5.0_02\lib were added to CLASSPATH.
    CLASSPATH was set to C:\Program Files\Java\jdk1.5.0_02\lib\dt.jar;C:\Program Files\Java\jdk1.5.0_02\lib\htmlconverter.jar;C:\Program Files\Java\jdk1.5.0_02\lib\jconsole.jar;C:\Program Files\Java\jdk1.5.0_02\lib\tools.jar;C:\Program Files\Java\jdk1.5.0_02\lib;C:\Program Files\Java\jdk1.5.0_02\lib\ir.idl;C:\Program Files\Java\jdk1.5.0_02\lib\jawt.lib;C:\Program Files\Java\jdk1.5.0_02\lib\jvm.lib;C:\Program Files\Java\jdk1.5.0_02\lib\orb.idl;C:\Program Files\Java\jdk1.5.0_02\demo\jfc\SwingApplet\SwingApplet.jar;.;c:\CoreJavaBook

    This is extremely strange... If you're sure it's not a problem in your code or with your classpath, the only other thing I can think to suggest is re-downloading / installing java

  • Possible to access classes in other folders without the use of packages?

    Hi,
    I'm trying to write a kind of connector application, and I have come across this stumbling block.
    I have a folder for my main program classes, which will not change. External to that folder( either in a subdirectory or another directory on the same level) I want to have my classes to "connect". The connected classes will be compiled dynamically, as they depend on something in the main classes folder for complilation... I trust I can satisfy that using javac -classpath...
    The problem is that I would like one of the main classes to be able to access the connected classes at runtime, from the other folder. The collection of connected classes will be changing, so that, coupled with the fact that one of the main classes will be required to compile each connected class seems to rule out the use of packages for the connected classes.
    Is there a way to get around this?
    Thank you,
    Jesse

    Are you trying to dynamically compile Java classes (in external folders
    without packages) via Java? Yes, I will be (hopefully) using com.sun.tools.javac. I haven't done that part yet, as I don't want to waste my time on a design that is fundamentally flawed :)
    Does each new 'application' get placed into its ownfolder? No. I will be building a collection of new apps that will all be contained in one folder.
    Once an application is compiled, must it beimmediately available to the process that compiled
    it? Yes. Once an application is compiled I need it to be accessable from that point on.
    Thanks,
    Jesse

  • Oracle.jbo.JboException: JBO-34010: The "adf/tabs/view/DataBindings.cpx" descriptor appears in the application classpath more than once:

    Hello
    We are using JDeveloper 11.1.1.6
    We have three 3 separate viewcontroller projects and one Master projects which i supposed to integrate all these projects into one.
    Issue:
    After putting all three together into the Master project, the app fails to deploy due to this error:
    oracle.jbo.JboException: JBO-34010: The "adf/tabs/view/DataBindings.cpx" descriptor appears in the application classpath more than once:
    We did some digging and found out that it is because of the fact that "DataBindings.cpx" in all three projects falls withing the default package. How do we rectify this issue. We cannot even Refector this file because that option is not available for this file. We have a demo soon, What can we do?
    Thanks...

    Hi,
    this error typically comes from name clashes. Apparently you created ADF libraries (or projects) that contain a DataBindings.cpx file. The DataBindings.cpx file seems to be located in the same folder structure and thus could not be merged but are found to be added twice. When you create new view controller projects then best practice is to ensure the root package name is unique to avoid such issues.
    Frank

  • Another classpath-package question

    I have two classes residing in a directory called Record, and both classes declarepackage Record;as their first line of code. The RecordObject class instantiates the DBConnector class, and will not compile unless I strip the package declarations off both classes. The compile error for RecordObject (when both classes have the package directive) is:
    C:\jswdk-1.0.1\examples\WEB-INF\servlets\Record\RecordObj.java:9: cannot resolve symbol
    symbol : class DBConnector
    location: class Record.RecordObj
    static DBConnector dbc;
    ^
    C:\jswdk-1.0.1\examples\WEB-INF\servlets\Record\RecordObj.java:27: cannot resolve symbol
    symbol : variable DBConnector
    location: class Record.RecordObj
    connection = DBConnector.getInstance().getConnection();
    when only the RecordObject class has the package directive, the error is:
    C:\jswdk-1.0.1\examples\WEB-INF\servlets\Record\RecordObj.java:9: cannot access DBConnector
    bad class file: .\DBConnector.class
    class file contains wrong class: Record.DBConnector
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    static DBConnector dbc;
    Following the recent classpath posts, I just changed my classpath, but this did not help the compilation:
    C:\>set CLASSPATH=%CLASSPATH%;C:\jswdk-1.0.1\examples\WEB-INF\servlets;
    ^

    This is even stranger:
    When I enter "set" in the dos window that I set the classpath in, I see my setting. However, if I open a separate dos window and enter "set", there is no CLASSPATH entry at all.
    When I try to compile my RecordObj class from the command line of the dos window with the classpath, all is fine. I had been compiling from Textpad before. But when I try to compile from the other dos shell, I get the same errors that TextPad showed me.
    Could somebody explain how setting the CLASSPATH only sets it in one dos window, and not in the total environment? Thanks.

  • What is the diffrence between package javax.sql and java.sql

    Is javax designed for J2EE?
    And when to use package javax?

    Hi,
    What is the diffrence between package javax.sql and java.sql?The JDBC 2.0 & above API is comprised of two packages:
    1.The java.sql package and
    2.The javax.sql package.
    java.sql provides features mostly related to client
    side database functionalities where as the javax.sql
    package, which adds server-side capabilities.
    You automatically get both packages when you download the JavaTM 2 Platform, Standard Edition, Version 1.4 (J2SETM) or the JavaTM 2, Platform Enterprise Edition, Version 1.3 (J2EETM).
    For further information on this please visit our website at http://java.sun.com/j2se/1.3/docs/guide/jdbc/index.html
    Hope this helps.
    Good Luck.
    Gayam.Srinivasa Reddy
    Developer Technical Support
    Sun Micro Systems
    http://www.sun.com/developers/support/

  • Hi! I can't upgrade my iTunes 10.3.1.55 on my Windows XP 2002 SP3 to the latest version of iTunes. Got the message: "A problem has occured with the Windows Installer-package. A program needed for this installation could not be run." What to do?

    Hi! I can't upgrade my iTunes 10.3.1.55 on my Windows XP 2002 SP3 to the latest version of iTunes. Got the message: "A problem has occured with the Windows Installer-package. A program needed for this installation could not be run." What to do?

    Perhaps let's first try updating your Apple Software Update.
    Launch Apple Software Update ("Start > All Programs > Apple Software Update"). Does it launch and offer you a newer version of Apple Software Update? If so, choose to install just that update to Apple Software Update. (Deselect any other software offered at the same time.)
    If the ASU update goes through okay, try another iTunes install. Does it go through without the errors this time?

  • Identify the last data package in start routine

    Hi Everyone
    We have a start routine in transformations. We require to do some special processing in the start routine only when the last data package is executing. How can we determine in the start routine that current package is last one or not ? Any pointers in this direction are appreciated.

    Hi,
    You can get packet Id from datapackid in start routine and end routine. But I'm not so sure how to identify the last packet ID, alternatively you can store this packet id in some where else and read the same value in End routine if your logic(processing) permits to do this in End routine instead of Start routine.
    METHODS
          start_routine
            IMPORTING
              request                  type rsrequest
              datapackid               type rsdatapid
            EXPORTING
              monitor                  type rstr_ty_t_monitors
            CHANGING
              SOURCE_PACKAGE              type tyt_SC_1
            RAISING
              cx_rsrout_abort.
    hope it helps...
    regards.
    Raju

  • TS1398 Got the dreaded no wifi on my wife's iPhone 4S. Wifi greyed out and no luck with the reset network instructions. Why isn't Apple addressing this issue? We are a family of Apple product users, 2 ipads, an ipad mini, 4 iPhones but one isn't working!

    Got the dreaded no wifi on my wife's iPhone 4S. Wifi greyed out and no luck with the reset network instructions. Why isn't Apple addressing this issue? We are a family of Apple product users, 2 ipads, an ipad mini, 4 iPhones but one isn't working! Issue began whenwe upgraded the operating system.....
    Come on Apple.....get this issue sorted out!

    Just out of warranty. This is a software issue. everything was ok until the software update. Apple just need to sort it out.

  • How to print Photo Info in the Custom Print Package

    I am  using LR CC, latest version on a Windows7 PC.
    I am trying to print Photo Info in the Custom Print package. I have no trouble selecting Photo Info in the Single Image/Contact Sheet Layout Style, but when I switch to the Custom Print Package, the Photo Info check box in the Page panel, disappears. I can't find any reference to this in the manual as to why this would occur, or not be available.
    Appreciate any help with this matter.
    Best Regards
    Steve

    Hi,
    Have a look at: Lightroom Help | Print module layouts and templates
    Only on the Single Image and Contact Sheet layouts can you " ... print information about photos, such as the filename, title, caption, and keywords ..."

  • After getting the dreaded gray/blue screen, I tried to run disk repair on the internal disk. I got an error message saying "Disk Utility can't repair this disk and restore your backed-up files. The volume Macintosh HD could not be verified completely

    After getting the dreaded gray/blue screen, I tried to run disk repair on the internal disk. I got an error message saying "Disk Utility can't repair this disk and restore your backed-up files. The volume Macintosh HD could not be verified completely." What do I do now? This is an iMac and I'm running 10.6.8.

    Clean Install of Snow Leopard
    Be sure to make a backup first because the following procedure will erase
    the drive and everything on it. See below for how to clone a drive.
         1. Boot the computer using the Snow Leopard Installer Disc or the Disc 1 that came
             with your computer.  Insert the disc into the optical drive and restart the computer.
             After the chime press and hold down the  "C" key.  Release the key when you see
             a small spinning gear appear below the dark gray Apple logo.
         2. After the installer loads select your language and click on the Continue
             button. When the menu bar appears select Disk Utility from the Utilities menu.
             After DU loads select the hard drive entry from the left side list (mfgr.'s ID and drive
             size.)  Click on the Partition tab in the DU main window.  Set the number of
             partitions to one (1) from the Partitions drop down menu, click on Options button
             and select GUID, click on OK, then set the format type to MacOS Extended
             (Journaled, if supported), then click on the Apply button.
         3. When the formatting has completed quit DU and return to the installer.  Proceed
             with the OS X installation and follow the directions included with the installer.
         4. When the installation has completed your computer will Restart into the Setup
             Assistant. Be sure you configure your initial admin account with the exact same
             username and password that you used on your old drive. After you finish Setup
             Assistant will complete the installation after which you will be running a fresh
             install of OS X.  You can now begin the update process by opening Software
             Update and installing all recommended updates to bring your installation current.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.
    You may be able to backup your data if you have an erased external drive you can use. Before you do the above but after you have opened Disk Utility you can try to clone your drive:
    Clone using Restore Option of Disk Utility
      1. Open Disk Utility.
      2. Select the destination volume from the left side list.
      3. Click on the Restore tab in the DU main window.
      4. Select the destination volume from the left side list and drag
           it to the Destination entry field.
      5. Select the source volume from the left side list and drag it to
          the Source entry field.
      6. Double-check you got it right, then click on the Restore button.
    Destination means the external backup drive. Source means the internal startup drive.
    Now this will only work if the drive is accessible and can be cloned by Disk Utility. Otherwise, you would need to access your drive from another Mac that you can connect via Firewire - Target Disk Mode.

  • ITunes won't upgrade to10.5. Error message "There is a problem with the Windows installer package. Contact the package vendor". I need help.

    iTunes won't upgrade to10.5. I'm on 10.1.17.
    When installing 10.5 it terminates with an error message "There is a problem with the Windows  installer package. Contact the package vendor".
    It does not provide an error code or details/description to further troubleshoot. As a result I can't upgrade my Apple devices to leverage the cloud.
    Any smarts out there who could help?
    Using PC Win-7 w/IE 7 (should that matter)
    Thanks much

    I know there's a million threads like this, but I thought I'd record my experience.  I, too, was having the original poster's error when I tried to update iTunes on Windows XP.  I think I was stuck on 10. 
    I solved it by un-installing iTunes and every other Apple app.  I discovered that Apple Software Update would not un-install as its MSI file could not be found.  I used the "Windows Install Cleanup" tool from Microsoft to remove Apple Software Update from the list of installed programs.  Google "kb290301" for a Microsoft page that includes a download link for it.  After that, I was able to install a fresh copy of iTunes 10.5.2.
    I'm not sure why this app's folder and MSI were missing from my computer.  I had once used Laplink PC Mover to move everything from my old computer to this one, and perhaps it missed a bit.

  • HT203175 I have attempted to sync my new iPod touch 4th gen. with my current PC running Windows XP and everytime I attempt it I get the dreaded blue screen, here are the error codes- 0x0000007E; 0XC00000005; 0X00000000; 0XBA51B7C8; 0XBA51B4C4 any suggesti

    I have attempted to sync my new iPod touch 4th gen. with my current PC running Windows XP and everytime I attempt it I get the dreaded blue screen, here are the error codes- 0x0000007E; 0XC00000005; 0X00000000; 0XBA51B7C8; 0XBA51B4C4 any suggestions?

    In the course of your troubleshooting to date, have you worked through the following document?
    iPhone, iPad, or iPod touch: Windows displays a blue screen message or restarts when connecting your device

Maybe you are looking for