• 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

Run/execute .java file not from c drive

 
Greenhorn
Posts: 14
Mac Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okey, to make thinks shorter/ simpler -
I have installed my jdk in D:\Program files\Java and jre in D:\Program files\Java_jre
Now I want to run .java files from anywhere of my pc not C:\Users\Anyname. As we are learning java in cmd.
How can I do that?
Sorry if I am asking in a wrong wing.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you execute java -version from the command line?
 
Brayn Richard
Greenhorn
Posts: 14
Mac Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:What happens if you execute java -version from the command line?


It says-
java version "1.8.0_65"
Java(TM) SE Runtime Environment (bulld 1.8.0_65-b17)
Java HotSpot (TM) 64-Bit Server VM (bulld 25.65-b01, mixed mode)

I think java is working fine. I guess
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like it. Try a simple .java file and see if it works. Note: package statements, while very necessary in "real life", can make executing on the command line a little tricky. Just a heads-up.
 
Greenhorn
Posts: 20
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be this this link here can help you.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you have to do (as already suggested) is move your command prompt to point to the directory where your Java® work lives. You can change to the D: drive (I think) by passing the command
d
and then you can use the cd command to move to a different directory. I have my own ideas how you do that: look here for a simple way to create a directory.
 
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set environment variables like below(put your local path)

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_45
CLASSPATH = .;C:\Program Files\Java\jdk1.8.0_45\bin
PATH = C:\Program Files\Java\jdk1.8.0_45\bin

If even after doing so it doesn't work, there must be an older version of java installed on your machine too. Find and remove that one.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? The OP appears to have a PATH correctly set already. The PATH settings you suggest are out of date; you should be using JDK8u65/66.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Subho Pramanik wrote:Set environment variables like below(put your local path)

CLASSPATH = .;C:\Program Files\Java\jdk1.8.0_45\bin


This is wrong. Your CLASSPATH should not include the bin directory of the JDK.

The CLASSPATH is what Java uses to look for compiled class files. The bin directory of the JDK does not contain compiled class files.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And CLASSPATH should not be set in your environment variables anyway.
It should be a project specific setting.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree. Usually when I'm working on a simple Java project without an IDE, I write a little batch file for the project that calls javac with the appropriate source- and classpaths, and output directory, and another one to run the application. Makes life a lot easier.
reply
    Bookmark Topic Watch Topic
  • New Topic