Page 1 of 1

Starting SmartFoxServer using java ant task

Posted: 29 Jul 2008, 13:25
by simongroenewolt
Hi

Smartfox version: 1.6.2

We are starting to develop a game using smartfox - I want to keep the development setup as automated as possible and therefore want to use an ant script to startup the smartfox server (after doing the necessary compiles and moves of files -- we are using java extensions)

My plan is to ask all developers to install their own version of smartfox and set an environment variable pointing to that installation.

I'm running into a problem with the jython part.
Exception in thread "main" Traceback (innermost last):
File "<string>", line 13, in ?
ImportError: no module named main
My ant file contains the following setup:
<property name="smartfoxlib" value="${env.SMARTFOXSERVER_HOME}/lib"/>
<property name="smartfoxjavaextensions" value="${env.SMARTFOXSERVER_HOME}/javaExtensions"/>
<property name="smartfoxsfsextensions" value="${env.SMARTFOXSERVER_HOME}/sfsExtensions"/>
<property name="pypath" value="${env.SMARTFOXSERVER_HOME}" />

<path id="smartfox.classpath">
<fileset dir="${smartfoxlib}">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${smartfoxjavaextensions}"/>
<pathelement path="${smartfoxsfsextensions}"/>
<pathelement path="${pypath}"/>
</path>

<target name="run">
<echo message="Smartfox Server Home = ${env.SMARTFOXSERVER_HOME}"/>

<property name="myclasspath" refid="smartfox.classpath"/>
<echo message="classpath = ${myclasspath}"/>
<java
classname="it.gotoandplay.smartfoxserver.SmartFoxServer"
classpathref="smartfox.classpath"
fork="true"
>
<jvmarg value="-Dfile.encoding=UTF-8"/>
<jvmarg value="-Djava.util.logging.config.file=logging.properties"/>
<arg value="smartfox_config.xml" />
</java>
</target>
(SMARTFOXSERVER_HOME is the environment var that points to the smartfox 'Server' directory)

From tracing a bit on the kernel level I have the idea that the java part of the server starts running, tries to load python stuff and fails half-way through...

I hope someone has a hint for me, I don't know a lot about Python/Jython

Simon

PS: the server runs just fine when I run it using it's own scripts from withing the server dir.

Posted: 29 Jul 2008, 13:43
by simongroenewolt
If I move the ant build.xml file into the smartfox 'Server' directory it works - so it probably has something to do with the current directory and the opening of files relative to that...

I still appreciate tips on how to make it work.

Posted: 29 Jul 2008, 13:47
by duncanhall
I've no idea if this would work, but what about creating a simple batch file in the SF server directory that starts SmartFox. Then you could call that batch file from your ant task. This may well run into the same relative paths/permissions problems, but it might be worth a try.

Posted: 29 Jul 2008, 14:11
by simongroenewolt
Thanks for the suggestion Duncan!

I've figured out a way to do it with 'pure' ant. There is a dir attribute for the java task that launches the java process with that dir as the cwd. That fixed the python loading issue.

Next problem was my custom config.xml - I ended up adding the directory it was in to the classpath, it seems smartfox loads it from there.

The reason I don't want to use a batch file is that we are doing development/testing/everything on both windows and osx (and deploying on linux)

Now I can tell people to install a clean smartfoxserver and run it with our settings and extensions without any modification to the install dir :-)