[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

javac and java -classpath concepts

1)Is there a way to set the classpath variable in both javac and java so that I do not need to convey it explicitly in the command line via navigating to the directory or as an arguement? For example, in Control Panel/System/Advanced/Environment Variables--User or System)

2)Is it true:  You only need to specify the entire package name after it has been compiled. (When running it) One only needs to provide the name of the file.java when compiling if the are in the corresponding directory.


0
kellyputty
Asked:
kellyputty
  • 5
  • 3
  • 3
2 Solutions
 
hoomanvCommented:
1) yes
set this environment variable
set CLASSPATH=you classpath
0
 
hoomanvCommented:
may be helpful
mindprod.com/jgloss/classpath.html
0
 
kellyputtyAuthor Commented:
The following is what I have set but javac and java don't "see" it:
CLASSPATH=C:\java\code

What could I be doing incorrectly such that javac and java aren't "seeing" the environment variable CLASSPATH?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hoomanvCommented:
type the command you use to run the class
0
 
mrigankCommented:
1) Yes.

a)My Computer->Proprties->Advanced->Environment Variables

Add a system variable called CLASSPATH. Put the directories that you want there as the value of the variable.

b) As hoomanv said, set CLASSPATH=%CLASSPATH%;Your Classpath here.

2) Yes it is true.
0
 
mrigankCommented:
2) If you have a class a.b.c.D.java

javac is like

home\a\b\c>javac D.java

java is like

home>java a.b.c.D
0
 
mrigankCommented:
Use

cmd>set CLASSPATH=%CLASSPAHT%;C:\java\code
0
 
mrigankCommented:
sorry, a typo

cmd>set CLASSPATH=%CLASSPATH%;C:\java\code
0
 
kellyputtyAuthor Commented:
mrigank said:
My Computer->Proprties->Advanced->Environment Variables

Add a system variable called CLASSPATH

>>CLASSPATH=C:\java\code;C:\java\oreilly\examples;  (I have source code in both)
-----------------
hoomany asked:
 type the command you use to run the class
>>
C:\java\code\c08\music5>javac Music5.java
But even the the CLASSPATH system variable is set, javac doesn't "see" it.
0
 
kellyputtyAuthor Commented:
mrigank, thank you that worked---
cmd>set CLASSPATH=%CLASSPATH%;C:\java\code
0
 
mrigankCommented:
:-)

no worries.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now