How do i run a java program an another directory?

How do I run a java program that's in a different directory?
I have been doing this in the command line:
java "C:\Document and Settings\freeOn\Desktop\Java\Test\test"
and I get
Exception in thread "main" java.lang.NoClassDefFoundError:
C:\Document and Settings\freeOn\Desktop\Java\Test\test
I just thought there might be a quick way to do this and not
have to cd to the following dir evertime i want to run an app in
console.
The test.java file is this:
import java.io.*;
public class test {
    public static void main(String args[]) {
      System.out.println("Testing.....");

Ok I looked in the java help and found the classpath, this makes it alittle easier.
java -cp C:\DOCUME~1\freeOn\Desktop\Java\Test\ test
At least i can run this in the run dialog which makes it easier thanks for you help kota balaji

Similar Messages

  • How to run the java program from another directory?

    Hi
    Assumption:
    data.java is in a package suncertify.db and place in a directory c:/code/suncertify/db/ directory
    data.class file: is in c:/code/suncertify/db/ directory
    current directory: c:/
    How can execute the data.class directly in c:/ directory without changing directory to c:/code/ ?
    Thanks in advance,
    Adrian

    Yes. You can use the -classpath and -sourcepath options to specify where to look for source files, and the -d option to specify where to generate the class files. Look up the usage of those options in the javac documentation:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html

  • How to run a java program in another folder

    Hello!
    I want to run for example the java class file in the path ./sourcecode/javafile.class. It works fine if I do the following:
    cd sourcecode
    java javafile
    but it cannot work if I do:
    java sourcecode/java
    The error it outputs is NoClassDefFoundError.
    Can someone tell me how to run a java program in another folder
    thanks a lot.

    You need to specify the classpath using the -cp flag when running. so instead of
    "java sourcecode/javafile"
    Try
    "java -cp sourcecode javafile"

  • How can i run my java program with out java language

    Hai to every one ..Iam new to java language ...am using windows xp operating system , i did not installed java language in my system .. how can i run a java program with out installing java language... Which files is requied to run java program..?
    any one can help me??

    Hai to every one ..Iam new to java language ...am
    using windows xp operating system , i did not
    installed java language in my system .. how can i run
    a java program with out installing java language...
    you ... can ... not ... do ... this
    Which files is requied to run java program..?
    any one can help me??a JVM. Download it from sun's website.
    [url http://java.sun.com/javase/downloads/index.jsp]Download JavaSE here

  • Running a java program in a directory other than the current directory

    How do I run a java program that's located in a directory other than the current directory?
    There is a file Test.java in /dir1/subdir1. If my current directory is anywhere other than that directory, say /dir2/subdir2, I can compile Test.java by using:
    javac -classpath /dir1/subdir1 /dir1/subdir1/Test.java
    But when I try to run it with:
    java -classpath /dir1/subdir1 /dir1/subdir1/Test
    I get a java.lang.NoClassDefFoundError: \dir1\subdir1\Test
    Any thoughts?

    You need to specify just the name of the class you want to run. So java -classpath /dir1/subdir1 Test

  • How can i run my java program in background process?

    hi all,
    i am working on desktop monitoring so when i start my program on client machine that is visible to all but i want this program client not visible to all instead of this can be run in background process . so, nobody can see that.
    so, how i can do this ?
    pls pls help me
    thanks in advanced to helper
    regards
    maulik & ritesh

    this will run the java program in the background.It'll just use the Windows Java Console instead of the command-line console. It has nothing to do with running as a background process.
    Edit: though this might be exactly what the OP wants: not "background process" but "no DOS console".

  • How can I run a java program on Linux?

    I have JBuilder's IDE installed on my Linux partition and it works. However I don't know how to compile and test a program without it. Also I tried to install Limewire on Linux and although I've installed the Java SDK on the system. Once before I installed JBuilder and then JBuilder (I guess) installed it again. However it told me it couldn't find the Java Virtual Machine. Isn't this installed with the JDK? I am able to run programs through JBuilder so I can't see why I'd have a problem. Any answers to the above issues would be greatly appreciated.

    Go here and work out how to make a simple app to compile and run on the command line: http://java.sun.com/docs/books/tutorial/getStarted/cupojava/unix.html#2b
    (You should find the JDK from a directory under the jbuilder directory so use that and not the /usr/local/jdk1.4 in the example.)
    Then find the classes or source code of your project and do the same thing to it.

  • How to remotly run a Java Program on machine B from machine A.

    Hi all,
    I would like to start a JVM/java program from machine A onto machine B (windows plateform). Machine B could be running at another location so where in the lan/intranet.
    OR
    I would like to be able to start the process(GUI application) on machine B using code running on machine A.
    Has anybody ever done somthing like this? Any help will be greatly appreciated.
    Kind regards,
    Suleman.
    [email protected]

    Machine B would have to be "listening" for program requests from Machine A.
    So, on machine B you could have
    a) corba server
    b) rmi server
    c) program listening on a socket for messages
    d) servlet running on a web server
    regards,
    Owen

  • Running my java program on another machine

    Hi
    I have built my program using the much maligned Borland JBuilder, so being quite proud of my new programe i want to run it on other machines, ie i want to put it on a cd and distribute it.!! So how do i do this, i understand that another machine will have JVM installed however is there somthing similar to .exe. Appreciate this may have been covered before but i think i may be confusing myself.. which aint hard
    in anticipation many thanks
    Nige

    exes? What for? How do you run an exe under UNIX?Something you may very well have to do is grant execute permission on the executable file that was thus created. UNIX and Linux do not automatically grant execute privileges on files the way Winblows does.
    PS.

  • How can I run this java program? Please help.

    I have jmf installed, sunone running , the file may be in the wrong directory.
    It is in some directory nowhere near the java lang dir.
    When I try to compile or build i cant. I'm off on a basic thing.
    here is the code.
    import     javax.sound.midi.InvalidMidiDataException;
    import     javax.sound.midi.MidiDevice;
    import     javax.sound.midi.MidiSystem;
    import     javax.sound.midi.MidiUnavailableException;
    import     javax.sound.midi.Receiver;
    import     javax.sound.midi.MidiMessage;
    import     javax.sound.midi.ShortMessage;
    import     javax.sound.midi.SysexMessage;
    public class MidiNote
         /**     Flag for debugging messages.
              If true, some messages are dumped to the console
              during operation.
         private static boolean          DEBUG = false;
         public static void main(String[] args)
              try {
                   // TODO: make settable via command line
                   int     nChannel = 0;
                   int     nKey = 0;     // MIDI key number
                   int     nVelocity = 0;
                   *     Time between note on and note off event in
                   *     milliseconds. Note that on most systems, the
                   *     best resolution you can expect are 10 ms.
                   int     nDuration = 0;
                   int     nArgumentIndexOffset = 0;
                   String     strDeviceName = null;
                   if (args.length == 4)
                        strDeviceName = args[0];
                        nArgumentIndexOffset = 1;
                   else if (args.length == 3)
                        nArgumentIndexOffset = 0;
                   else
                        printUsageAndExit();
                   nKey = Integer.parseInt(args[0 + nArgumentIndexOffset]);
                   nKey = Math.min(127, Math.max(0, nKey));
                   nVelocity = Integer.parseInt(args[1 + nArgumentIndexOffset]);
                   nVelocity = Math.min(127, Math.max(0, nVelocity));
                   nDuration = Integer.parseInt(args[2 + nArgumentIndexOffset]);
                   nDuration = Math.max(0, nDuration);
                   MidiDevice     outputDevice = null;
                   Receiver     receiver = null;
                   if (strDeviceName != null)
                        MidiDevice.Info     info = getMidiDeviceInfo(strDeviceName, true);
                        if (info == null)
                             out("no device info found for name " + strDeviceName);
                             System.exit(1);
                        try
                             outputDevice = MidiSystem.getMidiDevice(info);
                             outputDevice.open();
                        catch (MidiUnavailableException e)
                             if (DEBUG) { out(e); }
                        if (outputDevice == null)
                             out("wasn't able to retrieve MidiDevice");
                             System.exit(1);
                        try
                             receiver = outputDevice.getReceiver();
                        catch (MidiUnavailableException e)
                             if (DEBUG) { out(e); }
                   else
                        /*     We retrieve a Receiver for the default
                             MidiDevice.
                        try
                             receiver = MidiSystem.getReceiver();
                        catch (MidiUnavailableException e)
                             if (DEBUG) { out(e); }
                   if (receiver == null)
                        out("wasn't able to retrieve Receiver");
                        System.exit(1);
                   /*     Here, we prepare the MIDI messages to send.
                        Obviously, one is for turning the key on and
                        one for turning it off.
                   MidiMessage     onMessage = null;
                   MidiMessage     offMessage = null;
                   try
                        onMessage = new ShortMessage();
                        offMessage = new ShortMessage();
                        ((ShortMessage) onMessage).setMessage(ShortMessage.NOTE_ON, nChannel, nKey, nVelocity);
                        ((ShortMessage) offMessage).setMessage(ShortMessage.NOTE_OFF, nChannel, nKey);
                        /* test for SysEx messages */
                        //byte[] data = { (byte) 0xF0, (byte) 0xF7, (byte) 0x99, 0x40, 0x7F, 0x40, 0x00 };
                        //onMessage = new SysexMessage();
                        //offMessage = new SysexMessage();
                        //onMessage.setMessage(data, data.length);
                        //offMessage = (SysexMessage) onMessage.clone();
                   catch (InvalidMidiDataException e)
                        if (DEBUG) { out(e); }
                   *     Turn the note on
                   receiver.send(onMessage, -1);
                   *     Wait for the specified amount of time
                   *     (the duration of the note).
                   try
                        Thread.sleep(nDuration);
                   catch (InterruptedException e)
                        if (DEBUG) { out(e); }
                   *     Turn the note off.
                   receiver.send(offMessage, -1);
                   *     Clean up.
                   receiver.close();
                   if (outputDevice != null)
                        outputDevice.close();
              } catch (Throwable t) {
                   out(t);
              System.exit(0);
         private static void printUsageAndExit()
              out("MidiNote: usage:");
              out(" java MidiNote [<device name>] <note number> <velocity> <duration>");
              out(" <device name>\toutput to named device");
              out(" -D\tenables debugging output");
              System.exit(1);
         private static void listDevicesAndExit(boolean forInput, boolean forOutput) {
              if (forInput && !forOutput) {
                   out("Available MIDI IN Devices:");
              else if (!forInput && forOutput) {
                   out("Available MIDI OUT Devices:");
              } else {
                   out("Available MIDI Devices:");
              MidiDevice.Info[]     aInfos = MidiSystem.getMidiDeviceInfo();
              for (int i = 0; i < aInfos.length; i++) {
                   try {
                        MidiDevice     device = MidiSystem.getMidiDevice(aInfos);
                        boolean          bAllowsInput = (device.getMaxTransmitters() != 0);
                        boolean          bAllowsOutput = (device.getMaxReceivers() != 0);
                        if ((bAllowsInput && forInput) || (bAllowsOutput && forOutput)) {
                             out(""+i+" "
                                  +(bAllowsInput?"IN ":" ")
                                  +(bAllowsOutput?"OUT ":" ")
                                  +aInfos[i].getName()+", "
                                  +aInfos[i].getVendor()+", "
                                  +aInfos[i].getVersion()+", "
                                  +aInfos[i].getDescription());
                   catch (MidiUnavailableException e) {
                        // device is obviously not available...
              if (aInfos.length == 0) {
                   out("[No devices available]");
              System.exit(0);
    e
         *     This method tries to return a MidiDevice.Info whose name
         *     matches the passed name. If no matching MidiDevice.Info is
         *     found, null is returned.
         *     If forOutput is true, then only output devices are searched,
         *     otherwise only input devices.
         private static MidiDevice.Info getMidiDeviceInfo(String strDeviceName, boolean forOutput) {
              MidiDevice.Info[]     aInfos = MidiSystem.getMidiDeviceInfo();
              for (int i = 0; i < aInfos.length; i++) {
                   if (aInfos[i].getName().equals(strDeviceName)) {
                        try {
                             MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);
                             boolean     bAllowsInput = (device.getMaxTransmitters() != 0);
                             boolean     bAllowsOutput = (device.getMaxReceivers() != 0);
                             if ((bAllowsOutput && forOutput) || (bAllowsInput && !forOutput)) {
                                  return aInfos[i];
                        } catch (MidiUnavailableException mue) {}
              return null;
         private static void out(String strMessage)
              System.out.println(strMessage);
         private static void out(Throwable t)
              t.printStackTrace();

    Please post your code using code tags.
    When I try to compile or build i cant.What is your question? Exactly what error message do you get?

  • Reg how to a Run a java program 24/7

    i have a requirement to display the content of the folder 24/7,365 days
    regarding this i have written a program but it seems not much efficient regarding its work can any one help me ;
    Thread t = new Thread(new ScheduledTask());
    t.setDaemon(true);
    t.start();
    Thread.sleep(90000);
    is it possible to run the Daemon Thread continuosly
    Any suggestions please welcome
    Regards
    praveen

    praveenmca09 wrote:
    i have a requirement to display the content of the folder 24/7,365 days
    regarding this i have written a program but it seems not much efficient regarding its work can any one help me ;
    Thread t = new Thread(new ScheduledTask());
    t.setDaemon(true);
    t.start();
    Thread.sleep(90000);Remove setDaemon(true) - if you want the thread to keep the JVM from exiting, then it should not be a daemon. Also remove the Thread.sleep( 90000 ) - it's not necessary.

  • Running a java program in another java code

    Hello,
    I have a question.I wrote a java server code named server.java. In this server code, I receive another java class code called "HelloWorld.class" from another node. What I want to do is to execute the class HelloWorld inside server.java.
    Briefly, I would like to run a compiled java code (class code)in another executing class code. How can I achieve this?
    Thanks in advance
    �ebnem Bora

    Hi,
    Sorry but your terminology isn't that clear. Are you trying:
    1. To call methods on another class or
    2. To launch a separate process that will run another class?
    If it's either of these then they're not 'Advanced Language Topics' but simple:
    // Scenario 1
    // in Server class
    HelloWorld hw = new HelloWorld();
    hw.sayHello(); // or whatever the method is
    // Scenario 2
    Runtime.exec(new String [] {"java", "HelloWorld"}); // or whateverIs that of any help?
    Dom.

  • How can I open a java program through another program?

    Can someone tell me what's wrong with my code?
    <CODE>
    String thisFile = "javaw -classpath D:/DirectLink/classes;C:/JBuilderX/jdk1.4/jre/lib/rt.jar directlink.DirectLink";
    try {
    Runtime.getRuntime().exec("cmd /C start " + thisFile);
    catch (Exception e) {
    </CODE>
    This code will handle other programs however I don't know how to write it so it will work with calling another class.

    Yeah, I made sure it was in the path. I even used the
    exact command from a command prompt. Well almost, I
    had quotes around the classpath.
    Eh? Quotes around the classpath? Sorry if I was being unclear. What I mean is when I call this from a command prompt I put double quotation marks around the classpath like so:
    javaw -classpath "D:/DirectLink/classes;C:/JBuilderX/jdk1.4/jre/lib/rt.jar" directlink.DirectLink
    In the code on top I wrote it as a string and there were no quotation marks around the classpath.
    However, I'm not
    sure if I can use single quotes with java to simulate
    this or whether I can use a \" in it's place.
    I'm not sure what you're saying...but note that when you call exec you're not passing control to the shell, ?>so shell metacharacters are not interpreted.Once again sorry for not being clear. What I meant was I didn't know if I could write it like this:
    tempString = "javaw -classpath \"D:/DirectLink/classes;C:/JBuilderX/jdk1.4/jre/lib/rt.jar\" directlink.DirectLink"
    And whether this would work. All I really was asking is how can I pass the command to cmd so it will interprete it as it did when I entered it in manually before. I wanted to pass the command to cmd with double quotation marks around the classpath because that's how I did it earlier. I just wasn't sure how to do it.
    What I'm wondering is since it's a java class is there a
    better way to call it especially since executing
    commands seems to be different between different OS's?
    You can invoke it directly. Why did you decide to create a new process?Frankly, I don't understand the command very well. I haven't had to use it before and I'm really just trying to get a feel for it. I usually like to get something working, play around with some options, get more of a hands on feel. Then I usually will do more research on it. I was looking at some posts on the exec command and I tried a few of them and this one worked for me when it came to opening apps so I decided to give it a try.

  • URGENT: How to run a Java program from a different directory?

    Hi.
    How do I run a Java program from a directory that the file is not located in? So lets say im in c:\Java. But the file is in c:\Java\abc\efg\.
    What would be the command to run the Java file from c:\Java.
    I can't remember it and I need it asap.
    Cheers.

    If the class you are trying to run is MyApp.class, try
    c:\Java\>java -cp abc\efg MyAppThe actual classpath you specify will depend on whether or not MyApp.class is in a package (I've assumed it isn't) and whether or not any 3rd party jars are involbed (I've assumed not).
    Edited by: pbrockway2 on Apr 1, 2008 6:42 PM
    The command arguments read as "Run the MyApp class using as a classpath abc\efg relative to here (c:\Java)".

  • Running a Java program at startup in Linux

    Hello
    How do I run a Java program at startup in Linux? I know in Windows I can put a .bat file in C:\Windows\Start Menu\Programs\StartUp\ directory, but in Linux I have no idea how it is done.
    Thank you,
    Mihai

    This is really a Linux question, not Java.
    And then it depends on the version of Linux you are using.
    Maybe this will help, otherwise you should try on a forum for your version of Linux.

Maybe you are looking for