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

时间:2019-04-19 16:03:55

标签: eclipse hibernate tomcat web

我正在尝试在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中使用了最新的jar版本

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

程序应该运行无误

2 个答案:

答案 0 :(得分:0)

似乎这里的版本不匹配,LIMITtomcat 9
卡塔琳娜州的依赖关系需要升级,例如

catalina 6.0.53

在Maven存储库中寻找<dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-catalina</artifactId> <version>9.0.19</version> </dependency> 会显示警告

  

注意:该工件已移至:

     

org.apache.tomcat»tomcat-catalina

答案 1 :(得分:0)

这是一个部署路径问题。 在“属性”->“部署程序集”->“添加(Java构建路径条目)-Maven依赖关系”中添加Maven依赖关系后,此问题已解决。