• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to compile the classes in a user-defined package

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My apologies if this topic has already been addressed.
I'm attempting to teach myself JAVA 1.6 SE from Murach's Java SE 6. I originally learned on Java 1.4.
I tried following the directions in the book to use the command prompt to compile a class named LineItem.java. The class path leading to the class is C:\ Documents and Settings\User\My Documents\Java\MurachJava\JPractice\Ch09\LineItemX9-1. I tried to append > javac murach/business/ LineItem.java to this, and got the error message, 'My' is not recognized as an internal or external command, operable program or batch file.
I tried enclosing "My Documents" in double quotes, and got the error message, The filename, directoryname, or volume label syntax is incorrect.
I went to my old Java instructor. He told me to type the following into the command prompt; "C:\Program Files\Java\jdk1.6.0_26\bin\javac.exe", then "C:\Documents and Settings\User\My Documents\Java\MurachJava\JPractice\Ch09\LineItemX9-1\murach\business\LineItem.java". I still got the error message, the filename, directoryname, or volume label syntax is incorrect.
How do I set the classpath to this class in the package I defined so it will compile?
Thank you in advance for your help.

Eric Kantola
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should simplify things a bit - your main problem comes from having spaces in the path - Windows can have problems interpreting spaces in paths unless you get the syntax just right. So my first suggestion would be to move your code to a path with no spaces - maybe something like: "C:\code\JPractice\CH09\LineItemX9-1\"

Then double check that your javac.exe is actually located in the path "C:\Program Files\Java\jdk1.6.0_26\bin\". If it is there then you can can do this:

1) Open a new Command Prompt
2) Change directory to the top of your classpath (C:\code\JPractice\CH09\LineItemX9-1\).
3) Type in the command (including quotes): "C:\Program Files\Java\jdk1.6.0_26\bin\javac.exe" -cp ./ murach/business/LineItem.java

That assumes that your package is murach.business. For example, I have this Java file, in the package murach.business:


I saved the java file in the correct package structure under the path C:\code\JPractice\CH09\LineItemX9-1\


I then opened up a Command Prompt, used cd C:\code\JPractice\CH09\LineItemX9-1\ to change the directory to the base classpath. After that I ran the command I used above, but using the path to where I have the JDK installed.

 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why have you been told to set a classpath? It usually does more harm than good to set a system classpath, so you are better using the -cp tag. You should be setting a PATH to include your Java™ bin folder, however, as described in many places, eg here.
 
Eric Kantola
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Steve. I appreciate it.
Cambell, The chapter I was working on was user-defined packages, enums and Javadocs. The value-added text editor I use for writing Java code is TextPad, and TextPad doesn't support compiling some files in packages. Besides, I also need to set the classpath to do the Javadocs stuff in the command prompt, and appear to be getting the same error messages there. Thanks for the link, by the way, Campbell, and the welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic