Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1517
  • Last Modified:

Cannot Find Symbol Class

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

0
monica73174
Asked:
monica73174
  • 12
  • 8
  • 3
  • +1
1 Solution
 
objectsCommented:
how are you compiling?  Is the parent directory or the com directory oin your classpath?

0
 
ksivananthCommented:
use some free available editors like eclipse, netbeans...
0
 
CEHJCommented:
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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
objectsCommented:
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

0
 
monica73174Author 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.
0
 
CEHJCommented:
You need to put the j2ee jars in the classpath. Did you download the j2ee edition?
0
 
monica73174Author 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.  
0
 
monica73174Author Commented:
Oh one more thing, I am using JBoss
0
 
CEHJCommented:
If you're using JBoss, the j2ee jars will already be in the JBoss tree, so you can put them in the classpath
0
 
objectsCommented:
>  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

0
 
monica73174Author Commented:
That still gives me the same five errors.  I added the j2ee.jar to the classpath also.  I
0
 
objectsCommented:
what command are you now using?

0
 
monica73174Author 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
0
 
monica73174Author Commented:
I used this one javac -classpath "/java;%CLASSPATH%" AdderHome.java
0
 
monica73174Author Commented:
This one gives the errors as well.  javac -classpath /java;C:/jboss/lib/j2ee.jar AdderHome.java
0
 
objectsCommented:
try these:

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

javac -classpath /java;"%CLASSPATH%" AdderHome.java
0
 
monica73174Author 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
0
 
objectsCommented:
:)  with which one?

0
 
objectsCommented:
should be:

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

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

0
 
monica73174Author Commented:
actually both gave the same error.  
0
 
monica73174Author Commented:
I think it just compiled.  =)  Let me check.  I will be so happy if this works.  
0
 
monica73174Author Commented:
It works! It works!  Thank you sooo much!
0
 
objectsCommented:
no worries, glad I could help :)

0
 
monica73174Author Commented:
I would give you 1000 points if I could.  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 12
  • 8
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now