How to Compile and Run

How to Compile and Run

HOW TO

Run the already provided Jar

  • Run the already provided jar file

Compile and Run from Source Code

  • Compile the source files
  • Run the program from the newly created class files

Runnable Jar from above compile

  • Create a runnable jar for portability
  • Run the jar, once it’s been created


PREREQUISITES: Java 1.8 or newer – Must have JRE to run, must have JDK as well, to compile.
Also, the instructions here assume you have a Mac or Linux box. It will work on Windows as well, but you’ll have to change the instructions over to Windows syntax.

To run the jar file:

To run the jar file, download maze-cjromb-jar

Unzip the file.  It will make a subdirectory named Maze.  The jar file, the docs and the files subdirectory with the mazes.txt file will be in the Maze subdirectory.

Change into the Maze subdirectory, and at a command prompt, type

java -jar maze_cjromb.jar

Return to top

To compile the source code:

To compile the program on your own, make a new, empty directory, and put this zip file in it:

maze-cjromb-src-new

unzip the file inside that directory:

unzip maze-cjromb-src-new.zip

Change into the maze_source directory like this:

cd maze_source

 

Then compile the source like this:

javac -d ../maze_target src/com/maze/*.java

NOTES:

  1. Pay close attention to including or not including path slashes in the compile command.
  2. You don’t need anything except the normal $CLASSPATH set on your computer, if you run it from within the maze_target directory.  I’ve included the external libraries, the text file, and the java docs in the source zip file.

Expected Result: If the sun is shining, and all is right in the world, it should come back to a command prompt with no errors or messages.

Return to top

To run the newly compiled source code:

Change into the maze_target directory from the source directory like this:

cd ../maze_target

Then type in this command:

java com/maze/MazeMain

 

Expected Result: You should see several lines of text with directions in them. If you have a printout of the maze, you should be able to follow the directions to find your way from beginning to end.

Here’s a visual representation of the first maze included in the file.  And here’s the underlying spreadsheet the visual representation was created in.

Return to top

To create a jar file from the compiled program:

You will need to copy the class files you just created into that directory.

From the maze_target directory, copy the new class files into the maze_jar directory, like this:

cp -r com ../maze_target/

Then change into the maze_jar subdirectory like this:

cd maze_jar

Create the Jar file

jar cmvf META-INF/MANIFEST.MF maze_cjromb.jar com/maze/* lib/*

META-INF contains the manifest, so the jar can be runnable.maze_cjromb.tar is the resulting jar

Run the jar file you just created by typing this in from the maze_jar directory

java -jar maze_cjromb.jar

NOTE: You should be able to move that maze_cjromb.jar file to another subdirectory or another machine, however you MUST give someone BOTH the jar, and the files directory.

As long as Java 1.8 and the JRE are set up properly, that command should work.

Return to top

About This Maze Program

Return to main Maze page