I have a Red5 application that runs fine in Eclipse. But when I build the app and try to run it as a Windows service I am getting an error.
After the app starts, when it tries to start the Red5 server I get the following error/stack trace:
Tue Mar 14 16:00:51 MDT 2017: debug: about to get baseLoader
Tue Mar 14 16:00:51 MDT 2017: debug: about to get loader: sun.misc.Launcher$AppClassLoader@1bb3e9a
Tue Mar 14 16:00:51 MDT 2017: debug: about to set new loader:java.net.URLClassLoader@d16e55
Tue Mar 14 16:00:51 MDT 2017: debug: about to create boot object: java.net.URLClassLoader@d16e55
Tue Mar 14 16:00:51 MDT 2017: debug: about to get method 1: org.red5.server.Launcher@b20dae
Tue Mar 14 16:00:51 MDT 2017: debug: about to invoke method 1: public void org.red5.server.Launcher.launch() throws java.lang.Exception
Tue Mar 14 16:01:01 MDT 2017: error: Errorjava.lang.reflect.InvocationTargetException
Tue Mar 14 16:01:01 MDT 2017: error: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at ...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.rzo.yajsw.app.WrapperJVMMain.executeMain(WrapperJVMMain.java:53)
at org.rzo.yajsw.app.WrapperJVMMain.main(WrapperJVMMain.java:36)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'context.loader' defined in class path resource [red5.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcat.server' defined in class path resource [jee-container.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.red5.server.Launcher.launch(Launcher.java:69)
... 14 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcat.server' defined in class path resource [jee-container.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:217)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:350)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
at org.red5.server.ContextLoader.afterPropertiesSet(ContextLoader.java:113)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 24 more
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Unknown Source)
at java.util.Properties.setProperty(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at org.red5.server.tomcat.TomcatLoader.start(TomcatLoader.java:252)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1702)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1641)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 36 more
My relevant code is as follows:
// get current loader
logDebug(" about to get baseLoader");
ClassLoader baseLoader = Thread.currentThread().getContextClassLoader();
// build a ClassLoader
logDebug(" about to get loader: " + baseLoader);
ClassLoader loader = ClassLoaderBuilder.build();
// set new loader as the loader for this thread
logDebug(" about to set new loader:" + loader);
Thread.currentThread().setContextClassLoader(loader);
// create a new instance of this class using new classloader
logDebug(" about to create boot object: " + loader);
Object boot = Class.forName("org.red5.server.Launcher", true, loader).newInstance();
logDebug(" about to get method 1: " + boot);
Method m1 = boot.getClass().getMethod("launch", (Class[]) null);
logDebug(" about to invoke method 1: " + m1);
m1.invoke(boot, (Object[]) null);
// not that it matters, but set it back to the original loader
logDebug(" about to set original loader: " + m1);
Thread.currentThread().setContextClassLoader(baseLoader);
Any ideas what is causing the error and how to fix it?
EDIT:
I added a system property called red5.root set to the Red5 root directory as shown below and it got rid of the nullPointerException I was having above.
String red5Root = serverHome + "/red5-server-1.0.6-RELEASE";
System.setProperty("red5.root", red5Root);
However I am still having a problem connecting to the red5 server. When I try to go to access my web app with the following url:
localhost:8080/streaming/streaming.html
I am getting a 500 error with this exception:
java.lang.NullPointerException org.red5.logging.LoggerContextFilter.doFilter(LoggerContextFilter.java:64)
What could be causing this NullPointerExeption?
Since the first question is already kind of answered in the edit I will just answer the second question.
The NPE was happening because of conflicting logging jars in the classpath. I was able to solve the problem by removing the following from my webapps/myApp/WEB-INF/web.xml file.
<filter>
<filter-name>LoggerContextFilter</filter-name>
<filter-class>org.red5.logging.LoggerContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoggerContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>