We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Cannot Find Symbol Class

monica73174
monica73174 asked
on
Medium Priority
1,893 Views
Last Modified: 2013-11-23
I have three classes.   I keep getting a cannot find symbol class error.  All three of these files are in a package com.brainysoftware.ejb.  Why when I compile the AdderHome.java file do I get the error about the Adder class?
This is the file with the error.  It says Adder cannot be found
package com.brainysoftware.ejb;
 
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
 
public interface AdderHome extends EJBHome {
  Adder create() throws RemoteException, CreateException;
}
 
 
Here is the second file 
package com.brainysoftware.ejb;
 
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
 
public interface Adder extends EJBObject {
  public int add(int a, int b) throws RemoteException;
}
 
Here is the third file
package com.brainysoftware.ejb;
 
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
 
public class AdderBean implements SessionBean {
 
  public int add(int a, int b) {
    System.out.println("from AdderBean");
    return (a + b);
  }
 
  public void ejbCreate() {
  }
 
  public void ejbRemove() {
  }
 
  public void ejbActivate() {
  }
 
  public void ejbPassivate() {
  }
 
  public void setSessionContext(SessionContext sc) {
  }
}

Open in new window

Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
how are you compiling?  Is the parent directory or the com directory oin your classpath?

ksivananthVice President

Commented:
use some free available editors like eclipse, netbeans...
CERTIFIED EXPERT
Top Expert 2016

Commented:
You need to be doing something like the following
C:\Projects\Addition>set CLASSPATH=.
C:\Projects\Addition>javac com\brainysoftware\ejb\*.java

Open in new window

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
suggested that earlier, haven't got a reply yet how it went.
need to ensure that directory is on the classpath

though if you compile it from the parent directory of com then you can actually unset your classpath entirely which is preferable.

Understand that it is easier though to compile from same directory as the java files (less to type), and you don't want to have to wildcard, so just add the directory to the classpath (on the command line) gives you far more flexibility

eg. if your directory looks like /java/com/brainysoftware/.. you would use the following from your ejb directory:

javac -classpath /java AdderHome.java
 
nice and simple and will work with any classes under that package tree

let me know if you need any clarification

Author

Commented:
Hi,
Sorry I kind of posted this and went to bed.
I actually was compiliing it from textpad.  I was getting the one error about the Adder class not being found.  When I use javac -classpath /java AdderHome.java  I get five errors.  


c:\work\com\brainysoftware\ejb>javac -classpath /java AdderH
AdderHome.java:4: package javax.ejb does not exist
import javax.ejb.CreateException;
                ^
AdderHome.java:5: package javax.ejb does not exist
import javax.ejb.EJBHome;
                ^
AdderHome.java:7: cannot find symbol
symbol: class EJBHome
public interface AdderHome extends EJBHome {
                                   ^
AdderHome.java:8: cannot find symbol
symbol  : class Adder
location: interface com.brainysoftware.ejb.AdderHome
  Adder create() throws RemoteException, CreateException;
  ^
AdderHome.java:8: cannot find symbol
symbol  : class CreateException
location: interface com.brainysoftware.ejb.AdderHome
  Adder create() throws RemoteException, CreateException;
                                         ^
5 errors

I appologize because I am still pretty new.  I appreciate everyones help.
CERTIFIED EXPERT
Top Expert 2016

Commented:
You need to put the j2ee jars in the classpath. Did you download the j2ee edition?

Author

Commented:
I do not think I downloaded the J2EE edition.  So if I get the J2ee version this may solve the problem?  It is weird that I only get the single error when I complie it with textpad but if I complie in the command line I get five errors.  

Author

Commented:
Oh one more thing, I am using JBoss
CERTIFIED EXPERT
Top Expert 2016

Commented:
If you're using JBoss, the j2ee jars will already be in the JBoss tree, so you can put them in the classpath
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
>  When I use javac -classpath /java AdderHome.java  I get five errors.  

add the jar from your jboss install to the classpath

javac -classpath /java;/where/is/jboss/lib/j2ee.jar AdderHome.java

(change the above to correct location of jar)

or try this:

javac -classpath "/java;%CLASSPATH%" AdderHome.java

Author

Commented:
That still gives me the same five errors.  I added the j2ee.jar to the classpath also.  I
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
what command are you now using?

Author

Commented:
This is my classpath
C:\Tomcat 6.0\lib\servlet-api.jar;C:\Tomcat-6.0.16\lib\jsp-api.jar;C:\Tom
.16\lib\el-api.jar;C:\mysqlconnector\mysql-connector-java-5.1.7\mysql-con
java-5.1.7-bin;C:\Tomcat 6.0\lib\jsp-api.jar;C:\JBoss\lib\jboss-j2ee.jar

Author

Commented:
I used this one javac -classpath "/java;%CLASSPATH%" AdderHome.java

Author

Commented:
This one gives the errors as well.  javac -classpath /java;C:/jboss/lib/j2ee.jar AdderHome.java
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
try these:

javac -classpath /java;C:/jboss/lib/jboss-j2ee.jar AdderHome.java

javac -classpath /java;"%CLASSPATH%" AdderHome.java

Author

Commented:
That now gives me the original error I had.

C:\work\com\brainysoftware\ejb\AdderHome.java:8: cannot find symbol
symbol  : class Adder
location: interface com.brainysoftware.ejb.AdderHome
  Adder create() throws RemoteException, CreateException;
  ^
1 error
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
:)  with which one?

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
should be:

javac -classpath /work;C:/jboss/lib/jboss-j2ee.jar AdderHome.java

javac -classpath /work;"%CLASSPATH%" AdderHome.java

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
actually both gave the same error.  

Author

Commented:
I think it just compiled.  =)  Let me check.  I will be so happy if this works.  

Author

Commented:
It works! It works!  Thank you sooo much!
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
no worries, glad I could help :)

Author

Commented:
I would give you 1000 points if I could.  
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.