Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execute java files not from BIN!! How do I do that?

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have a question

I want to store my Java files not in Bin but in some other location and execute them. How do I do that?

Thanks in advance.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question makes no sense. Please give better details. Example command lines etc.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K.. this is what I meant.

Usually I save My programs say for example "prog1.java" in C:\Program Files\Java\jdk1.6.0_02\bin directory and then go to the command prompt and type all the path and execute it.

Instead of saving the file in the bin directory, I want to know if I can save it in say D:\My Programs and execute it?

Thanks.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course you can do that. And you certainly should be doing so. Putting your Java source code and classes in the JDK's "bin" directory is horrible.

Really, this doesn't have much to do with Java, and is just basic use of the command shell, such as Windows Command Prompt. If you are going to be doing development, using tools from a command shell, you really need to learn about this stuff, or you will get nowhere.

For your specific question, your choices are: -

  • When running "javac", "java" etc, give the full path to these programs, within the JDK
  • Set an environment variable to point to the "bin" directory in the JDK, and use the environment variable as part of the path to "javac", "java" etc.
  • Modify the PATH environment variable, to include the "bin" directory in the JDK. Then you can just type "javac", "java" in any directory.


  • As an entirely different approach would be to stop using the command shell and get yourself a Java IDE like NetBeans or Eclipse. I don't use these, so I can't advise on them, but I believe they do make things easier for beginners.
     
    Arjun Reddy
    Ranch Hand
    Posts: 629
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for replying back Peter. I've changed the Environmental Variable "Path" under "System Variables" to C:\Program Files\Java\JDK1.6.0_02\bin;%path%;

    It still doesn't work. I went back to C:\ and typed in javac.. It says Bad Command.
    [ November 13, 2007: Message edited by: Arjun Reddy ]
     
    Raghavan Muthu
    Ranch Hand
    Posts: 3381
    Mac MySQL Database Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    As peter told, you can add the path to your 'JDK's bin' direcotry at the end.

    You can do so by pasting the location to the directory (make sure you copy it from the root drive like C:\Java\Jdk6\bin for example) and append it at the end of the PATH variable.

    You get a button called 'Edit' when you click on the "Path" in the list of available environment variables.
     
    Arjun Reddy
    Ranch Hand
    Posts: 629
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the replies guys. I will try to make it work.
     
    fred rosenberger
    lowercase baba
    Bartender
    Pie
    Posts: 12097
    30
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    also note that on windows, you must open a new command window after editing your path. the window reads the path variable when it first opens. An existing window will not automatically pick up any changes you might make.
     
    Arjun Reddy
    Ranch Hand
    Posts: 629
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Fred it worked. Thanks to Peter and Raghavan too
     
    Stan James
    (instanceof Sidekick)
    Ranch Hand
    Posts: 8791
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    See if this helps, too. Under bullet 4 it talks about the -d parameter that specifies where the class files should go.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic