I want to run this GitHub java program: https://github.com/ss2cp/AI-TicketToRide
According to the README.md it should run with src/ttr.main/TTRMain
I am trying to start the game in linux, but I keep on getting the error:
Error: Could not find or load main class src.ttr.main.TTRMain
Caused by: java.lang.ClassNotFoundException: src.ttr.main.TTRMain
I tried
java src.ttr.main.TTRMain
java src/ttr.main/TTRMain
src/ttr.main/TTRMain
java ttr.main.TTRMain
java -jar JGame.jar
java -cp . src.ttr.main.TTRMain
java -cp . ttr.main.TTRMain
from the ~/Downloads/AI-TicketToRide-master/ folder (where the README.md and .classpath file is).
I also tried it from ~/Downloads/AI-TicketToRide-master/bin/ttr/main/ and ~/Downloads/AI-TicketToRide-master/src/ttr/main/
But no luck.
I am using Ubuntu 20.04 and openjdk 11.0.20.1 2023-08-24.
How do I start the program and from which directory? And should I set a classpath?
The following sequence of commands works for me.
Clone the repository:
Note: Requires Git to be installed on your computer.
Navigate to the project directory:
Note: This is necessary, as the image files in the project's
resourcesdirectory are loaded as files relative to the working directory.Execute the project:
Note: Requires Java 8+ to be on your path.
Note: On Windows, replace the
:(colon) in the-cpargument with a;(semicolon). You can also replace the/(forward slash) with a\(backslash), but that is not strictly necessary (Java will correctly interpret the value either way).Class-path
The
-cp bin:lib/JGame.jarpart is specifying the class-path. In this case, two locations are being put on the class-path. Thebindirectory contains the compiled class files of the source files in thesrcdirectory. Thelib/JGame.jarfile contains precompiled third-party code used by the project.Normally, I would say the
resourcesdirectory should also be put on the class-path, but that does not seem to be necessary here. It appears those images, instead of being loaded as resources like the directory name would imply, are being loaded as files. Luckily, relative file paths seem to be used, but this means that the project directory must be the working directory.Main class
The
ttr.main.TTRMainpart is the fully qualified binary name of the main class. Note thesrcdirectory is a "source root"; it is not part of the package structure.The class-path will be searched for the specified main class and, if found, execute that class's main method. Since the
bindirectory, which contains thettr/main/TTRMain.classfile, has been put on the class-path, thettr.main.TTRMainclass will be found.