6 Replies Latest reply: Jan 14, 2013 5:25 AM by EJP RSS

    Package Compilation Error

    984615
      Hi,
      i have started learning Packages.I am getting an error while compiling Package from Command Prompt.

      /*
      package com.jlc.p1;
      class Hello
      {
      void m1()
      {
      System.out.println("Package program Test in m1()");
      }
      }


      class Test84
      {
      public static void main(String args[ ])
      {
      Hello h1=new Hello();
      h1.m1();
      }
      }
      */


      When i am compiling it from Command Prompt
      as
      c:\Java Programs>javac -d.Test84.java
      I am gettiing the error

      javac: directory not found: .Test84.java
      Usage: javac <options> <source files>
      use -help for a list of possible options



      Please help me out
        • 1. Re: Package Compilation Error
          980759
          try this
          c:\Java Programs>javac com.jlc.p1.Test84.java
          • 2. Re: Package Compilation Error
            gimbal2
            Dayananda B V wrote:
            try this
            c:\Java Programs>javac com.jlc.p1.Test84.java
            You're guessing again, and yet again you're wrong.

            sigh, I don't like to answer when I can see only one thing was tried and then the stuff was dumped on a forum but now I feel obliged. The command used to compile is wrong, you just do a regular javac Filename.java, even when there are packages in play. The trick is to use a proper folder structure.

            Say that your classpath is this:
            -cp .;c:\java\project
            Our "project" directory is where we are going to store our Java application, with packages. If you have a class "myapp.model.User", so it is a class User in the package myapp.model, you would store it like this:

            c:\java\project\myapp\model\User.java

            See how that works? The package directory structure starts in the folder that is part of the classpath. To compile, simply navigate to the model subdirectory and type javac *.java to lazily compile everything in that directory, or pass the specific filename. That will produce a .class file in the same directory. You can make sure that classes are compiled to a different directory, but I wouldn't bother with that when you're still learning; it is best left over to automation tools such as an IDE or ANT/Maven.

            Now when you have all your classes neatly compiled in their proper directories you will want to run the application with a package. Lets say we have a class myapp.Main which has a main() function, you can run that with:
            java -cp c:\project myapp.Main
            Again c:\project is added to the classpath so that Java knows to look there for classes (and classes in packages).
            • 3. Re: Package Compilation Error
              EJP
              Dayananda B V wrote:
              try this
              c:\Java Programs>javac com.jlc.p1.Test84.java
              Please don't post untested guesswork here. This answer is complete and utter rubbish.
              • 4. Re: Package Compilation Error
                980759
                i completely agree , here I thought the class path set to c:\Java Programs
                • 5. Re: Package Compilation Error
                  Kayaman
                  Dayananda B V wrote:
                  i completely agree , here I thought the class path set to c:\Java Programs
                  It would've still been wrong. Please don't try to "help" people, when you don't know what you're doing.
                  • 6. Re: Package Compilation Error
                    EJP
                    Please don't post untested guesswork here. This answer is complete and utter rubbish.
                    i completely agree , here I thought the class path set to c:\Java Programs
                    And so is this. More untested guesswork, more rubbish.