Problem running my class file

i'm using os x and when i compile my HelloWorld.java i have no errors and it creates the HelloWorld.class file in the same directory. now if i try to run the program from the terminal by typing in
java HelloWorld it works file, but if i try to send the HelloWorld.class file to any other machine or even open it not using the terminal(finding the file and double clicking it) it won't run.
Any idea how to make this program stand alone like i would want??
Thanks

alright i'll look it up, the little i've done with
java on windows with textpad i thought i was creating
a .class that executed from the ms-dos window but
perhaps something else the compiler did behind the
scenes to make it executable?Nope.
java HelloWorldYou're running java.exe. It's taking HelloWorld as its argument, finding the class called HelloWorld.class, taking it as input, and executing its main method through the JVM.
It's exactly the same thing as if you type Notepad somefile.txt or javac SomeFile.javaThe first word is the .exe or .bat that's running, and the next word is an argument that the program interprets as a file to use as its input.

Similar Messages

  • How to run a class file in MAC os, compiled in XP.

    Hi all,
    i am compiling a java program in windows using JDK 1.5 and i am copying this file to MAC os (Panther). In Mac i am running this class file using JDK 1.4.i am getting the following exception,
    Exception in thread "main" java.lang.UnsupportedClassversion error.
    This is understandable, but is there any solution for this ...
    Any one experienced the same problem ...
    If any one comes up with a solution to solve this, plz let me know...
    Thanks in advance......

    You are compiling it in 1.5 and expecting 1.4 to run it?
    You have two options: compile it at the 1.4 level or upgrade your Mac to 1.5

  • Compiling on a dual core machine and running the class files on linux.

    does compiling on a dual core machine and running the class files on linux have any effect?

    well, the problem that i felt was that when i runmy
    class files on my machine(windows xp, dual core),
    Thread.sleep(60000) sleeps for 1 minute. but wheni
    run it on a linux machine, Thread.sleep(60000)sleeps
    for 2 minutes. my application has a lot ofthreads.
    I can't be 100% sure, but I'm pretty sure that
    sleep(60000) doesn't sleep for 2 minutes on the other
    machine.I, wholeheartedly, agree.
    Due to timing issues it may seem to sleep a few milliseconds more, but not double.
    Of course, if there is a "real-time" (or even simply higher than the Java app) priority program running that is using a lot of the CPU it may seem like it sleeps a lot longer than 60000, but that is a different issue.

  • How to run java .class file?

    How can i run/view .class file in java?. is there tool/utilities in java that can do that.?. Thanks

    Ednut wrote:
    I'm sure you must have been taught using the command: java yourClassName after navigating to the location of your compiled class in the command prompt.I'm sure the OP does not need condescending remarks from someone who knows almost as little Java as s/he does.

  • Problems running local swf files

    I recently developed problems running local swf files in
    Internet Explorer. This was working previously but recently it
    stopped working. Any ideas why the local files no longer work and
    how I can correct it?

    Hi Aquasue and welcome to our community
    In addition to the usual suspect fellow Adobe Community
    Expert Steve pointed out, the Flash player itself may be to blame.
    If you recently upgraded to the latest version (8 I believe) it
    imposes security particularly when using .SWFs locally.
    Click here to read a
    TechNote about it
    Cheers... Rick

  • Problems interpriting my .class file

    Hi, im new to java and I have a very simple .java file that I compiled into a .class file. The problem is, then I try and interprit it (Im using JDK 5) I get an error... "Exception in thread "main" java.lang.NoClassDefFoundError: Saluton"
    Saluton is my program. I've tried setting the "Path" and "classpath" variables, but it still doesnt work.
    Heres my path and classpath variable values.
    Classpath:
    ,;C:\Program Files\Java\jdk1.5.0_05\bin\javaPath:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\GTK\2.0\bin;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.5.0_05\binThank you very much for your help!
    Onlinealways

    You need to add the path to where your compiled .class file is to your system CLASSPATH. For example, if I create class X in package "pak1" then I will run it with:
    java pak1.XHowever, in order for the JVM to find X it must be in it's classpath. Thus if X.class was at
    C:\MyJava\bin\pak1\X.classI would need to add
    C:\MyJava\bin\to the classpath.

  • Unable to run a .class file w/ javaw

    I created a simple application which uses swing gui.
    This application works just fine when I click the "run" button in eclipse.
    But as soon as i copy the .class file from the eclipse project folder to somewhere else and try to run it with "javaw myclass" (the filename is myclass.class) nothing happens.
    No command not found error, no nothing.
    Its like javaw finds and executes the .class and then returns to the command prompt... But I dont see any windows or any sign of my program running.
    Thx in advance

    When run with just java I get this:
    C:\>java myclass
    Exception in thread "main" java.lang.NoClassDefFoundError: myclass$1
    at myclass.<init>(myclass.java:38)
    at myclass.<init>(myclass.java:28)
    But I Eclipse it works just fine...
    What does Eclipse do that I dont?

  • 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?

  • Trying to run java class files from my jsp

    I am having difficulty running java files from my jsp. I have compiled my two java classes and inserted them onto my server in the webapps/WEB-INF/classes/scripting directory and have imported scripting.* into my jsp page. The files both compiled ok before the class files were loaded onto the server but when I rty to run the jsp from the server, I keep getting a compiler error. Thanks in advance
    Iob

    Here are the few question
    1) Does your java classes which u created is declared under package scripting. *.class files are to be places under the WEB-INF/classes directory only. Not under scripting. But if you java classes say are under a package called a.b. Then you need to put under classes\a\b\.

  • How to run several class files at the same time

    I have four class files, there's: cvnt1.class,cvnt2.class,cvnt3.class and cvnt4.class.
    I want to know how to write application for running all of those files together. thanks!

    Your question is still unclear - do you want to access code from those class files (just add all of them to classpath) or do you want to create number of threads or number of processes (one per class) and start code from each class simultaneously or something else?

  • How to run a class file from windows ?

    hi, i have created a shorcut to run my java application from my windows desktop, but i have the error message "Couldn't find the main class, programm will exit",
    the shortcut is as follow
    [%windir%\System32\javaw.exe C:\ProgramFiles\\Main]
    thanks for you help,

    Im new to running java from a shortcut but this may help. I hope this helps.
    this is the command you ned to write and refer to my example;
    javaw.exe -cp <path to class file> packageName.className
    This is an example of wat i have typed to run my program from a shortcut;
    C:\JBuilder3\java\bin\javaw.exe -cp C:\jbuilder3\myclasses\welcome.jar welcome.welcome
    Hope this helps
    good luck!!!
    Matx3001

  • Problem running my classes

    Hello everybody,
    I have just installed jdk 6u1 on my linux RedHat as 4 system. I just executed the file and then added a PATH to my environment. I run apps like HelloWorld with no problem, but when it comes to a bit more complex ones I get these errors:
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class : Leaf
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so. 5.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
    at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
    at JvThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
    at JvRunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/l ib/libgcj.so.5.0.0)
    at __gcj_personality_v0 (/home/oracle/orako/java/java.version=1.4.2)
    at __libc_start_main (/lib/tls/libc-2.3.4.so)
    at JvRegisterClasses (/home/oracle/orako/java/java.version=1.4.2)
    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found i n [file:/usr/share/java/libgcj-3.4.6.jar, file:./, core:/]
    at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5. 0.0)
    at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj .so.5.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgc j.so.5.0.0)
    at JvFindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5. 0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
    at JvBytecodeVerifier.verify_instructions_0() (/usr/lib/libgcj.so.5.0.0)
    at JvVerifyMethod(_Jv_InterpMethod) (/usr/lib/libgcj.so.5.0.0)
    at JvPrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at JvWaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5. 0.0)
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so. 5.0.0)
    ...9 more
    Note that my app runs on Windows well. I my installation OK? What is up??

    Multiple post
    http://forum.java.sun.com/thread.jspa?threadID=5175040&tstart=0

  • Java running old class file

    When I make a change to a Swing program and compile, it runs the old version, as if the changes were never made. Any ideas?
    I make a new directory and copy the java file, re-compile and it works...but I don't want to have to do that every time.
    Dan

    If you have like
    class1.java
    class2.java
    class3.java
    class1.class
    class2.class
    class3.class
    then make changes to class1.java and class2.java, then run javac class1.java, it will see that class2.class exists so it won't bother to recompile class2.java, either delete all the classes or do javac *.java
    Shish

  • Can run as class file but not as a jar

    This is driving me nuts! I have a class called ReceiveTrap. If can run it with the following command and it runs fine:
    /usr/java/j2sdk1.4.0_01/bin/java -Djsnmp.loadRFC1213MIB=false -classpath /usr/jSNMP_trapd_server/lib/jSNMP.jar:/usr/jSNMP_trapd_server/lib/. ReceiveTrap
    As soon as I package it in a jar I get the following:
    Command:
    /usr/java/j2sdk1.4.0_01/bin/java -Djsnmp.loadRFC1213MIB=false -classpath /usr/jSNMP_trapd_server/lib/jSNMP.jar -jar PCATrapd.jar
    Output:
    Exception in thread "main" java.lang.NoClassDefFoundError: com/outbackinc/services/protocol/snmp/SnmpTrapListener
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
    I can't figure out how one way it finds the jars for jSNMP and the other way it doesn't. Any suggestions are appreciated.
    James

    I believe I'm doing that correctly. My manifest is:
    Manifest-Version: 1.0
    Main-Class: PCATrapd.ReceiveTrap
    [blank line]
    It's definitely finding my main class. If I change the Main-class from PCATrapd.ReceiveTrap to just ReceiveTrap, then I get a java.lang.NoClassDefFoundError: ReceiveTrap
    The ClassDef it says it can't find is located in the jar that's in my classpath, not PCATrapd.jar.
    Thanks,
    James

  • Problem in accessing class file for applet code

    I am developing a package in struts frame work.
    I place all the java files in action folder and jsp files in jsp folder.In one of the jsp I write code to invoke applet .But I am getting error as "class not found exception".Can any one help me? Below I am giving the code?
    <embed
    type="application/x-java-applet;version=1.4"
    pluginspage="http://java.sun.com/products/plugin/index.html#download"
    code="DigitalSignerApplet"
    archive="DigitalSignerApplet.jar"
    width="130"
    height="25"
    mayscript="true"
    scriptable="true"
    fileNameField="uploadFile"
    certificationChainField="certChain"
    signatureField="signature"
    signButtonCaption="Sign selected file">
    <embed>

    Excuse me with out files in webserver how can I get
    error, I am asking how to point to that specific classHuh? You can't. It's an HTML page with an applet. All normal rules apply.

Maybe you are looking for