从ant切换到maven后无法在tomcat上部署

时间:2019-02-21 15:24:18

标签: java hibernate maven tomcat8

我有一个从ant迁移到maven的项目。
这是一个tomcat应用程序。
但是,如果我现在使用maven编译war文件,则在启动war文件之后会出现异常。

  

javax.naming.NameNotFoundException:名称[comp / env]在此上下文中未绑定。找不到[comp]。       在org.apache.naming.NamingContext.lookup(NamingContext.java:817)       在org.apache.naming.NamingContext.lookup(NamingContext.java:173)       在org.apache.catalina.deploy.NamingResourcesImpl.cleanUp(NamingResourcesImpl.java:994)       在org.apache.catalina.deploy.NamingResourcesImpl.stopInternal(NamingResourcesImpl.java:976)       在org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)       在org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5476)       在org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)       在org.apache.catalina.manager.ManagerServlet.undeploy(ManagerServlet.java:1456)       在org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:373)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:635)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:742)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)       在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)       在org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)       在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:613)       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)       在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)       在org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)       在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)       在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)       在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)       在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:800)       在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1463)       在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)       在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)       在java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:628)       在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)       在java.base / java.lang.Thread.run(Thread.java:834)

当我使用ant进行编译时,应用程序启动就没有问题。

这是我的context.xml

<?xml version="1.0" encoding="UTF-8"?>
    <Context antiJARLocking="true" path="/AppControlServer">
    <Resource name="jdbc/App" auth="Container"
    type="javax.sql.DataSource" maxActive="50" maxIdle="10" maxWait="4000"
    username="App" password="App"
    driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://localhost:5432/App"/>
</Context>

应用程序正在使用休眠模式,这是我的hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.connection.datasource">java:comp/env/jdbc/App</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="hibernate.current_session_context_class">managed</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.show_sql">false</property>
        <! -- entity mapping -->
    </session-factory>
</hibernate-configuration>

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

好吧,如果您仅更改了构建平台,则比较两个war文件,看看有什么变化。当您知道发生了什么变化时,更容易修复它。

基于类似的迁移,我的猜测是您在源文件夹(src/main/java)中有资源文件。 Maven不会从源文件夹复制文件,它们应该放在资源文件夹(src/main/resources)中。如果您移动文件,请务必保留目录结构!