Error compiling

Started by
6 comments, last by Gage64 13 years, 6 months ago
Ive been messing with this code for over a week, and I can't figure out the problem! Anyone able to run this source code?

http://www.brackeen.com/javagamebook/ch05src.zip
(sorry for the link, I didn't want to post
the source code for many different files)

I think the main class is under:
com -> brackeen -> javagamebook -> tilegame -> GameManager.java

If you were able to run it with tweeking the code, let me know what you changed. Or, if you were able to run it without doing anything, or from a different class, that would be great to know as well.

Thanks everyone very much!!
Advertisement
First, download Ant. There are instructions here on how to configure it.

Now run Ant from the game's directory (ch05src) and it will create an executable .jar file called tilegame.jar.

I just did this and it worked. I was able to run the game without any problems.
This is from the book it tells you how to do it without using ant also.

Creating an Executable .jar File
Finally, when you're ready to pass out your game to friends, the last thing you want is to give them arcane instructions on how to run the code. Telling another programmer to type something like this at the command line might be okay:

java com.brackeen.javagamebook.tilegame.GameManager

But the casual user might not even know what a command line is or even what to do if problems occur. It's probably a good idea to make it easier by creating an executable .jar file. With an executable .jar file, all the user has to do is double-click the .jar file, and the game starts right up. Your programmer friends would probably appreciate the time it saves them as well.

If you're unfamiliar with what a .jar file is, it's a Java archive file—basically just a container for a group of classes. All the classes for your game are stored in the .jar file, which is usually compressed.

To make the .jar file executable, you specify which class to run in the .jar's manifest file. The manifest file is called META-INF/MANIFEST.MF inside the .jar. For this platform game, the manifest file looks something like this:

Manifest-Version: 1.0
Main-Class: com.brackeen.javagamebook.tilegame.GameManager

When you double-click a .jar file, the Java VM starts up and looks at the .jar file's manifest. If the Main-Class attribute is found, it runs the specified class. If there is no manifest or the Main-Class attribute doesn't exist, the VM just pretends that nothing happened and exits.

If you're using the jar tool to create .jar files, first create a manifest file in a text editor and then use the -m option to add the manifest file to your .jar.

If you're using Ant to build .jar files, Ant can create the manifest file automatically and add it to the .jar. Listing 5.15 shows a sample Ant target that creates an executable .jar file for the game.


Thanks Gage64, but I still have a question, when you say run Ant from the games directory, do you mean run the Build.xml file? I think JCreator comes with Ant so all im doing is 'running' the Build.xml file, but nothing else happens afterwords.
'ant' is the program; 'build.xml' is data for that program.
yeah i fugred that part out after posting, thanks! But im having a hard time setting up Ant, i already opened a new thread so i guess this thread is...
dead.
Sorry to bring this back up, but I guess im getting really close to being done with this.
I finally got ant to work, which was really tough.

I ran ant in my command promopt and told it to build C:\Users\Leaf\Documents\ch05src\ch05src\build.xml

It created my tilegame.jar, which Gage64 told me to execute.
Executing the file, it asked me to open it from a specific program.
I opened it with:
C:\Program Files\Java\jdk1.6.0_21\bin\javaw.exe

And, then it tells me
"Could not find main class C:\Program Files\Java\jdk1.6.0_21\bin\javaw.exe. Program will exit. "

So I tried to open it with java.ws which was just epic fail, tons of errors.

I'm almost done here, what am I doing wrong? And thanks everyone for much apreciated help! :D :D
You should have an environment variable called JAVA_HOME, whose only entry should be C:\Program Files\Java\jdk1.6.0_21.

And in the path environment variable, add this entry if it's not already there:

C:\Program Files\Java\jdk1.6.0_21\bin

If that doesn't solve it (I suspect it won't), you should reinstall the JDK.

This topic is closed to new replies.

Advertisement