Headless Server

I’m having trouble setting up a HeadlessServer… I need just a extremely simple starter. The wiki tutorials don’t really help much at all.

I’ve got the jMonkeyEngine3.jar in the classpath, and I have this code:



[java]package makeza.server;



import java.io.IOException;



import com.jme3.app.Application;

import com.jme3.app.SimpleApplication;

import com.jme3.network.*;

import com.jme3.system.JmeContext;



public class Main extends SimpleApplication {



/**

  • @param args

    */

    public static void main(String args) {

    Application app = new Main();

    app.start(JmeContext.Type.Headless);

    }



    public void simpleInitApp() {



    Server myServer;

    try {

    myServer = Network.createServer(1345);

    myServer.start();

    } catch (IOException e) {

    e.printStackTrace();

    }



    }



    }[/java]



    It’s throwing a lot of classnotfound errors such as the GUI libraries not existing etc, if it’s a headless server it shouldn’t need them.
WARNING: Failed to find loader: com.jme3.audio.plugins.OGGLoader
java.lang.NoClassDefFoundError: de/jarnbjo/ogg/PhysicalOggStream
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.jme3.asset.DesktopAssetManager.registerLoader(DesktopAssetManager.java:113)
at com.jme3.asset.AssetConfig.loadText(AssetConfig.java:74)
at com.jme3.asset.DesktopAssetManager.(DesktopAssetManager.java:84)
at com.jme3.system.JmeSystem.newAssetManager(JmeSystem.java:103)
at com.jme3.app.Application.initAssetManager(Application.java:171)
at com.jme3.app.Application.initialize(Application.java:476)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:203)
at com.jme3.system.NullContext.initInThread(NullContext.java:85)
at com.jme3.system.NullContext.run(NullContext.java:128)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: de.jarnbjo.ogg.PhysicalOggStream
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
Sep 26, 2011 10:05:04 PM com.jme3.asset.DesktopAssetManager
INFO: DesktopAssetManager created.
Sep 26, 2011 10:05:04 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
Sep 26, 2011 10:05:04 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
Sep 26, 2011 10:05:04 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[Headless Application Thread,5,main]
java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.jme3.system.JmeSystem.newAudioRenderer(JmeSystem.java:307)
at com.jme3.app.Application.initAudio(Application.java:211)
at com.jme3.app.Application.initialize(Application.java:485)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:203)
at com.jme3.system.NullContext.initInThread(NullContext.java:85)
at com.jme3.system.NullContext.run(NullContext.java:128)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more

By extending SimpleApplication the application is causing jME to start its asset manager that goes out looking for other pieces of code (in this case, the lack of the OGG library is biting you)



Try this:

[java]



package makeza.server;



import java.io.IOException;

import com.jme3.network.*;



public class Main {



/**

  • @param args

    */

    public static void main(String[] args) {

    Server myServer;

    try {

    myServer = Network.createServer(1345);

    myServer.start();

    } catch (IOException e) {

    e.printStackTrace();

    }

    }

    }

    [/java]

It seems that headless mode doesn’t set the audio renderer to null, probably should fix that

@sbook

That’s a good suggestion, however right after the server is created the application closes, here is the output.


Sep 27, 2011 7:49:26 PM com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread connect
INFO: Hosting TCP connection:0.0.0.0/0.0.0.0:1345.
Sep 27, 2011 7:49:26 PM com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread run
INFO: Kernel started for connection:0.0.0.0/0.0.0.0:1345.
Sep 27, 2011 7:49:26 PM com.jme3.network.kernel.udp.UdpKernel$HostThread connect
INFO: Hosting UDP connection:0.0.0.0/0.0.0.0:1345.
Sep 27, 2011 7:49:26 PM com.jme3.network.kernel.udp.UdpKernel$HostThread run
INFO: Kernel started for connection:0.0.0.0/0.0.0.0:1345.

Yes, you need to do something to keep the application running since the passive network threads are all daemons. Most servers started in this way will implement some kind of command prompt, I guess… or you could just while(true) sleep.



How do you intend to run the server?



If it’s just a command line app then you could do something like:

[java]

…setup the server…

server.start();

BufferedReader in = new BufferedReader(new InputStreamReader(System.io));

String line = null;

while( (line = in.readLine()) != null ) {

if( “exit”.equals(line) ) {

break;

}

}

server.shutdown();

[/java]

What @pspeed said is almost exactly what I would’ve replied with… except I probably would’ve been too lazy too write an example :wink:

@pspeed Ah, that works great.