Download CONFIGURING THE PSIMJ2 PACKAGE For Using with Eclipse

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CONFIGURING THE PSIMJ2 PACKAGE
For Using with Eclipse
Object Oriented Simulation with Java & PsimJ2
José M. Garrido
Department of Computer Science
November, 2014
College of Computing and Software Engineering
Kennesaw State University
c 2014, J. M. Garrido
Configuring the PsimJ2 package
1
2
Using The Eclipse Platform
The Eclipse platform is an open extensible IDE for developing programs
in Java, C++, and various other programming languages. Eclipse has been
developed for several Operating Systems platforms, such as Linux, MS Windows, Mac OS X, and others. The platform is composed of the Workbench,
the Workspace, and other components. The Workbench is the desktop development environment; it is a tool that integrates the creation, management,
and navigation of workspace resources. Eclipse uses the workspaces to store
the user projects.
Each Workbench window contains one or more perspectives, which contain views and editors and control what appears in certain menus and tool
bars. A Workbench consists of:
• Perspectives
• Views
• Editors
A perspective is a group of views and editors in the Workbench window.
One or more perspectives can exist in a single Workbench window. A view is
a visual component within the Workbench. It is normally used to navigate a
hierarchy of resources in the Workbench, or display properties for the active
editor. Modifications made in a view are saved immediately.
An editor is also a visual component within the Workbench. It is used
to edit or browse a resource. The visual presentation might be text or a
diagram. Editors are launched by clicking on a resource in a view. Some
features are common to both views and editors. These can be active or
inactive, but only one can be active at any one time. The active part is
the target for common operations like cut, copy and paste. If an editor
tab is not highlighted it indicates the editor is not active, however views
may show data based on the last active editor. The Eclipse software can be
downloaded from:
http://www.eclipse.org
c 2014 J. M. Garrido
Configuring the PsimJ2 package
2
3
Configuring Eclipse for Java Simulation Models
After installing the Eclipse Platform, start Eclipse by double-clicking on
the Eclipse icon on the desktop. The next few steps should be followed to
appropriately configure Eclipse for developing simulation models. Select a
folder for the Eclipse workspace. On the File menu, select Switch Workspace,
then select Other. The following window shows on the screen.
Set the folder where the projects with source files are located. All the
Java source files will be placed in a Java project. For example, assuming
that the Java projects are located in the parent folder C:\pjava, type this
path then click the OK button. Eclipse loads immediately the workspace.
Figure 1: A new project in Eclipse.
2.1
Developing OOSimL Simulation Models with Eclipse
As mentioned previously, all Java source files should be stored in a Java
project. To develop a simulation model, a Java project must first be created
c 2014 J. M. Garrido
Configuring the PsimJ2 package
4
with Eclipse. The Java source files are then placed within this project.
To create a new Java project, activate the File menu on the top tool bar,
select New, select Project, and then select Java Project.
Figure 2: Importing files for a new project in Eclipse.
Inside the New Project window, expand the Java subtree and select
Java Project. Click the Next button at the bottom of the window. Type
a name for the project and click the Finish button. Automatically a Java
Perspective is opened for the project. Figure 1 shows the Project Wizard
window that appears on the screen.
A project will normally contain more than one source file, each representing a class implementation. The source files can be created and edited
or can be imported from another folder if these files already exist. To create
a new source file in a project, click the project name, activate the File menu
on the top tool bar, select New then select File. Type the name of the file
and click on the Finish button.
To import an existing file, click on the name of the project, click on the
File menu, then select Import. On the Import window, expand the General
tree and select File System. Click on the Next button. On the new window
click the Browse button to find the source directory of the file to import.
Select the file(s) to import and click on the Finish button. Figure 2 shows
the Import files window that appears on the screen.
c 2014 J. M. Garrido
Configuring the PsimJ2 package
5
Figure 3: The Project Properties window.
The next step sets the additional libraries required to build the project by
setting the options in the build path for a Java project. Activate the Project
menu and select Properties. Figure 4 shows the window that appears on the
screen.
Select Java Build Path and open the Libraries tab. Figure 4 shows the
window that appears on the screen.
Click on the Add External JARs button. On the JAR Selection window,
search and select the JAR file that contains the required library. Click the
Open button. Click OK on the current window. shows the window that
appears on the screen.
Figure 4: The Build Path window to set external libraries.
c 2014 J. M. Garrido
Configuring the PsimJ2 package
6
Figure 5: The Build Path window with external libraries selected.
To run a simulation model that has been configured on Eclipse, click on
the project name in the Eclipse Project Explorer pane. Activate the Run
menu on the top tool bar, select Run As, select Java Application, then select
the matching item (default package). Figure 6 shows the Eclipse screen after
a simulation run of the Train model in project trainec.
3
Developing Models in a Command Window
In a DOS window, any text editor can be used to enter a new program in
Java or to modify an existing program. Two good editors for developing
Java programs are Notepad++ and the DOS Editor. For editing in a DOS
window, complete the following steps:
1. Start and open a Command window. You can do this by clicking the
Start button and then selecting Run. In the Run window, type the
word command and click the OK button.
2. Change the directory to the one where your files are stored. Use the
CD command in DOS.
3. Start the DOS editor. Figure 7 shows a DOS window with the editor.
4. Use the Java compiler to compile the Java program (e.g. Tarea.java).
c 2014 J. M. Garrido
Configuring the PsimJ2 package
7
Figure 6: Running the Train simulation model in Eclipse
5. Use the Java virtual machine (JVM) to execute the compiled program. When starting execution, enter the input data to the program,
if needed.
6. Return to the Windows desktop by typing exit while in DOS.
To change the directory to the one where you have the source programs,
type the following command: cd\, and then press the Enter key. If the
directory with your source programs is called eoosl, on the next line type
cd eoosl and then press the Enter key; this changes to the directory called
eoosl. To get a list of the files in the current directory, type dir and then
press Enter.
To start the DOS editor, type edit at the command prompt then press
the Enter key. After the editor starts and if you are typing a new source
program, start typing line by line; press the Enter key at the end of every
line. When you have completed entering the text, click on the File menu and
select the Save as option. Type the name of the file (program name). It
must start with a capital letter, and have a .java extension. For example,
Tarea.java. Figure 7 shows the DOS editor with some text lines already
entered. To exit the DOS editor, click the File menu, and then select Exit.
To invoke the Java compiler and compile the file Tarea.java, type javac
Tarea.java in DOS. After a few seconds, the Java compiler completes and
c 2014 J. M. Garrido
Configuring the PsimJ2 package
8
Figure 7: The DOS editor
displays error messages, if any. Take note of the error messages and go back
to the DOS editor to correct them, by editing the OOSimL source program.
If there are no error messages, run the program by invoking the Java
Virtual Machine (JVM), and then type java Tarea at the DOS prompt.
Notice that you don’t need the file extension. After a few seconds, your
program starts execution.
Compiling simulation programs, involve setting the classpath for the
compiler to find the appropriate libraries, psimj2.jar and acm.jar. Assume that these libraries are located in the c:\eoosl directory and that
the current directory contains the Java classes for the simulation model, the
following command compiles all the Java files in the current directory.
javac -classpath c:\eoosl\psimj2.jar;c:\eoosl\acm.jar *.java
c 2014 J. M. Garrido
Configuring the PsimJ2 package
9
The following command will start execution of the simulation model,
assuming that the main class is named Barber.
java -classpath c:\eoosl\psimj2.jar;. Barber
c 2014 J. M. Garrido