I found a solution to fix this issue. It seems like DWR doesn´t instantiate every class on the server-startup. (But it apparently does if there is only one class defined in the config file). However, I just implemented a "dummy-method" in dwr-classes, called "start()". The Method does nothing, but when it get's called from javascript, the class gets instantiated. My solution looks like this:
<servlet>
<display-name>DWR Servlet</display-name>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>classes</param-name>
<param-value>
de.package.Dwr1,
de.another.package.Dwr2
</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
Dwr1
@RemoteProxy public class Dwr1 { @RemoteMethod public String getString(String key) { return Util.GetString(key); } }
Dwr2
@RemoteProxy public class Dwr2 { public Dwr2() { ServerUtil.registerOnFE(new UpdateClient()); } @RemoteMethod public void start() { //Do nothing } private void updateBrowser(final String arg) { Browser.withPage("/page.do", new Runnable() { @Override public void run() { ScriptSessions.addFunctionCall("update", arg); } }); } private class UpdateClient { @Override onRecieveUpdate(String arg) { updateBrowser(arg); } } }
A call of the start()-method of Dwr2 class triggers the insantiation of it.