Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

moose greetings

 
chris crouch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey there,
i have browsed some of the older post though i cant seem to find an answer,

I have checked my javac version which works and also compiled the moose greetings into a class file, though when i try to run it through the cmd it gives me either
all of the java options
or
not reconqnized as a batch

iv tried
C:\java\src\java -classpath . moosegreetings
java -classpath C:\java\src\moosegreetings
java -classpath C:\java\src\moosegreetings.class

and i am a little confused



 
Rajdeep Biswas
Ranch Hand
Posts: 221
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Ranch.

When you open cmd, browse to the .class containing directory and type javac and java individually, what do you see?
Plus what do you know about running a class? How to do it? [looking at your current knowledge]

Edit: Have you set your "path" and "classpath" environment variables? When you enter echo %path% and echo %classpath% in cmd individually, what do you see please post them here.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That is a very common problem, caused by not setting a path variable. Don’t set a classpath. You can find details of setting the path in the Java Tutorials common problems page (and guess which problem comes up first!) or one of our FAQ. Note the two solutions are slightly different, but both work.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very peculiar if you can get javac to work and not java. If sorting out your path doesn’t help, try re‑installing the JDK with the same location as previously.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, you can find detailed instructions on how to set environment variable properly here.
 
chris crouch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys thanks for the fast responses,


Rajdeep Biswas wrote:Welcome to Ranch.

When you open cmd, browse to the .class containing directory and type javac and java individually, what do you see?
Plus what do you know about running a class? How to do it? [looking at your current knowledge]

Edit: Have you set your "path" and "classpath" environment variables? When you enter echo %path% and echo %classpath% in cmd individually, what do you see please post them here.


i think this is where the problem is, when i echo the path i get
C:\Program Files\Java\ jdk1.7.0_09\bin; plus other paths
though when i echo classpath i get
C:\Program Files\QuickTime\QTsystem\QTjava.zip

so i added %JAVA_HOME%\bin into the begining of classpath and when i echo %classpath% i get
C:\Program Files\Java\ jdk1.7.0_09\bin
i thought i had fixed the problem though when i type java -classpath . MooseGreetings i get access denied and when i run cmd as admin i get it doesnt recongnize it as a batch file?
 
chris crouch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i typed for %i in (javac.exe) do @echo %~$PATH:i
into the cmd and the reply was
C:\Program Files\Java\jdk1.7.0_09\bin\javac.exe

im just unsure of why i can run the class file
 
Rajdeep Biswas
Ranch Hand
Posts: 221
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris crouch wrote:..so i added %JAVA_HOME%\bin into the begining of classpath and when i echo %classpath% i get C:\Program Files\Java\ jdk1.7.0_09\bin..

Please modify it as:
.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib


1. The dot that you will add in the beginning represents current directory for locating classes[many people say its not required, but I have not tested yet.]
2. The second entry has JDK lib folder that has necessary jar files
3. The third has JRE lib folder.

Is it working after modification?
If not, please uninstall JDK, and reinstall and follow the above points for setting the environment variables [See above post by Kemal Sokolovic has a link].
 
chris crouch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i changed the classpath to what you said and when i echo %classpath% i get
.:C:\Program Files\Java\jdk1.7.0_09\lib;C:\Program Files\Java\jdk1.7.0_09\lib;

though it is still telling me that access is denied

maybe i should uninstall and reinstall
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris crouch wrote: . . .

so i added %JAVA_HOME%\bin into the begining of classpath and when i echo %classpath% i get
. . .
No, I’m afraid that was a mistake. That sort of thing belongs in the PATH. If JAVA_HOME includes the JDK installation folder, you don’t need the JRE folder in your PATH at all.
You appear to have hit the QuickTime (QT) problem; if you install QT it is notorious for setting a classpath while you aren’t watching and that messes up your Java programming.

The solution to the QT classpath problem is to add a dot for “current directory” to the classpath. Add dot‑semicolon .; (no spaces) to the beginning of the classpath. Remove the entry for the Java installation directory from the classpath. Leave the QT entry unchanged (or restore it from your previous post). You will probably have to enclose the whole classpath in quote marks because of the space in the QT entry.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris crouch wrote: . . .
maybe i should uninstall and reinstall
Not yet. Print the classpath and path with echo %PATH% and echo %CLASSPATH%
Get your Java version with java -version and javac -version
Show us the output, whether real or error. We have an FAQ about how to copy the error messages.
 
chris crouch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
echo %class% output was
C:\Program Files\Java\jdk1.7.0_09\bin; other non related paths

echo %classpath% was
.;C:\Program Files\Java\jdk1.7.0_09\lib;C:\Program Files\Java\jdk1.7.0_09\lib;.quick time path

java -version is
java version "1.7.0_09"
java TM SE Runtime Enviroment(build 1.7.0_09-bo5)
java hotspot TM client VM (build 23.5-bo2, mixed mode, sharing)

javac -version is
javac 1.7.0_09
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the fact that you should delete the JDK and JRE lib folder from the classpath, I can’t see anything else wrong. The JVM looks in the JDK installation folder for classes as a default, so those entries are not necessary.
I presume the JDK1.7.0_09 entry was at the beginning of the PATH? You can get problems if it is at the end of the PATH, because you might be compiling with a JDK7 version of javac and running the .class files with a JDK6 version of java.
If you get numbers from java -version/javac -version (and Hotspot), that suggests your PATH and installation are probably correct.
Have you created yourself a java folder? That is a good idea. You can give it any name you like, and you use the mkdir command to create such a folder and cd to use it. Try the moose greetings file inside that folder, and run it from the very same folder. That is what the . for current directory is for.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I earlier wrote:. . .
I presume the JDK1.7.0_09 entry was at the beginning of the PATH? . . .
If you get 1.7.0_09 as version numbers for both programs, then it probably is in the right place in the PATH.
 
chris crouch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeaaa i ran it as admin as it wouldnt allow me to use the mkdir, i created a new folder and copied in the file, re-compilled and ran the class and it worked moooooed away
cheers guys and campbell for your time
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome and well done.

But why did you have to run as admin? Surely the command prompt opens in your personal documents folder or similar, where you have permission to create folders as a default?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic