• Post Reply Bookmark Topic Watch Topic
  • New Topic

Run/execute .java file not from c drive  RSS feed

 
Brayn Richard
Greenhorn
Posts: 14
Java Mac Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you execute java -version from the command line?
 
Brayn Richard
Greenhorn
Posts: 14
Java Mac Oracle
  • Mark post as helpful
  • send pies
  • 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: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Ryan Gabriel
Greenhorn
Posts: 20
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be this this link here can help you.
 
Campbell Ritchie
Marshal
Posts: 55788
164
  • Mark post as helpful
  • send pies
  • 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.
 
Shubhendu Pramanik.
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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: 55788
164
  • Mark post as helpful
  • send pies
  • 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.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And CLASSPATH should not be set in your environment variables anyway.
It should be a project specific setting.
 
Stephan van Hulst
Saloon Keeper
Posts: 7821
142
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!