wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Execute java files not from BIN!! How do I do that? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Execute java files not from BIN!! How do I do that?" Watch "Execute java files not from BIN!! How do I do that?" New topic
Author

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

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
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.


Be Humble... Be Nice.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
This question makes no sense. Please give better details. Example command lines etc.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
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

Joined: Oct 30, 2001
Posts: 1970
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

    Joined: Nov 10, 2007
    Posts: 627
    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

    Joined: Apr 20, 2006
    Posts: 3344

    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.


    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    Arjun Reddy
    Ranch Hand

    Joined: Nov 10, 2007
    Posts: 627
    Thanks for the replies guys. I will try to make it work.
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11153
        
      16

    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.


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Arjun Reddy
    Ranch Hand

    Joined: Nov 10, 2007
    Posts: 627
    Thanks Fred it worked. Thanks to Peter and Raghavan too
    Stan James
    (instanceof Sidekick)
    Ranch Hand

    Joined: Jan 29, 2003
    Posts: 8791
    See if this helps, too. Under bullet 4 it talks about the -d parameter that specifies where the class files should go.


    A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Execute java files not from BIN!! How do I do that?
     
    Similar Threads
    jdk1.3.0_02 PATH????????????
    I need to set the classpath
    Class file and File having extension bin
    Taking community college online course in Java 1
    Tomcat: Starting It Up