• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 7113
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: 7113
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: 76408
365
  • 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: 76408
365
  • 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: 14266
321
  • 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.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic