简体   繁体   English

无法将类强制转换为同一类-在Glassfish服务器应用程序中重新启动后

[英]Class cannot be cast to the same class - after restart in Glassfish server application

I use Glassfish 2 and if I restart it, I have web applications that raise the following error: "Class package1.Model1 cannot be cast to package1.Model1". 我使用Glassfish 2,并且如果重新启动它,则我的Web应用程序会引发以下错误:“类package1.Model1无法转换为package1.Model1”。

Then, I have to deploy the applications again and they return to work. 然后,我必须再次部署应用程序,它们才能恢复工作。

How could I solve this problem? 我该如何解决这个问题?

A class is likely being loaded in multiple classloaders, creating two incompatible versions of that class. 一个类可能会在多个类加载器中加载,从而创建该类的两个不兼容版本。 But without any details of how the app is setup and deployed, I cannot say much more. 但是,如果没有有关如何设置和部署应用程序的任何详细信息,我不能说太多。

When is this error occurring exactly? 该错误何时准确发生? Also post more details of your setup. 还要发布您的设置的更多详细信息。

I had this issue with a WAR in an EAR, where the WAR and EAR both included the jar in question. 我在EAR中遇到WAR时遇到了这个问题,其中WAR和EAR都包含了相关的jar。 Posting in case someone else has this problem. 如果其他人有此问题,请发布。

Don't include your jars in your wars if you're already including them in your ear. 如果您已经将罐子放在耳朵里,请不要在战争中包括它们。

<build>
    <finalName>WebApp</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>


            <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>


                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM