Results 1 to 3 of 3
  1. #1
    mzatanoskas is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default Executing a java .class file from outside the containing folder

    I'm trying to run a java .class file from the command line in XP from outside the containing folder but I'm having trouble making it work.

    Say the file is:

    H:\Java\HelloWorld.class

    I'm at the command prompt in C:\ and I type:

    java -cp H:\Java\HelloWorld

    I get that class definition not found error. Of course it works fine when I run the file from the same folder.

    The reason I need to do this is that I need to run the file from another program, by opening java.exe and passing it the filepath and other arguments.

    I hope someone can help, it's probably very basic but it's soooo frustrating! :confused:

    Thanks!

  2. #2
    Zamppa is offline Member
    Join Date
    Feb 2009
    Location
    Finland
    Posts
    13
    Rep Power
    0

    Default

    The classpath and class name are two different things and hence given as two separate parameters.

    Try:
    java -classpath H:\Java\ HelloWorld

  3. #3
    mzatanoskas is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default

    D'oh!

    thanks a lot Zamppa, that worked but I had to get rid of the trailing \ for some reason.

Similar Threads

  1. Executing a jar file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 02-14-2014, 09:02 AM
  2. Creating Folder in JAVA and Copying File
    By fnoman in forum New To Java
    Replies: 8
    Last Post: 10-18-2008, 07:33 AM
  3. executing a method in main class
    By rangers27 in forum New To Java
    Replies: 3
    Last Post: 07-19-2008, 05:04 AM
  4. executing the java file
    By TheBayWatchMan in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 09:31 AM
  5. how to use class in upper folder
    By osval in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •