Glassfish 原因:java.lang.ClassCastException包装无法强制转换为

Glassfish 原因:java.lang.ClassCastException包装无法强制转换为,glassfish,javafx,jndi,lookup,ejb-3.1,Glassfish,Javafx,Jndi,Lookup,Ejb 3.1,我试图在glassfish 3.1容器上运行远程EJB,并使用Javafax 2.2客户端,在“查找”远程EJB时抛出一个exeption。 我的应用程序的目的是获取/放置Javafx客户端对象,这些对象在服务器端保存/检索为XML文件 在服务器端EJB被打包到EAR中 控制器“scriber\u S\u controller”是无状态会话EJB package scrubber_S_Controller; import java.io.Serializable; import javax.

我试图在glassfish 3.1容器上运行远程EJB,并使用Javafax 2.2客户端,在“查找”远程EJB时抛出一个exeption。 我的应用程序的目的是获取/放置Javafx客户端对象,这些对象在服务器端保存/检索为XML文件

在服务器端EJB被打包到EAR中

控制器“scriber\u S\u controller”是无状态会话EJB

package scrubber_S_Controller;

import java.io.Serializable;

import javax.ejb.Stateless;
import javax.xml.bind.JAXBException;
import scrubber_S_Model.SimpleObject;

/**
 * Session Bean implementation class Session
 */
@Stateless
public class Session implements SessionRemote, Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -5718452084852474986L;

    /**
     * Default constructor. 
     */
    public Session() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public SimpleObject getSimpleObject() throws JAXBException {
        SimpleObject simpleobjet = new SimpleObject();
        return simpleobjet.retrieveSimpleObject();
    }

    @Override
    public void setSimpleObject(SimpleObject simpleobject) throws JAXBException {
        simpleobject.saveSimpleObject(simpleobject);

    }

}
使用的远程接口是

package scrubber_S_Controller;

import javax.ejb.Remote;
import javax.xml.bind.JAXBException;

import scrubber_S_Model.SimpleObject;

@Remote
public interface SessionRemote {
    public SimpleObject getSimpleObject() throws JAXBException;
    public void setSimpleObject(SimpleObject simpleobject) throws JAXBException;

}
SimpleObject在洗涤器模型包中进行管理:

package scrubber_S_Model;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement(name = "SimpleObject")
public class SimpleObject implements java.io.Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 306212289216139111L;

    /**
     * Used to define a simpleObject Value Object
     */
    @XmlElement(name = "scrubberValveValue")
    private int scrubberValveValue;

    @XmlElement(name = "bypassValveValue")
    private int bypassValveValue;

    @XmlElement(name = "exhaustState")
    private boolean exhaustState;

    @XmlElement(name = "layoutColor")
    private String layoutColor;

    @XmlElement(name = "textValue")
    private String textValue;

    @XmlElement(name = "textColor")
    private String textColor;

    @XmlElement(name = "pressureThreshold")
    private int pressureThreshold;

    public SimpleObject(int bypassvalvevalue, int scrubbervalvevalue,
            boolean exhauststate, String layoutcolor, String textvalue,
            String textcolor, int pressurethreshold) {

        this.bypassValveValue = bypassvalvevalue;
        this.scrubberValveValue = scrubbervalvevalue;
        this.exhaustState = exhauststate;
        this.layoutColor = layoutcolor;
        this.textValue = textvalue;
        this.textColor = textcolor;
        this.pressureThreshold = pressurethreshold;
    }

    /**
     * Empty constructor, just to enable JAXB.
     */
    public SimpleObject() {
    }

    /**
     * Gets the value of the scrubberValveValue property.
     * 
     */
    public int getScrubberValveValue() {
        return this.scrubberValveValue;
    }

    /**
     * Sets the value of the scrubberValveValue property.
     * 
     */
    public void setScrubberValveValue(int value) {
        this.scrubberValveValue = value;
    }

    /**
     * Gets the value of the bypassValveValue property.
     * 
     */

    public int getBypassValveValue() {
        return this.bypassValveValue;
    }

    /**
     * Sets the value of the bypassValveValue property.
     * 
     */
    public void setBypassValveValue(int value) {
        this.bypassValveValue = value;
    }

    /**
     * Gets the value of the exhaustState property.
     * 
     */

    public boolean isExhaustState() {
        return this.exhaustState;
    }

    /**
     * Sets the value of the exhaustState property.
     * 
     */
    public void setExhaustState(boolean value) {
        this.exhaustState = value;
    }

    /**
     * Gets the value of the layoutColor property.
     * 
     * @return possible object is {@link String }
     * 
     */
    public String getLayoutColor() {
        return this.layoutColor;
    }

    /**
     * Sets the value of the layoutColor property.
     * 
     * @param value
     *            allowed object is {@link String }
     * 
     */
    public void setLayoutColor(String value) {
        this.layoutColor = value;
    }

    /**
     * Gets the value of the textValue property.
     * 
     * @return possible object is {@link String }
     * 
     */

    public String getTextValue() {
        return this.textValue;
    }

    /**
     * Sets the value of the textValue property.
     * 
     * @param value
     *            allowed object is {@link String }
     * 
     */
    public void setTextValue(String value) {
        this.textValue = value;
    }

    /**
     * Gets the value of the textColor property.
     * 
     * @return possible object is {@link String }
     * 
     */

    public String getTextColor() {
        return this.textColor;
    }

    /**
     * Sets the value of the textColor property.
     * 
     * @param value
     *            allowed object is {@link String }
     * 
     */
    public void setTextColor(String value) {
        this.textColor = value;
    }

    /**
     * Gets the value of the pressureThreshold property.
     * 
     */

    public int getPressureThreshold() {
        return this.pressureThreshold;
    }

    /**
     * Sets the value of the pressureThreshold property.
     * 
     */
    public void setPressureThreshold(int value) {
        this.pressureThreshold = value;
    }


public void saveSimpleObject(SimpleObject simpleobjet) throws JAXBException {
        FileOutputStream fileout = null;
        JAXBContext jc = JAXBContext.newInstance(SimpleObject.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        try {
            fileout = new FileOutputStream("simpleobjectfile.xml");
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        marshaller.marshal(simpleobjet, fileout);
        try {
            fileout.flush();
            fileout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

public SimpleObject retrieveSimpleObject() throws JAXBException {
        FileInputStream fileinput = null;
        JAXBContext jc = JAXBContext.newInstance(SimpleObject.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        try {
            fileinput = new FileInputStream("simpleobjectfile.xml");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } 
        SimpleObject simpleobjet = (SimpleObject)unmarshaller.unmarshal(fileinput);
        try {
            fileinput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return simpleobjet;

    }

}
编组/解编组的Junit测试工作正常

EJB的部署提供了以下JNDI命名:

    INFO: EJB5181:Portable JNDI names for EJB Session: [java:global/Scrubber_S_EAR/Scrubber_S/Session, java:global/Scrubber_S_EAR/Scrubber_S/Session!scrubber_S_Controller.SessionRemote]
INFO: CORE10010: Loading application Scrubber_S_EAR done in 4 406 ms
在客户端,Javafx应用程序如下所示:

package ScrubberView;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.bind.JAXBException;
import scrubber_CView_Model.SimpleObject;
import session.SessionRemote;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class scrubberView extends Application {

    @Override
    public void start(Stage primaryStage) throws JAXBException {
        try {
            Properties propriétés = new Properties();
            propriétés.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
            Context ctx = new InitialContext(propriétés);
            SessionRemote mySession = (SessionRemote)ctx.lookup("java:global/Scrubber_S_EAR/Scrubber_S/Session");
            //Create an object to exchange 
            SimpleObject simpleObject = new SimpleObject(1, 2, true, "layoutcolor", "text", "textcolor", 10 );
            mySession.setSimpleObject(simpleObject);
            @SuppressWarnings("unused")
            SimpleObject simpleObject2 = new SimpleObject();
            simpleObject2  = mySession.getSimpleObject();           
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            System.out.println(e.toString()   );
            e.printStackTrace();
        }

        //compose the scrubberview scene and show it
        primaryStage.setTitle("scrubberView");
        BorderPane borderpane = new BorderPane();
        Scene scene = new Scene(borderpane, 350, 80, Color.GREY);
        primaryStage.setScene(scene);
        scene.getStylesheets().add("./CleanRoomControl.css");
        primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}
以下jar位于应用程序的buid enc中

C:\glassfish3\glassfish\modules\auto-depends.jar
C:\glassfish3\glassfish\modules\common-util.jar
C:\glassfish3\glassfish\modules\config-api.jar
C:\glassfish3\glassfish\modules\config-types.jar
C:\glassfish3\glassfish\modules\config.jar
C:\glassfish3\glassfish\modules\deployment-common.jar
C:\glassfish3\glassfish\modules\dol.jar
C:\glassfish3\glassfish\modules\ejb-container.jar
C:\glassfish3\glassfish\modules\ejb.security.jar
C:\glassfish3\glassfish\modules\glassfish-api.jar
C:\glassfish3\glassfish\modules\glassfish-corba-asm.jar
C:\glassfish3\glassfish\modules\glassfish-corba-codegen.jar
C:\glassfish3\glassfish\modules\glassfish-corba-csiv2-idl.jar
C:\glassfish3\glassfish\modules\glassfish-corba-newtimer.jar
C:\glassfish3\glassfish\modules\glassfish-corba-omgapi.jar
C:\glassfish3\glassfish\modules\glassfish-corba-orb.jar
C:\glassfish3\glassfish\modules\glassfish-corba-orbgeneric.jar
C:\glassfish3\glassfish\modules\glassfish-naming.jar
C:\glassfish3\glassfish\modules\gmbal.jar
C:\glassfish3\glassfish\modules\hk2-core.jar
C:\glassfish3\glassfish\modules\internal-api.jar
C:\glassfish3\glassfish\modules\javax.ejb.jar
C:\glassfish3\glassfish\modules\kernel.jar
C:\glassfish3\glassfish\modules\management-api.jar
C:\glassfish3\glassfish\modules\orb-connector.jar
C:\glassfish3\glassfish\modules\orb-iiop.jar
C:\glassfish3\glassfish\modules\security.jar
C:\glassfish3\glassfish\modules\transaction-internal-api.jar
在运行

SessionRemote mySession = (SessionRemote)ctx.lookup("java:global/Scrubber_S_EAR/Scrubber_S/Session"); 
第行,它提出了以下例外:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassCastException: scrubber_S_Controller._SessionRemote_Wrapper cannot be cast to session.SessionRemote
    at ScrubberView.scrubberView.start(scrubberView.java:27)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
    ... 1 more
如果我尝试使用其他命名:

SessionRemote mySession = (SessionRemote)ctx.lookup("java:global/Scrubber_S_EAR/Scrubber_S/Session!scrubber_S_Controller.SessionRemote");
它提出了同样的解释

如果有人能帮我解决这个问题,那就太好了

非常感谢你的帮助


我希望我的英语水平不会太差。

我用以下方法解决了这个问题:

  • 从env中删除jar文件,只将gf-client.jar放在类路径中,如

  • 将“scriber\u S\u controller”重命名为“session”(作为客户端中的相应包)

  • 从“SimpleObject”类中删除“retrieveSimpleObject()”和“saveSimpleObject(SimpleObject SimpleObject)”并将其添加到新的“SimpleObject持久化类”
  • 使用“SimpleObject持久化”保存和检索SimpleObject
啊!在这之后,它运行良好