P
Priya Kheterpal
Hi,
I am just posting this message so that it might be useful for people
who access this site and may get this kind of error.Though the
solution might not be useful for all as this error can come in many
scenarios.But one of the scenarios can be one that I got.
I was trying to compile the java with following code as in Mastering
EJb2.I have placed this file in D:\examples directory
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class HelloClient
{
public static void main(String args[])
{
Properties props = System.getProperties();
try
{
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj,HelloHome.class);
Hello hello = home.create();
/*System.out.println(hello.hello());
hello.remove(); */
}
catch(Exception e){};
}
}
My Hello.class was also placed in D:\examples directory along with the
classes like HelloHome.class etc.The classpath was set till D:\.
I was getting the following error while compiling this file from
D:\examples.I have given the following command for compiling:javac
HelloClient.java
The following was the error that I was getting -
HelloClient.java:20: cannot access examples.Hello
bad class file: D:\examples\Hello.class
illegal start of class file
Please remove or make sure it appears in the correct subdirectory of
the classpa
th.
Hello hello = home.create();
^
1 error
Intially I was confused, as to me the classpath seemed to be perfectly
correct.Still I tried changing classpath many times.But , still it was
of no use.
Then I realised that my HelloClient.java code was also containing the
code which was accessing HelloHome.class which was also in same
location as Hello.class.And , I was not getting any error for this
class.So , I recompiled my Hello.java to again create Hello.class(and
deleted the previous Hello.clas) and it solved the problem.I suppose
my Hello.class got corrupted.I am not sure how.
I am just posting this message so that it might be useful for people
who access this site and may get this kind of error.Though the
solution might not be useful for all as this error can come in many
scenarios.But one of the scenarios can be one that I got.
I was trying to compile the java with following code as in Mastering
EJb2.I have placed this file in D:\examples directory
package examples;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
public class HelloClient
{
public static void main(String args[])
{
Properties props = System.getProperties();
try
{
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("HelloHome");
HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj,HelloHome.class);
Hello hello = home.create();
/*System.out.println(hello.hello());
hello.remove(); */
}
catch(Exception e){};
}
}
My Hello.class was also placed in D:\examples directory along with the
classes like HelloHome.class etc.The classpath was set till D:\.
I was getting the following error while compiling this file from
D:\examples.I have given the following command for compiling:javac
HelloClient.java
The following was the error that I was getting -
HelloClient.java:20: cannot access examples.Hello
bad class file: D:\examples\Hello.class
illegal start of class file
Please remove or make sure it appears in the correct subdirectory of
the classpa
th.
Hello hello = home.create();
^
1 error
Intially I was confused, as to me the classpath seemed to be perfectly
correct.Still I tried changing classpath many times.But , still it was
of no use.
Then I realised that my HelloClient.java code was also containing the
code which was accessing HelloHome.class which was also in same
location as Hello.class.And , I was not getting any error for this
class.So , I recompiled my Hello.java to again create Hello.class(and
deleted the previous Hello.clas) and it solved the problem.I suppose
my Hello.class got corrupted.I am not sure how.