aspose file tools*
The moose likes Beginning Java and the fly likes moose greetings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "moose greetings" Watch "moose greetings" New topic
Author

moose greetings

chris crouch
Greenhorn

Joined: Dec 03, 2012
Posts: 6
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

Joined: Mar 26, 2012
Posts: 186

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.


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36578
    
  16
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

Joined: Oct 13, 2005
Posts: 36578
    
  16
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

Joined: Jun 19, 2010
Posts: 825
    
    5

In addition, you can find detailed instructions on how to set environment variable properly here.


The quieter you are, the more you are able to hear.
chris crouch
Greenhorn

Joined: Dec 03, 2012
Posts: 6
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

Joined: Dec 03, 2012
Posts: 6
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

Joined: Mar 26, 2012
Posts: 186

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

Joined: Dec 03, 2012
Posts: 6
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

Joined: Oct 13, 2005
Posts: 36578
    
  16
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

Joined: Oct 13, 2005
Posts: 36578
    
  16
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

Joined: Dec 03, 2012
Posts: 6
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

Joined: Oct 13, 2005
Posts: 36578
    
  16
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

Joined: Oct 13, 2005
Posts: 36578
    
  16
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

Joined: Dec 03, 2012
Posts: 6
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

Joined: Oct 13, 2005
Posts: 36578
    
  16
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: moose greetings
 
Similar Threads
Java on 32 Bit Windows?
Trouble installing JDK 7
Compile "MooseGreetings.java" Access Denied
Issues with checking that my JDK is configured properly
compiling packages with javac using appropriate directory structure