Unable to deploy .war application to GlassFish 3.1

2019-05-15 13:45发布

I have a .war application module, that can be successfully deployed without any exotic changes and server tuning. However, i was unable to deploy this app to GF 3.1.2: server throws following exception:

java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchFieldError: theInstance

What i am doing wrong? Has anyone suggest me something? Is there any additional settings that i should perform to deploy .war module successfully?

Thanks a lot in advance.

UPD

More precise log entry:

javax.xml.bind.JAXBException: Provider com.sun.xml.bind.ContextFactory_1_0_1 could not be instantiated: javax.xml.bind.JAXBException - with linked exception: [java.lang.NoSuchFieldError: theInstance]
- with linked exception: [javax.xml.bind.JAXBException - with linked exception: [java.lang.NoSuchFieldError: theInstance]]

4条回答
萌系小妹纸
2楼-- · 2019-05-15 14:02

Sounds like a class loader issue.

You need your WEB-INF/lib JAXB jars used ahead of the GlassFish JAXB jars. Or change your app to use the versions GlassFish 3.1.2 is bundled with.

Servlet spec says that web applications should use the local class loader before delegating to the parent. I think GlassFish delegates to the the parent class loader for web applications by default. Use <class-loader delegate="false"/> in web.xml or glassfish-web.xml.

Note there may be other ways to modify the class loader in GlassFish if this does not work.

This type of issue is common during deployment to many application servers. I've used GlassFish daily for the last 5+ years and see this every so often. Recently saw a similar issue when deploying to JBoss on CloudBees, and modified a deployment descriptor accordingly.

Googling "glassfish prefer web-inf/lib jars".

Response To psed comment below EJB interfaces must reside in the class path hierarchy shared by the Web module and EJB module. If you have an EJB interface jar in WEB-INF/lib and another copy of the EJB interface jar on the EJB module classpath, you would get a ClassCastException when injecting/locating the EJB in your web application. I assume WebServices have the same issue. Sharing the EJB interface jar though an EAR should resolve this issue though. Note there may be other issues I am unaware of

查看更多
看我几分像从前
3楼-- · 2019-05-15 14:03

You should not bundle JAXB jars with your application - Glassfish already has them, and it seems this is causing a conflict (incidentally, I've been digging through JAXB code recently, and theInstance is part of a static class defined by MarshallerImpl)

查看更多
干净又极端
4楼-- · 2019-05-15 14:15

This instruction is for GlassFish 3.1.2 The issue is runtime classes from JAXB 2.2.5 are not backward compilable with JAXB 1 code. This issue was fixed with JAXB 2.2.6, however, it's not in latest GlassFish release. So, either you wait until the next GlassFish upgrade or you do it manually.

Here is how i did, I removed the 2 bundle files from GlassFish module

C:\glassfish3\glassfish\modules\jaxb-osgi.jar
C:\glassfish3\glassfish\modules\endorsed\jaxb-api-osgi.jar

Clear the osgi-cache by deleting all the subfolder in

C:\glassfish3\glassfish\domains\domain1\osgi-cache

Download JAXB 2.2.6 from ORACLE JAXB

Extract the zip file to a temp location [C:\Java\jaxb-ri-2.2.6\jaxb-ri-2.2.6\osgi]

copy C:\Java\jaxb-ri-2.2.6\jaxb-ri-2.2.6\osgi\jaxb-osgi.jar to C:\glassfish3\glassfish\modules\

copy C:\Java\jaxb-ri-2.2.6\jaxb-ri-2.2.6\osgi\jaxb-api-osgi.jar to C:\glassfish3\glassfish\modules\endorsed\

restart your server ... i hope this will help. Good Luck

查看更多
萌系小妹纸
5楼-- · 2019-05-15 14:23

You should place your all jar files to your runtime server lib...

查看更多
登录 后发表回答