0

我尝试将各种帖子和教程中的 [我认为是] 示例的相关部分组合起来,以创建 Eclipse 项目,我可以在其中使用 Glassfish 的 appclient 调用已部署到 Glassfish 的无状态 bean 上的方法. 当我运行 appclient 时,我似乎无法通过“找不到类”错误。

为了使这项工作富有成效,我希望在组装具体步骤以使其发挥作用时获得一些帮助,以便其他人也可以从练习中受益——我一直在寻找几天来找到一组具体步骤对于这样的事情,并没有找到任何小,简洁和完整的东西。为了给予适当的承认,其中大部分内容改编自http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/

环境是:
- Eclipse Juno,SR2
- Glassfish 3.1.2
- JDK 1.7.0.21

(Apologies for the formatting; I couldn't get indentation to work the way I wanted)  

These are the steps I've followed (which don't work, and where I'm asking for help):  
1. Create an Eclipse EAR Project:  
  1a. New Project -> Java EE -> Enterprise Application Project  
  1b. Project name: AdderEAR  
2. Create an Eclipse EJB Project, and add it to EAR Project:  
  2a. New Project -> EJB -> EJB Project  
  2b. Project name: AdderEJB  
  2c. Add project to an EAR: AdderEAR  
    ** After this, there are 3 projects: AdderEAR, AdderEJB, and AdderEJBClient.  
3. EJB Project: Add "adder" package, and adder.adderBean class:  
  3a. AdderEJB -> New Package ("adder")  
  3b. AdderEJB -> adder -> New Session Bean:  
    3b1> Class name: AdderBean  
    3b2> State type: Stateless  
    3b3> No-interface View (selected)  
    3b4> Remote ("adder.AdderBeanRemote")  
    ** AdderEJB: adder.AdderBean.java file created  
    ** AdderEJBClient: adder.AdderBeanRemove.java file created  
4. Add "sum" method to AdderBeanRemove interface and AdderBean EJB  
5. Start glassfish server  
6. Deploy AdderEAR to glassfish:  
  6a. Right-click Glassfish server in Servers view  
  6b. Add and Remove...  
  6c. Select AdderEAR and add  
7. Create Adder appclient Project:  
  7a. New Project -> Java EE -> Application Client Project  
  7b. Project name: AdderAppClient  
  ** AdderAppClient: [default package].Main.java file created  
8. Edit Main.java to include EJB of type AdderBeanRemote as static field:  
9. Use Eclipse "Quick fix" to do the following:  
  9a. On error at @EJB: Fix project setup -> Add archive 'javax.ejb.jar'  
  9b. On error at static field: fix project setup -> Add project 'AdderEJBClient' to build path...  
10. Add a couple println's to main() in Main.java, including invocation of adderBean.sum()  
** No errors detected by Eclipse at this point; all files saved  
11. Export app client jar:  
  11a. AdderAppClient -> Export -> App Client Jar File to ~/tmp/AdderAppClient.jar  
12. Run appclient using acc-sum.xml of same domain where eclipse deployed the EAR:  
  12a. cd ~/tmp  
  12b. appclient -xml ~/personal_domain/config/sun-acc.xml -jar AdderAppClient.jar  


这是发生错误的地方:

    $ cd ~/tmp
    $ ls
    AdderAppClient.jar
    $ appclient -xml ~/personal_domain/config/sun-acc.xml -jar AdderAppClient.jar 
    Jun 17, 2013 2:52:04 PM org.glassfish.apf.impl.DefaultErrorHandler error
    SEVERE: Class [ Ladder/AdderBeanRemote; ] not found. Error while loading [ class Main ]
    In AdderAppClient:main()
    Exception in thread "main" java.lang.NoClassDefFoundError: adder/AdderBeanRemote
            at Main.main(Main.java:12)
    Caused by: java.lang.ClassNotFoundException: adder.AdderBeanRemote
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at org.glassfish.appclient.client.acc.ACCClassLoader.findClass(ACCClassLoader.java:212)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
            ... 1 more
    $


以下是eclipse的相关文件:

    // Main.java: -------------------------------------------------------

    import javax.ejb.EJB;
    import adder.AdderBeanRemote;

    public class Main
    {
      @EJB
      public static AdderBeanRemote adderBean;

      public static void main(final String[] args)
      {
        System.out.println("In AdderAppClient:main()");
        System.out.println("Sum of 3 and 4 is " + adderBean.sum(3, 4));
      }

      public Main()
      {
        super();
      }
    }

    // AdderBeanRemote.java: ----------------------------------------------

    package adder;

    import javax.ejb.Remote;

    @Remote
    public interface AdderBeanRemote
    {
      public int sum(int a, int b);
    }

    // AdderBean.java:  ---------------------------------------------------

    package adder;

    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;

    @Stateless
    @LocalBean
    public class AdderBean
        implements AdderBeanRemote
    {
      public AdderBean()
      {
      }

      @Override
      public int sum(final int a, final int b)
      {
        return a + b;
      }
    }


这是我第一次尝试在 eclipse 和 glassfish 的 appclient 中使用 EJB,所以我怀疑我的错误是非常基本的,并且由于缺乏熟悉,我错过了一些基本的东西。任何指针将不胜感激。

4

0 回答 0