Tuesday 15 March 2011

javax.naming.NoInitialContextException: Need to specify class name in environment

if jndi.properties file is missing then you get this error. check the contents of jar file. Error stack trace is


[java] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parame
ter, or in an application resource file: java.naming.factory.initial
[java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
[java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
[java] at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
[java] at javax.naming.InitialContext.lookup(InitialContext.java:392)
[java] at ejb30.client.BankClient.main(Unknown Source)

Sunday 13 March 2011

javax.naming.NoInitialContextException

[java] javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory


This problem can be solved by adding weblogic.jar to the classpath
<?xml version="1.0" encoding="UTF-8"?>
<project name="ch03-lab01" default="usage" basedir=".">
<property environment="env" />
<property file="env.properties" />
<property name="app.name" value="ch03-lab01" />
<property name="config.dir" value="${basedir}/config" />
<property name="src.dir" value="${basedir}/src" />
<property name="build.dir" value="${basedir}/build" />

<taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy">
<classpath>
<pathelement location="${weblogic.home}/server/lib/weblogic.jar" />
</classpath>
</taskdef>

<path id="j2ee.classpath">
<pathelement location="${build.dir}" />
<fileset dir="${bea.home}/modules">
<include name="javax.ejb_3.0.1.jar" />
<include name="javax.annotation_1.1.jar" />
<include name="javax.persistence_1.0.0.0_1-0.jar" />
</fileset>
</path>

<target name="usage">
<echo message="build file for ${app.name}, available targets are:" />
<echo message="==================================================" />
<echo message="clean ---------> deletes build directory" />
<echo message="undeply ---------> deletes ear file from server" />
<echo message="all ---------> clean, complile, package and deploy the app" />
</target>

<target name="all">
<antcall target="usage" />
<antcall target="run-client" />
</target>


<target name="clean">
<delete dir="${build.dir}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dir}/client" />
<mkdir dir="${build.dir}/client/META-INF" />
</target>

<target name="compile" depends="clean">
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="j2ee.classpath" includeantruntime="false" />
</target>

<target name="package-ejb" depends="compile">
<jar jarfile="${build.dir}/BankService.jar">
<fileset dir="${build.dir}">
<include name="ejb30/session/**" />
<include name="ejb30/entity/**" />
</fileset>
<metainf dir="${config.dir}">
<include name="persistence.xml" />
</metainf>
</jar>
</target>

<target name="package-client" depends="compile">
<copy todir="${build.dir}/client">
<fileset dir="${config.dir}" includes="jndi.properties" />
</copy>
<jar jarfile="${build.dir}/Client.jar" manifest="${config.dir}/manifest.mf">
<fileset dir="${build.dir}/client" includes="**" />
<fileset dir="${build.dir}">
<include name="ejb30/client/Client.class" />
</fileset>
</jar>
</target>

<target name="package-ear" depends="package-ejb, package-client">
<jar destfile="${build.dir}/BankService.ear"
basedir="${build.dir}"
includes="BankService.jar"/>
</target>


<target name="deploy" depends="package-ear">
<wldeploy user="${admin.username}" password="${admin.password}"
adminurl="t3://${weblogic.hostname}:${weblogic.port}"
debug="true" action="deploy" name="BankService"
source="${build.dir}/BankService.ear" failonerror="${failondeploy}" />
</target>

<target name="undeploy">
<wldeploy user="${admin.username}" password="${admin.password}"
adminurl="t3://${weblogic.hostname}:${weblogic.port}"
debug="true" action="undeploy"
name="BankService" failonerror="${failondeploy}" />
</target>

<target name="run-client" depends="deploy">
<java classname="ejb30.client.Client" fork="yes">
<arg line="3 Belfast Northern"/>
<classpath>
<pathelement location="${build.dir}/Client.jar" />
<pathelement location="${weblogic.home}/server/lib/weblogic.jar" />
</classpath>
</java>
</target>
</project>

Sunday 6 March 2011

The type java.lang.Object cannot be resolved. It is indirectly referenced fromrequired .class files eclipse

Eclipse new Error Discovered

The type java.lang.Object cannot be resolved. It is indirectly referenced fromrequired .class files eclipse


Solution

Add the following code to .classpath file:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>