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"/>

Wednesday, 24 November 2010

Specified VM install not found: type Standard VM, name jre6

Ant wont run says "Specified VM install not found: type Standard VM, name jre6"!
Solution : delete the "C:\Users\Mujahed\workspace_helios\.metadata\.plugins\org.eclipse.debug.core\.launches\projectname build.xml.launch file"
and problem is solved"

Friday, 5 November 2010

maven eclipse error - Eclipse is running in a JRE, but a JDK is required

-startup
plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.1.R36x_v20100810
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vm
C:\Work\Sun\SDK\jdk\jre\bin\client\jvm.dll
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms128m
-Xmx1200m
-Dsun.lang.ClassLoader.allowArraySyntax=true

Friday, 16 April 2010

Missing indirectly referenced artifact javax.transaction:jta:jar:1.0.1B:compile

I added the following to my pom.xml

<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>


displayed error message:

Missing indirectly referenced artifact javax.transaction:jta:jar:1.0.1B:compile

This is due to licensing reason, JTA cannot be downloaded from the central repositories.

You will need to download/install the jar into your own repository manually.

Check out the Java.net maven 2 repo.
http://download.java.net/maven/2/javax/transaction/jta/1.0.1B/
Download the .jar, .jar.md5, and .jar.sha1 into you [.m2/javax/transaction/jta/1.0.1B/]
using the following:
mvn install:install-file -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar -Dfile=jta-1.0.1B.jar

Thursday, 8 April 2010

Maven IBM SDK java null pointer exception

When trying to install Maven 2 with IBM SDK on win vista, everything looks ok until maven archetype:generate command is issued. Once the command is issued it download a few jars and throws exception.
I had to uninstall IBM sdk from classpath env variables and delete the folder then reinstall java sdk and pointed it to classpath. Everycommand works now.

This means IBM SDK AND MAVEN are not compatible? isin't?