Results 1 to 5 of 5
  1. #1
    b-style is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Compiling a Class into a Package Problem -

    hello -

    i am attempting to compile a java class into a package from the command line.

    - i am able to process javac ProblemServlet.java

    - however when i attempt to javac -d ProblemServlet.java, receive the following error in the command line:

    javac: invalid flag: files/apache
    Usage: javac <options> <source files>
    use -help for a list of possible options.
    -------------------------------------------------

    backstory - i've just moved an older application from a JRUN server to a TOMCAT 7 server running on Windows 7 Prof and need to change the database connnection string.

    the servlets i'm am adjusting have been complied previously in the JRUN environment, so the file structure or the package details have not been altered. i am simply trying to adjust database connection strings.

    surely i am missing something. but i am unclear as to why javac = fine, but javac -d = unable to compile.

    any suggestions or ideas would be great.

    thanks in advance.

    best,
    mb.

  2. #2
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Compiling a Class into a Package Problem -

    According to "javac -help", the -d flag requires a directory. You gave it a file. Give it what it wants and I expect it will gladly give you what you want.

  3. #3
    b-style is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Compiling a Class into a Package Problem -

    thx jlczuk.

    and i agree. the issue is when i use javac ProblemServlet.java -d PackageLevelA, then it complies the class into a package that looks like PackageLevelA > PackageLevelA > PackageLevelB>ProblemServlet. Class versus what i want of:

    PackageLevelA > PackageLevelB > ProblemServlet.Class

    Since I have to be in the class directory to compile ProblemServlet.java - I am unable to reach my desired goal.

    Any insights ?

  4. #4
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Compiling a Class into a Package Problem -

    I wish I could be of more help, but I work in Eclipse, so I don't use javac brute force from a command prompt. Generally, the source tree structure mirrors the package name. So if ProblemServlet is in package PackageLevelA.PackageLevelB the source file will be in PackageLevelA/PackageLevelB/ProblemServlet.java.

    Have you tried running javac, without -d, from the parent directory of PackageLevelA? I would expect the .class file to be created in the same directory as the source.

  5. #5
    b-style is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Compiling a Class into a Package Problem -

    appreciate the help. actual solution turned out to be:

    javac ProblemServlet.java -d .

    this then allowed for the class to be compiled in the proper/necessary package while keeping all .java files in the web-inf/classes folder.

    thanks again for your time.

    best,
    mb.

Similar Threads

  1. CMD Package Compiling
    By buston01 in forum Advanced Java
    Replies: 2
    Last Post: 12-10-2010, 07:04 AM
  2. Facing problem in compiling user defined package
    By UJJAL DHAR in forum New To Java
    Replies: 2
    Last Post: 05-24-2010, 11:40 AM
  3. Package Compiling
    By kaperks in forum Advanced Java
    Replies: 1
    Last Post: 02-23-2009, 02:56 PM
  4. [SOLVED] Compiling Package Class
    By nwboy74 in forum New To Java
    Replies: 3
    Last Post: 11-14-2008, 11:19 PM
  5. Compiling a class in a package from cmd
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •