Stendhal on Eclipse: Difference between revisions

From Arianne
Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
 
(224 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Navigation for Stendhal Top|Building & Hosting}}
{{Navigation for Stendhal Top|Building & Hosting}}


This guide describes how to setup a development environment in Eclipse for Stendhal.
==First Steps==
<ol>
<li> First of all open the view called Package Explorer.</li>
<li> "New Project..."</li>
<li> "CVS" -> "Project from CVS" </li>
<li> Get stendhal from CVS. (Connection type: pserver, User: anonymous, Password - leave blank, Host:arianne.cvs.sourceforge.net, Repository: /cvsroot/arianne)</li>
<pre>
file-> new -> project -> project-> from cvs
click next


== Get Java ==
check "create new repository"
click next


* If you can play Stendhal, you already have Java and can skip this step.
host : arianne.cvs.sourceforge.net
* If you do not have java installed, please download it https://java.com<br> (if you are on Linux, use your packet manager)
repository path : /cvsroot/arianne
user : anonymous
connection Type: pserver
click next


== Get Node.js ==
check "use an existing module"
click directory: stendhal
click next


* https://nodejs.org (optional: for building & using web client)
checkout as a project configured using the new project wizard
click next


== Get Eclipse==
click finish


* Go to https://www.eclipse.org/downloads/
select a wizard: java project (do not select a simple "general" project!)
* Download: "Eclipse IDE for Java Developers"
project Name: stendhal ( or whatever you like to call it )
* Unzip the download and run Eclipse
make sure in jre a java version 1.5 or higher is selected
* In Eclipse, close the "Welcome" window
click finish
</pre>
<li> Right click on your project folder and select "Properties" in the context menu.</li>
<li> Then select "Java Build Path" on the left side of the dialog box.</li>
<li> Now remove all existing folders from source path and add the two source folders 'src' and 'tests' by clicking on the "Add Folder..." button</li>
<pre>
source folder #1:
stendhal/src
Included:(All)
Excluded:(None)
Native library location: (None)


You can click on the following images to see them in large.
source folder #2:
stendhal/tests
Included:(All)
Excluded:(None)
Native library location: (None)


<gallery>
default output folder: stendhal/bin
File:Eclipse_00.png|On the first run of Eclipse, this "Welcome" window is shown. Please close it.
</pre>
File:Eclipse_00a.png|Typical window layout with the Package Explorer on the left hand side and an empty area for editors in the middle
<li> On the "Libraries" tab: click on the "Add JARs" button and select all the *.jar-files in stendhal/lib</li>
</ol>
</gallery>
Note: If you installed Eclipse in Ubuntu via a package manager, also install: "eclipse-egit"
Eclipse should be able to compile the source code now. There could be a little yellow sign (signalling warning messages) before your project folder but there must not be red X (error messages). The package explorer should now display the "src" folder below the root folder with a different icon, the icon is like a small grid.

== New Project from Git ==

In Eclipse:

* Open menu "File -> Import
* In the dialog select: "Git -> Projects from Git" and click "Next".
* Select "Clone URI" and click "Next".
* Fill in the following information:
** '''URI''':
*** GitHub readonly: <code><nowiki>https://github.com/arianne/stendhal.git</nowiki></code><br>(if you have a github account, please go to https://github.com/arianne/stendhal and click on "Fork" to create you own copy of the repository and then use that in Eclipse instead)
*** GitHub read/write (SSH): <code><nowiki>git@github.com:arianne/stendhal.git</nowiki></code>
* The result of the fields are filled in automatically, click "Next"
* On the Branch selection page, keep everything selected and click "Next"
* Under "Destination" choose the directory where you want to download the source code and select "Next".
* Eclipse will now download Stendhal from git, this may take a while
* "Import existing projects" and select "Next"
* "Finish" import of project Stendhal

Click on the screenshots to enlarge them, if you need help with any of the steps:

<gallery>
Eclipse 01.png|Open File | Import
Eclipse 02.png|Import from Git
Eclipse 03.png|Clone URI
Eclipse 04.png|Fill in URI and watch the remaining fields to be filled automatically
Eclipse 05.png|Just click "next" on branch selection
Eclipse 06.png|Just click "next" on destination
Eclipse 07.png|Wait for the download to complete. This may take quite a while
Eclipse 08.png|Import existing project
Eclipse 09.png|Confirm import of project "Stendhal" by clicking finish
</gallery>


==Trouble Shooting==
==Trouble Shooting==
menu Windows | Preferences | Java | Installed JREs
* there should be at least one entry with a valid JAVA_HOME path (make it so so JDK compliance is 5.0 ?)


After completing the import wizard, Eclipse should look like the following screenshot:
==To make it run the server in Debug mode==

[[File:Eclipse 10.png]]

There is a project called "stendhal" listed in the Package Explorer view. There may be a tiny yellow triangle in front of the blue project icon. But if you see a red circle or a red exclamation mark, something went wrong. In this case there will be an error in the "Problems" view at the bottom.


== Start StendhalServer ==

* In the toolbar there is the "Debug" button, which looks like a little, green bug. There is a little black arrow on the right side of it.
* In the toolbar there is the "Debug" button, which looks like a little, green bug. There is a little black arrow on the right side of it.
[[File:Eclipse_debug_configurations_menu.png]]
* This will open a menu, please choose "Debug configurations ..." ("Open Debug Dialog..." on older versions)
* This will open a menu, please choose "Debug configurations ..." ("Open Debug Dialog..." on older versions)
* Then in the dialog select "Java Application" and click on the "new" icon in the top left corner.
* Then in the dialog select "Java Application" and click on the "new" icon in the top left corner.
[[File:Eclipse_new_debug_configuration.png]]


<pre> Name: StendhalServer
Name: StendhalServer
Main class: games.stendhal.server.StendhalServer
Main class: games.stendhal.server.StendhalServer


* All other settings ("include system libries", "Stop in main", ... can be left at their default value.
* All other settings ("include system libries", "Stop in main", ... can be left at their default value.
* on the [Arguments] tab: VM arguments: -Xmx128M

* on the [Classpath] tab: click "UserEntries" - button "Advanced" - (*) add folder | OK - and select the "stendhal" project root folder | OK
on the [Arguments] tab:
VM arguments: -Xmx128M

on the [Classpath] tab:
click UserEntries
button "Advanced"
(*) add folder | OK
and select the project root folder | OK
</pre>

* button [Debug]
* button [Debug]

And then the server should be started.
And then the server should be started.


NOTE: On newer Eclipse versions, the [Classpath Entries] are under Dependencies tab.
==To make the client run==

== Start Stendhal Client ==
# Open games.stendhal.client.update.Starter.java in the editor
# Open games.stendhal.client.update.Starter.java in the editor
# Then again the small black arrow on the right side of the green bug. (Or you may also choose to use the "Run" command instead of "Debug" in case you only want to debug the server component.)
# Then again the small black arrow on the right side of the green bug.
# Select "Debug Configurations" (or "Run Configurations...").
# Java Application -> new-icon, and it should be prefilled.
# Select Java Application and click the "New" button in upper-left corner.
# On the [Classpath] tab - button "Advanced" - (*) add folder | OK - and select the project root folder. | OK
# On the [Classpath] tab select "User Entries" - button "Advanced" - (*) add folder | OK - and select the project root folder. | OK

yay shiny new client, shiny server

Note: On OS X, you will first need to change character encoding to UTF-8. Select the stendhal project, then Project -> Properties -> Resource -> Text Encoding (default is MacRoman).


== Making patches ==
== Making patches ==
Line 98: Line 100:


==Running JUnit Tests in Eclipse==
==Running JUnit Tests in Eclipse==
# If you are runing JUnit tests in Eclipse, there are some additional things to be taken into account:
# Eclipse always automatically sets up a new run configuration for you if you invoke the "Run As" -> "JUnitTest" context command on a class or folder. It creates a default classpath configuration derived from the project settings in this run configurations. So there is missing the 'Stendhal' root folder in the classpath, which results in failures running some test cases. To fix this, open the run configurations and add the 'Stendhal' root folder like described above for the client configuration:
# On the [Classpath] tab - button "Advanced" - (*) add folder | OK - and select the project root folder. | OK
# After adding project-root to your classpath, Eclipse should automatically exclude the folders "src/" and "tests/". If not, exclude them together with "tools/" and "tiled/src/".

==Switching from pserver to extssh==
If you need to switch from anonymous read-only access to read/write, follow these
instructions.
(based on clues at http://blog.maestropublishing.com/changing-cvs-username-and-password-in-an-ecli)

# Window -> Show View -> Other
# Open up CVS, and double click on "CVS Repositories". A new tab will show up, named CVS Repositories
# Right click on the arianne line, and select Properties
# Change Connection Type to extssh
# Set User and Password to your sourceforge user id and password
# Click Apply. Eclipse will take a few minutes to update attributes.


This is an advanced topic. If you make changes to the Java code, it is a good idea to run the automatic test.
After that, test by trying another CVS Synchronize. The first time, you will probably get a dialog about the server certificate.


Setting up JUnit tests in Eclipse:
# Click the arrow next to either the green "Run" or "Debug" button.
# Select "Run/Debug Configurations...".
# Select "JUnit" in the left column and press the "New launch configuration" at the top of left column.
# Give it a unique name, like "Stendhal Tests".
# Select "Run all tests in the selected project, package or source folder".
# OPTIONAL: (this step simply reduces the number of directories that Eclipse will search in for tests)
## Press "Search".
## Select "tests" folder under Stendhal root directory and press "OK".
# Under "Test runner" select "JUnit 4".
# Under "Classpath" tab select "User Entries" and press "Advanced" on the right panel.
#* NOTE: There should already be a folder under "User Entries" with a "(default classpath)" suffix. Do not delete this folder.
# Select "Add Folders" and press "OK".
# Select the Stendhal root folder and press "OK".
# Now click "Add JARs..." on the right panel.
# Under the Stendhal root folder select all the .jar files in libs and press OK.
# Now press "Apply" to save the configuration or "Run" to save and run it.





Latest revision as of 18:13, 20 June 2023


This guide describes how to setup a development environment in Eclipse for Stendhal.

Get Java

  • If you can play Stendhal, you already have Java and can skip this step.
  • If you do not have java installed, please download it https://java.com
    (if you are on Linux, use your packet manager)

Get Node.js

Get Eclipse

You can click on the following images to see them in large.

Note: If you installed Eclipse in Ubuntu via a package manager, also install: "eclipse-egit"

New Project from Git

In Eclipse:

  • Open menu "File -> Import
  • In the dialog select: "Git -> Projects from Git" and click "Next".
  • Select "Clone URI" and click "Next".
  • Fill in the following information:
    • URI:
      • GitHub readonly: https://github.com/arianne/stendhal.git
        (if you have a github account, please go to https://github.com/arianne/stendhal and click on "Fork" to create you own copy of the repository and then use that in Eclipse instead)
      • GitHub read/write (SSH): git@github.com:arianne/stendhal.git
  • The result of the fields are filled in automatically, click "Next"
  • On the Branch selection page, keep everything selected and click "Next"
  • Under "Destination" choose the directory where you want to download the source code and select "Next".
  • Eclipse will now download Stendhal from git, this may take a while
  • "Import existing projects" and select "Next"
  • "Finish" import of project Stendhal

Click on the screenshots to enlarge them, if you need help with any of the steps:

Trouble Shooting

After completing the import wizard, Eclipse should look like the following screenshot:

There is a project called "stendhal" listed in the Package Explorer view. There may be a tiny yellow triangle in front of the blue project icon. But if you see a red circle or a red exclamation mark, something went wrong. In this case there will be an error in the "Problems" view at the bottom.


Start StendhalServer

  • In the toolbar there is the "Debug" button, which looks like a little, green bug. There is a little black arrow on the right side of it.

  • This will open a menu, please choose "Debug configurations ..." ("Open Debug Dialog..." on older versions)
  • Then in the dialog select "Java Application" and click on the "new" icon in the top left corner.

Name: StendhalServer
Main class: games.stendhal.server.StendhalServer
  • All other settings ("include system libries", "Stop in main", ... can be left at their default value.
  • on the [Arguments] tab: VM arguments: -Xmx128M
  • on the [Classpath] tab: click "UserEntries" - button "Advanced" - (*) add folder | OK - and select the "stendhal" project root folder | OK
  • button [Debug]

And then the server should be started.

NOTE: On newer Eclipse versions, the [Classpath Entries] are under Dependencies tab.

Start Stendhal Client

  1. Open games.stendhal.client.update.Starter.java in the editor
  2. Then again the small black arrow on the right side of the green bug.
  3. Select "Debug Configurations" (or "Run Configurations...").
  4. Select Java Application and click the "New" button in upper-left corner.
  5. On the [Classpath] tab select "User Entries" - button "Advanced" - (*) add folder | OK - and select the project root folder. | OK

Making patches

If you have modified and tested the code and want to send us a patch, please see How To Create Patch For Stendhal.

Running JUnit Tests in Eclipse

This is an advanced topic. If you make changes to the Java code, it is a good idea to run the automatic test.

Setting up JUnit tests in Eclipse:

  1. Click the arrow next to either the green "Run" or "Debug" button.
  2. Select "Run/Debug Configurations...".
  3. Select "JUnit" in the left column and press the "New launch configuration" at the top of left column.
  4. Give it a unique name, like "Stendhal Tests".
  5. Select "Run all tests in the selected project, package or source folder".
  6. OPTIONAL: (this step simply reduces the number of directories that Eclipse will search in for tests)
    1. Press "Search".
    2. Select "tests" folder under Stendhal root directory and press "OK".
  7. Under "Test runner" select "JUnit 4".
  8. Under "Classpath" tab select "User Entries" and press "Advanced" on the right panel.
    • NOTE: There should already be a folder under "User Entries" with a "(default classpath)" suffix. Do not delete this folder.
  9. Select "Add Folders" and press "OK".
  10. Select the Stendhal root folder and press "OK".
  11. Now click "Add JARs..." on the right panel.
  12. Under the Stendhal root folder select all the .jar files in libs and press OK.
  13. Now press "Apply" to save the configuration or "Run" to save and run it.