Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

ARRGH - Java and command prompt commands

  • 27-10-2009 09:50PM
    #1
    Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭


    Ok,
    Im writing a piece of software that uses GEVA and, while running, needs to repeatedly start Robocode. Run a battle,(with a commandPrompt command) and get the results from that battle.
    Ive got the results bit sorted out. and Im fairly sure i can get java to call the command. The ony problem is that i cant figure out the commad i need.

    robocode is located here: C:\Users\Korvanica\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode

    so the command to run robocode should be:
    java -Xmx512M -Dsun.io.useCanonCaches=false -cp C:\\Users\\Derek\\Desktop\\"4th Year"\\"Semester One"\\Project\\GEVA\\GEVA-v1.1\\robocode\\libs\\robocode.jar robocode.Robocode -battle C:\\Users\\Derek\\Desktop\\"4th Year"\\"Semester One"\\Project\\GEVA\\GEVA-v1.1\\robocode\\battles\\grammatical.battle -nodisplay -results C:\\Users\\Derek\\Desktop\\"4th Year"\\"Semester One"\\"COMP30290 Natural Computing"\\Project\\GEVA\\GEVA-v1.1\\robocode\\results.txt


    but this keeps spittin out errors saying:

    Can't find robocode.core-1.x.jar module near to robocode.jar
    ClassPath: C:\\Users\\Derek\\Desktop\4th Year\Semester One\Project\\GEVA\\GEVA-v1.1\\robocode\\libs\\robocode.jar


    Its strange that in the error, it shows single slashes in half the classpath, but its right in the actual command that was fed in.

    Any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 573 ✭✭✭MacGyver


    I think ur quotes are wrong but I'm not near a computer to test it. I'm sure someone will be along soon to confirm or shoot me down


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica


    MacGyver wrote: »
    I think ur quotes are wrong but I'm not near a computer to test it. I'm sure someone will be along soon to confirm or shoot me down

    Without the Quotes i get:

    Exception in thread "main" java.lang.NoClassDefFoundError: Year\\Semester
    Caused by: java.lang.ClassNotFoundException: Year\\Semester
    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)
    Could not find the main class: Year\\Semester. Program will exit.


    So it doesnt seem to get as far as my origional one. Madness

    Basically if anyone could just fire me a command that can run from anywhere in the filesystem (ie: one with a path in the command).
    Example: "notepad C:\\Users\\Derek\\Desktop\\4th Year\\test.txt" or something to make sure im doin it right. - just tested that, ran grand. Without quotes and all.

    I believe the problem may lie with "robocode.Robocode" in the origional command.


  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    Should be

    java -Xmx512M -Dsun.io.useCanonCaches=false -cp "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\libs\robocode.jar" robocode.Robocode -battle "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\battles\grammatical.battle -nodisplay -results "C:\Users\Derek\Desktop\4th Year\Semester One\COMP30290 Natural Computing\Project\GEVA\GEVA-v1.1\robocode\results.txt"

    Obv if your calling this from within java then both the \ and " need to be escaped to \\ and \"


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica


    lynchie wrote: »
    Should be

    java -Xmx512M -Dsun.io.useCanonCaches=false -cp "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\libs\robocode.jar" robocode.Robocode -battle "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\battles\grammatical.battle -nodisplay -results "C:\Users\Derek\Desktop\4th Year\Semester One\COMP30290 Natural Computing\Project\GEVA\GEVA-v1.1\robocode\results.txt"

    Obv if your calling this from within java then both the \ and " need to be escaped to \\ and \"

    Tried running from just the cmd, no joy.
    Could not find the main class: robocode.Robocode. Program will exit.


  • Registered Users, Registered Users 2 Posts: 1,919 ✭✭✭ronivek


    Firstly I'd double check that the robocode.jar file contains the class Robocode.

    Secondly I'd double check that the package structure within the jar file is correct; i.e. that robocode.Robocode is indeed the fully-qualified classname.

    You're sure that's the correct path to that jar file also?


  • Advertisement
  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    As was stated above check your paths. They must be wrong. Confirm that the path C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\libs\ is correct by pasting it into the run command and see if it opens that folder. Then confirm that the robocode.jar is actually there.


  • Registered Users, Registered Users 2 Posts: 2,800 ✭✭✭voxpop


    lynchie wrote: »
    Should be

    java -Xmx512M -Dsun.io.useCanonCaches=false -cp "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\libs\robocode.jar" robocode.Robocode -battle "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\battles\grammatical.battle -nodisplay -results "C:\Users\Derek\Desktop\4th Year\Semester One\COMP30290 Natural Computing\Project\GEVA\GEVA-v1.1\robocode\results.txt"

    The above is missing a quote after grammatical.battle - should be
    java -Xmx512M -Dsun.io.useCanonCaches=false -cp "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\libs\robocode.jar" robocode.Robocode -battle "C:\Users\Derek\Desktop\4th Year\Semester One\Project\GEVA\GEVA-v1.1\robocode\battles\grammatical.battle" -nodisplay -results "C:\Users\Derek\Desktop\4th Year\Semester One\COMP30290 Natural Computing\Project\GEVA\GEVA-v1.1\robocode\results.txt"
    


    you should really be using a batch file or something to setup you environment and classpaths - it would make the executing your project much clearer


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica


    Ok cool,
    so ive been messing around trying to get a batch file working for the job.
    @echo off
    echo Testing
    java -Xmx512M -Dsun.io.useCanonCaches=false -cp libs/robocode.jar robocode.Robocode -battle battles\grammatical.battle -nodisplay -results results.txt
    echo GAME OVER
    echo on
    

    This should start a robocode battle and run that battle in the command line.

    its location is
    C:\Users\Derek\Desktop\4th Year\Semester One\COMP30290 Natural Computing\Project\GEVA\misc\src\misc

    this works when i run it from its directory ( with terminal or just clicking on it) but if i want to call it from somewhere else in the file system how would i go about doing this? - Currently when i try this it gives me:
    Testing
    Exception in thread "main" java.lang.NoClassDefFoundError: robocode/Robocode
    Caused by: java.lang.ClassNotFoundException: robocode.Robocode
    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)
    Could not find the main class: robocode.Robocode. Program will exit.
    GAME OVER

    When i call it from the previous folder, (ie the SRC folder) using "misc\test.bat" it gives me the above error.


  • Registered Users, Registered Users 2 Posts: 2,800 ✭✭✭voxpop


    Set up your classpath in batch file using

    set CLASSPATH=classpath1;classpath2...


    When you execute the java command, it takes the current working directory (.) and runs everything from there

    you are setting the classpath using a relative path libs/robocode.jar. This is relative to the current working directory.

    So from your example libs/robocode.jar is in the misc folder - if you want to run you bat file from anywhere else you need the full classpath, not relative.


  • Registered Users, Registered Users 2, Paid Member Posts: 2,032 ✭✭✭lynchie


    As I said before put quotes around the full path i.e.

    -cp "C:\Users\Derek\Desktop\4th Year\Semester One\COMP30290 Natural Computing\Project\GEVA\misc\src\misc\libs\robocode.jar"


  • Advertisement
Advertisement