Running Class file

Hello,
I am a beginner.
I got a problem which is every time I run a class file after compiling *.java. I have to type the whole path
java -classpath C: (foldername) (filename)
to run the program.
It is suppose to be no problem once I can run the command "javac" successfully. Now everytime I have to type
javac (filename)
Also the setting still got something wrong which it cannot generate the path to /Lib/tools.jar as well
Could anyone help me on this?
Thank you very much
My operating system is Window 98 SE
Here is my autoexec.bat setting:
SET PATH=c:\windows;c:\windows\COMMAND;C:\PROGRA~1\SYMANTEC\PCANYW~1
@SET CLASSPATH=C:\PROGRA~1\PHOTOD~1\ADOBEC~1
SET PATH=%PATH%;C:\PROGRA~1\COMMON~1\AUTODE~1
SET PATH=%PATH%;c:\PROGRA~1\COMMON~1\AUTODE~1
PATH C:\WINDOWS;C:\WINDOWS\COMMAND
SET PATH=%PATH%;C:\JAVA\BIN
set CLASSPATH=.:C:\JAVA\lib\tools.jar
PATH c:\windows;c:\windows\COMMAND;C:\WINDOWS/DESKTOP
SET CLASSPATH=C:\WINDOWS\COMMAND;C:\WINDOWS/DESKTOP

Your batch file overrides the value of CLASSPATH several times. Try putting the paths of everything you require into the last instance of the "SET CLASSPATH" line and then eliminate all other instances of it for purposes of readability.
By the way, this kind of question should probably not be posted in the "Java Virtual Machine" forum. No offense, but the "New to Java Technology" forum would be more appropriate.

Similar Messages

  • Running class files from the windows command line...

    Hello Everyone,
    My instructor showed us a way to run class files from the windows command line. However every time I try to run the class file from the command line using a command like: java CruiseHelper.class
    I get an error that states "Exception in thread "main" java.lang.NoClassDefFoundError: CruiseHelper/class"

    Hello Everyone,
    My instructor showed us a way to run class files from
    the windows command line. However every time I try
    to run the class file from the command line using a
    command like: java CruiseHelper.class
    I get an error that states "Exception in thread
    "main" java.lang.NoClassDefFoundError:
    CruiseHelper/class"Classes are not file names. You don't have a class named "CruiseHelper.class", that's a file name. The class name is just CruiseHelper (if you have no package statement in it).
    So,
    java -classpath . CruiseHelper

  • How to run .class file and .jar file in jdev9i

    I want to run .class file and .jar file in jdev9i,what should I do?
    Also,I want to generate .class file and .jar file in jdev9i,what should i do?

    Add the .class file containing the public static void main(...) method to the project by clicking on the + toolbar button in the navigator, open the project properties and properly set the additional classpath then right click on the .class in the navigator and say run. It should work, I've just tried it.
    Doesn't work for a .jar yet, in JDeveloper 9.0.3 it works both for .class and .jar
    Michel

  • How to run class files in a jar independently.

    Hello all
    I have a java file which use an API.jar file which is an API file of some other application of mine.This file form a sought of client for that application.Now i want to run this file from command line which is giving NoClassDefFoundError exception.This exception is because of the dependency over API.jar.I dont want to pack this single file into a jar and then run that jar since it only makes a simple task complicated and makes a simple class look like a big application.Can anybody tell me the solution to it?
    Regards,
    Mansi

    MansiSachar wrote:
    I am working on WindowsXP and the command u just sent is again giving the same exception.The exception is :
    Exception in thread "main" java.lang.NoClassDefFoundError: ûcp
    Caused by: java.lang.ClassNotFoundException: ûcp
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    I think the problem can also be the placement of the dependant jars.do i need to keep them in "bin" folder?I am assuming that in the error message, it says "-cp" not "ûcp" Can you confirm that you entered the command as posted? Because it looks like java.exe sees the -cp as the class to execute instead of the classpath option.
    Try using -classpath instead of -cp. What version of java are you using? (java -version should give you the version).
    If the jars are in the current directory, the placement of the jar files is correct.

  • Running .CLASS file in Java JDK1.3.1_19

    Hello
    i am an old java programmer. but stopped for a while... so i guess im a bit rusy at it...
    anyway...
    i installed jdk1.3.1_19 on my pc and did everything as they asked for in the installation but i get an error wen i run the .CLASS file
    the error i get is:
    "exception in thread 'main' java.lang.NoClassDefFoundError: C:\jexamples\Welcome1"
    i read a documentation abt some CLASSPATH... which im kinda confused abt... how do i set that? and wat do i set it as?...
    Thanx for the help in advance!

    i am an old java programmer. but stopped for a
    while... so i guess im a bit rusy at it...
    anyway...
    i installed jdk1.3.1_19 on my pc Why did you install an old version instead of the latest version?
    and did everything
    as they asked for in the installation but i get an
    error wen i run the .CLASS file
    the error i get is:
    "exception in thread 'main'
    java.lang.NoClassDefFoundError:
    C:\jexamples\Welcome1"
    i read a documentation abt some CLASSPATH... which im
    kinda confused abt... how do i set that? and wat do i
    set it as?...Do not set or use the CLASSPATH environment variable. Instead use the -classpath option when compiling or running your programs. Otherwise, you'll never figure out what's going on.
    When asking about compiling problems, you need to post:
    1) The path to all the files used in your program
    2) The prompt where you entered the commmand
    3) The actual command you entered

  • Running  .class file from autoexec.bat (in Windows Xp environment)

    How to run a .class file from autoexec.bat file. I have WinXP installed on my PC. I tried the solution given by Forum memebers but they didn't work.
    after setting the classpath
    i wrote
    java -cp simple in autoexec.bat , but results were not satisfactory.

    What does "not satisfactory" mean? If the commans works from any .bat file, it'll work from autoexec.bat, too.
    May I ask what you're trying to accomplish? I'm not sure whether XP dtill uses autoexec.bat for console initialization after all.

  • Cannot run .class file.  What's wrong, please?

    Hi,
    I have installed J2SDK1.4.2_03 in D: drive in folder JavaApplications.
    Have appended the path: ;D:\JavaApplications\bin in System Variable.
    Written a simple program named WhatIsYourName.java and saved in D:\JavaPractices
    At D:\JavaPractices> compile the program using javac WhatIsYourName.java and it is OK
    At D:\JavaPractices> checked directory and the WhatIsYourName.class file is there.
    When typed: java WhatIsYourName
    Error message appears:
    Error: could not open C:\Program Files\Java\j2re1.4.2_03\lib\i386\jvm.cfg
    Reinstalled J2SDK1.4.2_03 in D: drive in folder JavaApplications again, same error.
    When I checked the C:\Program Files, there is a bin and lib folders residing in a 1.3.1_07 folder in the JRE folder. The JRE folder is found in a folder called JavaSoft. Is it because of this that the error occurred?
    Could not understand why?
    Please help.
    Thank you very much.
    Theophilus

    Hi ChuckBing,
    You are right. The older version is being found first. After removing the older version I can run the .class file.
    Need to ask you about checking the full path when invoking java which you suggested. At D:\JavaPractices directory am I supposed to type \JavaApplications\bin\java WhatIsYourName ? I don't quite get what you mean.
    Thank you very much.
    Theophilus Mah

  • Java not running .class files

    I rebooted my computer, and now whenever I type
    java <filename> it responds with:
    C:\Development\Java\Projects\Scratch>java T1
    Exception in thread "main" java.lang.NoClassDefFoundError: T1
    However, it compiles fine:
    class foo {
    class T1 {
        public static void main (String [] args) {
            foo [] fooArray = new foo[5];
            if (fooArray[1] instanceof Object)
              System.out.println("fooArray[1] is an object");
            if (fooArray[1] instanceof foo)
              System.out.println("fooArray[1] is a foo");
    }What am I missing to get it to run with java T1?
    (every other class file that used to work behaves the same way)

    Yes, it is the classpath. Strangely . is in my classpath in the environment settings in the control panel. I guess I can survive adding -cp . but it is kind of a pain in the a__ for no reason I can discern

  • I can compile java, but I cannot run class file.

    Exception in thread "main" java.lang.NoClassDefFoundError: Demonstrate
    That is the error I get when I type: java Demonstrate
    I have "C:\j2sdk1.4.0\bin" in the path for the Environment Variables in windows xp. I've even tried to insert that into a CLASSPATH several ways and it does not change the error.
    javac Demonstrate.java works fine. That compiled file can work on other computers. Because of that, I do not think it's a setting error. Any ideas ? Thanks for any help.

    Microsoft problem? I like nothing better than bashing M$, but this sounds like a CLASSPATH problem to me.
    I'll assume that your Demonstrate.java does NOT have a package statement in it and has a main method that you'd like to run. If so, you compile like this:
    javac Demonstrate.javaThe result is a Demonstrate.class file in the same directory as Demonstrate.java.
    Now, type this in the command shell right in the directory where Demonstrate.class lives to run it:
    java -classpath . DemonstrateYou won't get that ClassNotFoundException.
    Whenever you see that exception, it means you don't have your CLASSPATH set properly. - MOD
    You won't get ta

  • How to create a .bat file to run *.class files?

    Hello.
    I have compiled java *.class files.
    I would like to make a shortcut on my desktop to run my Java programs.
    How to write a shortcut (.bat file or something else) to run Java programs?
    Thanks

    1) Make it into an executable jar file (internet search for "java executable jar" will give you lots of help)
    2) Write a batch file. If you do not know how to do this, a Java forum is not the place to find out. Do an internet search or find a windows support site.

  • PATH VARIABLES AND RUNNING CLASS FILES

    People:
    I'm a complete Java neophyte and (slowly) learning. Rather than using the NetBeans IDE I have installed, I'm taking the text editor approach to type my source code.
    After I type code into my text editor, does it necessarily matter where I save my text files? For my first application, I created HelloWorldApp.java in Notepad, originally saving the file to the same folder where my J2SE 5.0 installation is stored, which is:
    C:\Program Files\Java
    My javac (Java compiler) is located in:
    C:\Program Files\Java\jdk1.5.0_01\bin
    When I was first trying to compile HelloWorldApp.java, I received errors saying the Java compiler couldn't be found; I was told to create a path environment variable so the javac could be found to compile my code. When I went to the control panel to set an appropriate path variable, I deleted a (wacky!) Roxio path (don't even know how that got there), entering in its place:
    C:\Program Files\Java
    as the new path name, although, again, my Java compiler is located in
    C:\Program Files\Java\jdk1.5.0_01\bin
    After restarting my computer to implement the new path variable into the operating system, I tried compiling my program, but still got error messages. However, when I moved my HelloWorldApp.java text file from the location where I originally saved it, which was:
    C:\Program Files\Java
    to
    C:\Program Files\Java\jdk1.5.0_01\bin
    my HelloWorldApp.java finally compiled to a class file, which I finally ran! Did my program run because I moved the HelloWorldApp text file from C:\Program Files\Java into the C:\Program Files\Java\jdk1.5.0_01\bin folder where the javac is located?
    Or did my C:\Program Files\Java path variable allow for the Java compiler to be found, although it's located in C:\Program Files\Java\jdk1.5.0_01\bin ? (This is why I asked above if it matters where you save your text document source code.)
    In using a text editor to type source code, where should I save my Java text files next time?
    Any help would be much appreciated! Thanks!

    Add the following directories to the PATH variable.
    C:\Program Files\Java\jdk1.5.0_01\bin
    I agree with this part.
    and add the following to the CLASSPATH variable
    C:\Program Files\Java\jdk1.5.0_01\lib;C:\Program
    Files\Java\jdk1.5.0_01\jre\lib;.
    Where is this insanity coming from?
    You do not need to set your classpath unless you are using a third party library or you have different parts of your program stored under different paths.
    OP: You can store your source files anywhere you want to. You should put them somewhere that is easy for you to access. Most people have a common directory for all of their projects, with subdirectories for each project.
    The only real restriction on where you put your source files is that the directory struction they are in must match the package statement at the top of the source file.
    So, if your file has:
    package chat.client.events;
    at the top, then the source file must be in a directory named chat/client/events relative to where you keep your source files.

  • Any trouble in running .class files in separate location to compilation

    Hi there,
    Do you know if it is possible, easy to run a .class file in a location completely separate to where it was compiled.
    Example, I compile my Java program in c:\myprogs ... here the file can see all the .jar files etc it needs.
    But I want to run the .class file from e:\runprogs, a server location which does not allow the compiled java program to see the .jar files etc it needed for compilation?
    Will there be any trouble in running the .class file. Does the .class file still need to see .jar files files etc during execution?
    ????

    Java classes are dynamically linked, so any jars required for compiling still need to be visible to use the classes. Ensure the JARs are on the appropriate classpath.

  • How to run .class files in IE?

    the basic html codes are
    <applet code="<filename>.class" width = 400 height = 400 >
    </applet>
    i have tried on applets and it works but i dont know why it does not when i am using JApplet with swing. i also have placed the html file in the classes directory. when i open IE to load the html file, the applet does not appear and it says unable to find <filename>.class.
    does anyone know why? and what's the correct way?

    which JVM is used by IE? The 1.1.8JVM from IE is very old so you should use a Java2 JVM or a Swing-Plugin for IE

  • Running the .class file from java code

    I'm doing a kind of providing service like compiling and running Java code on server side and giving output to the end user.
    Please suggest me an approach with code to run .class file from the Java code.
    import java.io.*;
    public class demo {
    public static void main(String args[]) throws IOException, InterruptedException {
    int result;
    try {
    System.out.println("command output:");
    Process proc = Runtime.getRuntime().exec("java -cp . demoh");
    InputStream in = proc.getInputStream();
    result = proc.waitFor();
    BufferedInputStream buffer = new BufferedInputStream(proc.getInputStream());
    BufferedReader commandOutput = new BufferedReader(new InputStreamReader(buffer));
    String line = null;
    System.out.print(commandOutput);
    try {
    while ((line = commandOutput.readLine()) != null) {
    System.out.print(line);
    System.out.println("command output: " + line);
    }//end while
    commandOutput.close();
    } catch (IOException e) {
    //log and/or handle it
    }//end catc
    } catch (IOException e) {
    System.err.println("IOException raised: " + e.getMessage());
    }

    What happened when you tried what you have there?

  • Error in reading .class files

    What kind of program opens .class files?
    i'm new to java technology and am very confused with all these.
    Can someone please help?
    .class files ...
    i think its got something to do with JVM
    please send me instructions on how to run .class files
    thanks

    You need java.exe from the JRE or J2SDK. You can find the download links on the front page of http://java.sun.com. At its simplest, if your class file is called MyProgram.class, you would run it with the command "java MyProgram".

Maybe you are looking for