Helo Helpers, I have to dynamically create a JNDI Datasource, I tried to do this with a listener called SetupApplicationListener. Here is the beginning of WEB-LIB/web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee"> <display-name>pri-web</display-name> <listener> <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> </listener> <listener> <listener-class>myapp.SetupApplicationListener</listener-class> </listener>
Listener Code:
public class SetupApplicationListener implements ServletContextListener { public static Log LOG = null; public void contextInitialized(ServletContextEvent ctx){ try { createOracleDataSource(); ..... } } private void createOracleDataSource() throws SQLException, NamingException { OracleDataSource ds = new OracleDataSource(); ds.setDriverType(...); ds.setServerName(...); ds.setPortNumber(...); ds.setDatabaseName(...); ds.setUser(...); ds.setPassword(...); new InitialContext().bind("java:comp/env/jdbc/myDS", ds); } ..... }
And there is an error:
[ERROR] 29/01/2013 09:44:50,517 (SetupApplicationListener.java:86) -> Error javax.naming.NamingException: Context is read only at org.apache.naming.NamingContext.checkWritable(NamingContext.java:903) at org.apache.naming.NamingContext.bind(NamingContext.java:831) at org.apache.naming.NamingContext.bind(NamingContext.java:171) at org.apache.naming.NamingContext.bind(NamingContext.java:187) at org.apache.naming.SelectorContext.bind(SelectorContext.java:186) at javax.naming.InitialContext.bind(InitialContext.java:359) at myapp.SetupApplicationListener.createOracleDataSource(SetupApplicationListener.java:102)
Can I set the read-only “Context” properties of “true”? Thank you :)
Tomcat 6.0 Oracle 11g jdk1.5
EDIT : not needed dynamically, I have to determine the jndi data source myself. I cannot change server files because it is a shared server. It must be jndi, because other modules use it that way, thanks.
source share