Skip to content

Easily bind Objects of any type via JNDI in standalone java app. Example: Get a DataSource from JNDI

License

Notifications You must be signed in to change notification settings

joseerodrigues/easyjndi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

easyjndi

Easily bind Objects of any type via JNDI in standalone java app. Example: Get a DataSource from JNDI

Maven dependency

<dependency>
  <groupId>io.github.joseerodrigues.utils</groupId>
  <artifactId>easyjndi</artifactId>
  <version>0.0.1</version>
</dependency>

How to use

  1. Install easyjndi InitialContextFactory
  2. Use the returned context instance and add your jndi mappings

Sample - create a DataSource in a standalone app

Using c3p0 for a datasource implementation

//create a new datasource using c3p0
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass("com.ibm.db2.jcc.DB2Driver"); 
cpds.setJdbcUrl("jdbc:db2://myhost:5021/mydb");
cpds.setUser("username");                                  
cpds.setPassword("password");

//setup easyjndi
Context ctx = EasyJndi.install();

//bind JNDI name to dataSource instance
ctx.bind("jdbc/DB", cpds);

And that's it!

Now any lookups will return your provided dataSource

InitialContext ctx = new InitialContext();

DataSource ds = ctx.lookup("jdbc/DB");

About

Easily bind Objects of any type via JNDI in standalone java app. Example: Get a DataSource from JNDI

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages