gpt4 book ai didi

java - 如果未提供范围,为什么 Glassfish 不会启动失败但 Tomcat 会启动?

转载 作者:行者123 更新时间:2023-11-28 22:13:27 24 4
gpt4 key购买 nike

我有一个非常简单的 Java Web 应用程序,其中包含 2 个 jsp 文件(索引和测试)。部署描述符应该提供一些线索:

<web-app... usual stuff here...>

<servlet>
<servlet-name>BeerServlet</servlet-name>
<servlet-class>com.tugay.example.BeerServlet</servlet-class>

</servlet>

<servlet-mapping>
<servlet-name>BeerServlet</servlet-name>
<url-pattern>/tugay</url-pattern>
</servlet-mapping>

</web-app>

这个项目是由 maven -webapp archetype 创建的,pom 中只有一个依赖:

    <dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>

我在 IntelliJ 中有 2 个运行配置,一个用于 Tomcat 7.0,一个用于 Glassfish 3.1.2.2

当 pom 如上所述时,应用程序可以很好地部署到两台服务器。但是当我删除时:

<scope>provided</scope>

部署在 Tomcat 中失败,但在 Glassfish 中仍然成功。这是为什么?

这是来自 Tomcat 日志文件:

SEVERE: Error configuring application listener of class org.apache.catalina.deploy.ApplicationListener@49f8d077 java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4854) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1551) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:762) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:762) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1454) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:818) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) Oct 20, 2013 1:03:08 AM org.apache.catalina.core.StandardContext listenerStart SEVERE: Skipped installing application listeners due to previous error(s)

最佳答案

<scope>provided</scope>在maven中用于告诉这个库(javaee-api)将由服务器提供。省略时,默认为 <scope>compile</scope>意味着所需的 jar 在编译期间可用,并与 WAR 文件一起打包在 lib 中文件夹。 javaee-api包中包含javax.servlet、javax.servlet.http ..等,也是Tomcat提供的。所以当你省略范围时,jar 被打包在 WAR 文件中,但是这个 jar 也是由 tomcat 提供的,所以存在 jar 冲突。Glassfish 能够解决这个问题。

关于java - 如果未提供范围,为什么 Glassfish 不会启动失败但 Tomcat 会启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com