Guide: How to compile a .jar file for your extension

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Bax, Lapo, rjgtav

Step by Step SFSx2 debugging

Postby hamish » 14 Dec 2010, 11:54

Step by Step SFSx2 extension debugging

Hi just went through this process and thought i'd post it to make it easy for everyone, coz there are a few errors in the posts i've read.

I'm using eclipse IDE for java developers 3.6.1, and sfs2x server is running on my local machine, on windows xp

backup the bat file at

install folder/SFS2X/sfs2x.bat

edit the file with notepad and replace what's there with

@java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y -cp "./;lib/*;lib/Jetty/*;extensions/__lib__/*" -Dfile.encoding=UTF-8 com.smartfoxserver.v2.Main $1 $2 $3

go to eclipse

run/debug configurations...

right click Remote Java Application and choose Add...

make sure the connection properties are set to
host: localhost
Port: 8787

double click the bat file you edited.

the cmd window should appear and say

Listening for transport dt_socket at address 8787

press the little green bug in eclipse to start the debugging session ( i found i had to click the little arrow next to it and select my extension name)

when you start the debugging session the SFSx2 server should start as normal

set some breakpoints in your extension code.

and enjoy.
Last edited by hamish on 24 Jan 2011, 15:54, edited 1 time in total.
hamish
 
Posts: 6
Joined: 13 Dec 2010, 16:49
Location: UK

Postby lolandroll » 19 Dec 2010, 09:03

Does enyone can tell how to recompile the expamles from that page:

http://docs2x.smartfoxserver.com/Develo ... se-recipes

becouse I wanted to chage database name for something else and changing it in java filese doesn't seems to work

#########################
Nevermind -
i saw that lapo add new tutorial in the docs

http://docs2x.smartfoxserver.com/Develo ... extensions

:) That would help
lolandroll
 
Posts: 7
Joined: 30 Nov 2010, 17:15

Re: Guide: How to compile a .jar file for your extension

Postby levancho » 22 Feb 2012, 11:54

just want to contribute my approach.

I use executable instead of bat file so in that case editing : sfs2x-standalone.vmoptions was sufficient for me to get debugger working.

I added :
Code: Select all
-Xdebug
-Xnoagent
-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n


and just to make sure debugger is working, you should see something like his in startup console (at the begining) :

Code: Select all
Listening for transport dt_socket at address: 8787
User avatar
levancho
 
Posts: 71
Joined: 27 Jun 2011, 16:03

Re: Guide: How to compile a .jar file for your extension

Postby huhailong » 14 Jan 2013, 03:45

does all java class for a zone need to put to one xxxExtension.jar ?
because i have a problem: i create a class MyOSExtension extends OpenSpaceExtension, this class will create all room and other data when sfs2x start,
i put this class to fox2Extension.jar, this jar also has some other class to handle the client request,
right now i changed some other class and export to fox2Extension.jar,
class MyOSExtension didn't change, but when jar replaced, the class MyOSExtension automaticlly running, so it will create all room again but failed.
if class MyOSExtension runned again, it will occur issue for our sfs game.
the issue log is :
11:35:03,168 INFO [com.smartfoxserver.v2.controllers.ExtensionController-3] utils.Logger - [OpenSpace] User dragon [0] requested path from (52, 56, 0) to (56, 58, 0) on map 'floors/b801_fn1#A'
11:35:03,172 ERROR [com.smartfoxserver.v2.controllers.ExtensionController-3] utils.Logger - [OpenSpace] java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: An unexpected exception occurred while the OpenSpace Core Extension executed command path
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.openspace.commands.CalculatePathCommand.execute(CalculatePathCommand.java:84)
com.smartfoxserver.openspace.handlers.OSRequestHandler.handleClientRequest(OSRequestHandler.java:81)
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:192)
com.smartfoxserver.v2.controllers.ExtensionController.processRequest(ExtensionController.java:133)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
huhailong
 
Posts: 28
Joined: 14 May 2010, 04:39

Re: Guide: How to compile a .jar file for your extension

Postby Bax » 15 Jan 2013, 09:46

huhailong, please don't double-post: viewtopic.php?p=66043#p66043
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
 
Posts: 3847
Joined: 29 Mar 2005, 09:50
Location: Italy

Re: Guide: How to compile a .jar file for your extension

Postby FCrocetti » 19 Apr 2013, 10:07

Hello,

I'm having issues on listing in the zone extension list my custom jars compiled from Netbeans 7.1, I don't succeed neither on SFS2X for OSX 10.8 nor for Windows 7. I have to say that I'm completely newbie in Java (but I'm a senior programmer in a bunch of other languages so it's not a problem), but I followed these steps and the video tutorial though my extension is not listed.

I don't succeed to list neither a "hello world" extension like this:

Code: Select all
import com.smartfoxserver.v2.extensions.SFSExtension;

public class testSfsExtension extends SFSExtension {

    @Override
    public void init() {
        trace("***[ Test Sfs Extension loaded ]***");
    }
   
}


Since moving your TrisExtension.jar to my folder in /extensions makes my folder to be correctly listed in Zone manager (but my classes are not listed in the Main classes), I can only suppose it has something to do with how I'm compiling.

You can find the project source (very small, it is the example above) here, it contains the Netbeans project folder so you can see both source and the compiled jar (in the folder /dist). By the way in the project settings I have Source/Binary Format=JDK6 and Encoding=UTF-8, you can take a look at the screenshot here.

Thank you in advance, best regards.
FCrocetti
 
Posts: 2
Joined: 19 Apr 2013, 01:40

Re: Guide: How to compile a .jar file for your extension

Postby Lapo » 19 Apr 2013, 10:19

Hi,
a few suggestions.

1- Please do use a package declaration in your classes
2- Please always start a class name with a capital letter (TestSfsExtension not testSfsExtension)
3- Follow the SFS2X jar naming convention: <AnyName>Extension.jar, e.g.: MyCoolExtension.jar, GameExtension.jar, PokerExtension.jar etc...

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 15677
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Guide: How to compile a .jar file for your extension

Postby FCrocetti » 19 Apr 2013, 11:58

Great! It worked, I don't know if it was because of first capital letter renaming on the extension class or the suffix "Extension" to jar filename or both, however now they're listed and I can continue testing! It's probably useful to append these hints to the topic message.

Thanks
FCrocetti
 
Posts: 2
Joined: 19 Apr 2013, 01:40

Re: Guide: How to compile a .jar file for your extension

Postby Bax » 22 Apr 2013, 10:22

The problem was the "Extension" suffix.
This is described in the doc too.
Paolo Bax
The SmartFoxServer Team
User avatar
Bax
Site Admin
 
Posts: 3847
Joined: 29 Mar 2005, 09:50
Location: Italy

Previous

Return to SFS2X Questions

Who is online

Users browsing this forum: Bing [Bot] and 1 guest