You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Quintin Beukes <qu...@skywalk.co.za> on 2009/10/22 22:39:47 UTC

Re: test project with HSQL => NoInitialContextException

Is the jndi.properties a Java feature? Meaning, I can put
jndi.properties at the root of my classpath and just do "new
InitialContext()" to have it loaded as the Context environment?

I usually do:
    Properties props = new Properties();
    props.load(SomeClass.class.getResourceAsStream("/META-INF/context.properties"));
    InitialContext ic = new InitialContext(props);

And if the first 2 steps are unnecessary, I've probably wasted a
couple of minutes...

Quintin Beukes



On Thu, Oct 22, 2009 at 7:04 PM, Jean-Louis MONTEIRO
<je...@atosorigin.com> wrote:
>
> Hi,
>
> Your JVM doesn't seem to find the OpenEJB initial context factory.
> Can you add the initial context factory in your java code just after
> creating Properties ?
> Have a look here  http://openejb.apache.org/3.0/embedded-configuration.html
> http://openejb.apache.org/3.0/embedded-configuration.html
>
> Did you add jndi.properties to your classpath?
>
> Both should work.
>
> Jean-Louis
>
>
>
> hypnosat7 wrote:
>>
>> Hello,
>>
>>  I'm trying to test my EJB project from another project. I've add a
>> dependencie in my test project to the EJB project. And I've set the
>> properties in a jndi.properties file in my test project. But when I launch
>> my first test class I get this error:
>>
>> javax.naming.NoInitialContextException: Need to specify class name in
>> environment or system property, or as an applet parameter, or in an
>> application resource file:  java.naming.factory.initial
>>       at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
>>       at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
>>       at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
>>       at javax.naming.InitialContext.lookup(Unknown Source)
>>       at ma.service.RessourceBeanTest.setUp(RessourceBeanTest.java:22)
>>       at junit.framework.TestCase.runBare(TestCase.java:128)
>>       at junit.framework.TestResult$1.protect(TestResult.java:106)
>>       at junit.framework.TestResult.runProtected(TestResult.java:124)
>>       at junit.framework.TestResult.run(TestResult.java:109)
>>       at junit.framework.TestCase.run(TestCase.java:120)
>>       at junit.framework.TestSuite.runTest(TestSuite.java:230)
>>       at junit.framework.TestSuite.run(TestSuite.java:225)
>>       at
>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>>       at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>>
>>
>> This is the jndi.properties file:
>> # set the initial context factory
>> java.naming.factory.initial =
>> org.apache.openejb.client.LocalInitialContextFactory
>>
>> # change some logging
>> log4j.category.OpenEJB.options = debug
>> log4j.category.OpenEJB.startup = debug
>> log4j.category.OpenEJB.startup.config = debug
>>
>> # create some resources
>> educaDatabase = new://Resource?type=DataSource
>> educaDatabase.JdbcDriver = org.hsqldb.jdbcDriver
>> educaDatabase.JdbcUrl = jdbc:hsqldb:mem:educadb
>> educaDatabase.UserName = sa
>> #educaDatabase.Password =
>>
>> # override properties on your "educaPU" persistence unit
>> #educaPU.eclipselink.target-database =
>> org.eclipse.persistence.platform.database.HSQLPlatform
>>
>> # set some openejb flags
>> #openejb.jndiname.format = {ejbName}/{interfaceClass}
>> openejb.descriptors.output = true
>> openejb.validation.output.level = verbose
>>
>>
>> and this is my test:
>>
>> public class RessourceBeanTest extends TestCase {
>>
>>       private RessourceRemote ressourceEJB;
>>
>>       @Override
>>       protected void setUp() throws Exception {
>>               System.out.println(System.getProperty("java.class.path"));
>>               Properties p = new Properties();
>>               InitialContext context = new InitialContext(p);
>>               ressourceEJB = (RessourceRemote) context
>>                               .lookup("RessourceBean/remote");
>>       }
>>
>> thanks for any help.
>>
>
> --
> View this message in context: http://www.nabble.com/test-project-with-HSQL--%3D%3E-NoInitialContextException-tp26013029p26013646.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>

Re: test project with HSQL => NoInitialContextException

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hi Quintin,

yes, IMO it isn't necessary. 
Your JVM looks for /jndi.properties in your classpath.

Jean-Louis


Quintin Beukes-2 wrote:
> 
> Is the jndi.properties a Java feature? Meaning, I can put
> jndi.properties at the root of my classpath and just do "new
> InitialContext()" to have it loaded as the Context environment?
> 
> I usually do:
>     Properties props = new Properties();
>    
> props.load(SomeClass.class.getResourceAsStream("/META-INF/context.properties"));
>     InitialContext ic = new InitialContext(props);
> 
> And if the first 2 steps are unnecessary, I've probably wasted a
> couple of minutes...
> 
> Quintin Beukes
> 
> 
> 
> On Thu, Oct 22, 2009 at 7:04 PM, Jean-Louis MONTEIRO
> <je...@atosorigin.com> wrote:
>>
>> Hi,
>>
>> Your JVM doesn't seem to find the OpenEJB initial context factory.
>> Can you add the initial context factory in your java code just after
>> creating Properties ?
>> Have a look here
>>  http://openejb.apache.org/3.0/embedded-configuration.html
>> http://openejb.apache.org/3.0/embedded-configuration.html
>>
>> Did you add jndi.properties to your classpath?
>>
>> Both should work.
>>
>> Jean-Louis
>>
>>
>>
>> hypnosat7 wrote:
>>>
>>> Hello,
>>>
>>>  I'm trying to test my EJB project from another project. I've add a
>>> dependencie in my test project to the EJB project. And I've set the
>>> properties in a jndi.properties file in my test project. But when I
>>> launch
>>> my first test class I get this error:
>>>
>>> javax.naming.NoInitialContextException: Need to specify class name in
>>> environment or system property, or as an applet parameter, or in an
>>> application resource file:  java.naming.factory.initial
>>>       at javax.naming.spi.NamingManager.getInitialContext(Unknown
>>> Source)
>>>       at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
>>>       at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown
>>> Source)
>>>       at javax.naming.InitialContext.lookup(Unknown Source)
>>>       at ma.service.RessourceBeanTest.setUp(RessourceBeanTest.java:22)
>>>       at junit.framework.TestCase.runBare(TestCase.java:128)
>>>       at junit.framework.TestResult$1.protect(TestResult.java:106)
>>>       at junit.framework.TestResult.runProtected(TestResult.java:124)
>>>       at junit.framework.TestResult.run(TestResult.java:109)
>>>       at junit.framework.TestCase.run(TestCase.java:120)
>>>       at junit.framework.TestSuite.runTest(TestSuite.java:230)
>>>       at junit.framework.TestSuite.run(TestSuite.java:225)
>>>       at
>>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>>>       at
>>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>>       at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>>>       at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>>>       at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>>>       at
>>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>>>
>>>
>>> This is the jndi.properties file:
>>> # set the initial context factory
>>> java.naming.factory.initial =
>>> org.apache.openejb.client.LocalInitialContextFactory
>>>
>>> # change some logging
>>> log4j.category.OpenEJB.options = debug
>>> log4j.category.OpenEJB.startup = debug
>>> log4j.category.OpenEJB.startup.config = debug
>>>
>>> # create some resources
>>> educaDatabase = new://Resource?type=DataSource
>>> educaDatabase.JdbcDriver = org.hsqldb.jdbcDriver
>>> educaDatabase.JdbcUrl = jdbc:hsqldb:mem:educadb
>>> educaDatabase.UserName = sa
>>> #educaDatabase.Password =
>>>
>>> # override properties on your "educaPU" persistence unit
>>> #educaPU.eclipselink.target-database =
>>> org.eclipse.persistence.platform.database.HSQLPlatform
>>>
>>> # set some openejb flags
>>> #openejb.jndiname.format = {ejbName}/{interfaceClass}
>>> openejb.descriptors.output = true
>>> openejb.validation.output.level = verbose
>>>
>>>
>>> and this is my test:
>>>
>>> public class RessourceBeanTest extends TestCase {
>>>
>>>       private RessourceRemote ressourceEJB;
>>>
>>>       @Override
>>>       protected void setUp() throws Exception {
>>>               System.out.println(System.getProperty("java.class.path"));
>>>               Properties p = new Properties();
>>>               InitialContext context = new InitialContext(p);
>>>               ressourceEJB = (RessourceRemote) context
>>>                               .lookup("RessourceBean/remote");
>>>       }
>>>
>>> thanks for any help.
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/test-project-with-HSQL--%3D%3E-NoInitialContextException-tp26013029p26013646.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/test-project-with-HSQL--%3D%3E-NoInitialContextException-tp26013029p26022191.html
Sent from the OpenEJB User mailing list archive at Nabble.com.