By: Hoang Huynh ([email protected]) Copyright ...peter.liu/jac444/jfreechart.pdf · 1....

24
By: Hoang Huynh ([email protected]) Copyright © 2008 Hoang Huynh 1

Transcript of By: Hoang Huynh ([email protected]) Copyright ...peter.liu/jac444/jfreechart.pdf · 1....

Page 1: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

By: Hoang Huynh ([email protected])

Copyright © 2008 Hoang Huynh

1

Page 2: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

We will be using two JAR files from the JFreeChart library:1. C:\Program Files\jfreechart-1.0.9\lib\jcommon-1.0.12.jar2. C:\Program Files\jfreechart-1.0.9\lib\jfreechart-1.0.9.jar

2

Page 3: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

3

Page 4: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

1. Open up the Robocode workspace in Eclipse2. Open up the “robocodeextract” project and copy the

jfreechart-1.0.9.jar and jcommon-1.0.12.jar files to robocodeextract’s libs folder

4

Page 5: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

5

Page 6: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Now, we will add a reference to the JAR files from the robocodeproject.

Right click on the “robocode” project folder and click “Properties”

6

Page 7: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Select “Java Build Path”, then open the “Libraries” tab. Then click the “Add JARs…” button.

7

Page 8: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

11

Page 9: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Open up the ANT build script (the build.xml file in the build project) and browse to the “compile.robocode” target.

Now, modify the “<!-- Copy libs into the build folder -->” section to read:

<!-- Copy libs into the build folder -->

<copy file="${src.extract}/libs/codesize.jar" toDir="${build}/libs"/>

<copy file="${src.extract}/libs/jcommon-1.0.12.jar" toDir="${build}/libs"/>

<copy file="${src.extract}/libs/jfreechart-1.0.9.jar" toDir="${build}/libs"/>

And the “<!-- Compile Robocode -->” section to read:<compile srcdir="${src.robocode}" destdir="${build}"

classpath="${build}/libs/codesize.jar;${build}/libs/jcommon-

1.0.12.jar;${build}/libs/jfreechart-1.0.9.jar"/>

Result:Robocode will now automatically copy the JAR files to the build folder, and reference it when compiling.

12

Page 10: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Save the file.

You should now be able to compile, but you will get a runtime error when you attempt to run Robocode from Eclipse.

13

Page 11: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

14

Page 12: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Setting up the class path.

Click on the Run button and click “Open Run Dialog…”

15

Page 13: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Browse to the Robocode run configuration, open the Classpathtab, click the on the “User Entries” tree node, and then click “Add JARs…”

16

Page 14: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Select the two JFreeChart JAR files in the build/build/lib folder. Click OK

Note - If you don’t see the build folder or the JAR files, you need to:

• Recompile your Robocode project (by clicking on the Project menu > Clean…), and/or• Refresh the “build” project folder (by right clicking on the “build” project folder and clicking “Refresh”)

17

Page 15: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Apply the changes and test your project by clicking Run.

Result:You can now run Robocode in Eclipse, but you won’t be able to run it outside of Eclipse.

18

Page 16: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

19

Page 17: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

There are two minor changes we have to make if you want to deploy using the archive.setup build target.

First, open up the robocode.bat file using the Text Editor (do not double click it! That will run the file!)

20

Page 18: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Append this to the end of the –cp (classpath) command line option:

;libs/jfreechart-1.0.9.jar;libs/jcommon-1.0.12.jar

The file should now read as:java -Xmx512M -Dsun.io.useCanonCaches=false -cp

libs/robocode.jar;libs/codesize.jar;libs/cachecle

aner.jar;libs/jfreechart-1.0.9.jar;libs/jcommon-

1.0.12.jar robocode.Robocode

21

Page 19: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Now, do the same for “robocode.sh”

22

Page 20: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Append this to the end of the –cp command line argument::libs/jfreechart-1.0.9.jar:libs/jcommon-1.0.12.jar

So that the line reads as:java -Xmx512M -Dsun.io.useCanonCaches=false -cp

libs/robocode.jar:libs/codesize.jar:libs/cachecle

aner.jar:libs/jfreechart-1.0.9.jar:libs/jcommon-

1.0.12.jar robocode.Robocode $*

23

Page 21: By: Hoang Huynh (hlhuynh@learn.senecac.on.ca) Copyright ...peter.liu/jac444/jfreechart.pdf · 1. Open up the Robocode workspace in Eclipse 2. Open up the “robocodeextract”project

Save the files, and you’re done! If you need additional help, feel free to contact me at: [email protected]

24