运行动态Web项目tomcat时出现问题“只能导入一个类型。 org.hibernate.cfg.Configuration解析为一个包“

问题描述 投票:0回答:2

我试图在eclipse上迁移旧的Web项目(jsp / java)。创建了一个新的动态Web项目。复制相应文件夹中的所有代码,并将项目转换为Maven项目并添加所有必需的依赖项。解决了所有已编译的时间错误。当我通过eclipse在tomcat上运行项目时出现以下错误。

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: [18] in the generated java file: [/home/xxx/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/webadmin/org/apache/jsp/login_jsp.java]
Only a type can be imported. org.hibernate.cfg.Configuration resolves to a package 

Apr 19, 2019 2:21:03 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet [jsp] threw exception
java.lang.ClassNotFoundException: org.apache.jsp.login_jsp

问题看起来只与配置有关。尝试从pom文件中删除冲突,在hibernate.cfg的所有不同路径上尝试。在pom中使用了最新版本的罐子

前几行web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">

  <display-name>webapp</display-name>
   <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>

  </welcome-file-list>
  <filter>
    <filter-name>sessionfilter</filter-name>
    <filter-class> com.blossom.action.SessionFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sessionfilter</filter-name>
    <url-pattern>*.do</url-pattern>
  </filter-mapping>
  <servlet>
    <description></description>
    <display-name>album_insert</display-name>
    <servlet-name>album_insert</servlet-name>
    <servlet-class>com.xxx.action.album_insert</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>album_insert</servlet-name>
    <url-pattern>/album_insert</url-pattern>
  </servlet-mapping>

poi.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>webadmin</groupId>
  <artifactId>webadmin</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>



<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>catalina</artifactId>
    <version>6.0.53</version>
    <scope>provided</scope>
</dependency>
    <dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.9.3</version>
</dependency>

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.9</version>
</dependency>

<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>net.sf.ezmorph</groupId>
    <artifactId>ezmorph</artifactId>
    <version>1.0.6</version>
</dependency>


<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.11.2</version>
</dependency>


<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.1.0</version>
</dependency>


<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.4.2.Final</version>
</dependency>
<dependency>
    <groupId>com.servlets</groupId>
    <artifactId>cos</artifactId>
    <version>05Nov2002</version>
</dependency>
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3</version>    
</dependency>
  </dependencies>
</project>

构建路径

1. Tomcat 9.0
2. EAR Libary
3. JRE (java 8 oracle)
4. Maven dependencies
5. Web app libraries

该程序应该运行没有错误

eclipse hibernate tomcat web
2个回答
0
投票

似乎这里的版本不匹配,tomcat 9但是catalina 6.0.53。 Catalina的依赖需要升级,比如说

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-catalina</artifactId>
  <version>9.0.19</version>
</dependency>

在maven存储库中查找catalina 6.0.53会显示警告

注意:此工件已移至:

org.apache.tomcat»tomcat-catalina


0
投票

这是一个部署路径问题。在Properties-> Deployment Assembly - > Add(Java Build Path Entries)-Maven Dependencies中添加Maven依赖项之后,问题就解决了。

热门问题
推荐问题
最新问题