简体   繁体   English

Linux上的Tomcat 7无法在Grails 3 War文件中找到Java类

[英]Tomcat 7 on Linux Cannot Locate Java Class in Grails 3 War File

I have a grails 3 project, with java source code in the src/main/groovy/ folder (as specified here ). 我有一个Grails 3项目,在src /主/常规/文件夹的Java源代码(如指定此处 )。

The code works well in IntelliJ IDE and when deployed on Mac OS X El Capitan with a Tomcat 7 Server (tested with 7.0.73, 7.0.70, and 7.0.33, installed as specified here ) 该代码在IntelliJ IDE中运行良好,并且在带有Tomcat 7服务器的Mac OS X El Capitan上进行了部署(已按此处指定的方式进行了7.0.73、7.0.70和7.0.33的测试)

Server Details (Where the error happens) 服务器详细信息(发生错误的位置)

However on a Red Hat Linux Server the tomcat version command reports the following (though the startup default page lists version 7.0.33), 但是,在Red Hat Linux服务器上,tomcat version命令报告以下内容(尽管启动默认页面列出了7.0.33版),

Server version: Apache Tomcat/7.0.70
Server built:   Aug 5 2016 19:24:52 UTC
Server number:  7.0.70.0
OS Name:        Linux
OS Version:     2.6.32-642.6.2.el6.x86_64
Architecture:   amd64
JVM Version:    1.8.0_111-b14
JVM Vendor:     Oracle Corporation

the war file runs when put in the web app directory, but stalls on any page that uses a the java class in src/main/groovy with the following error (in the catalina.out log file), war文件放在Web应用程序目录中时运行,但是停滞在使用src / main / groovy中的java类的任何页面上,并且出现以下错误(在catalina.out日志文件中),

ERROR org.springframework.boot.context.web.ErrorPageFilter - Forwarding to error page from request [/url/] due to exception [Could not initialize class package_name.class_name]
java.lang.NoClassDefFoundError: Could not initialize class package_name.class_name

and occasionally gives this error (though seemed to stop after setting up LD_LIBRARY_PATH on Linux), 并偶尔出现此错误(尽管在Linux上设置LD_LIBRARY_PATH后似乎停止了),

ERROR org.springframework.boot.context.web.ErrorPageFilter - Forwarding to error page from request [/url] due to exception [no opencv_java310 in java.library.path]
java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path

Several things that do work, 起作用的几件事,

  • The code builds successfully to a war file 代码成功构建到war文件
  • When navigating to webapps/war_name/WEB-INF/classes/package_name/ the class file is there, AND can be run using (from the classes/ folder not package_name/) java package_name.class_name. 导航到webapps / war_name / WEB-INF / classes / package_name /时,存在类文件,并且可以使用java package_name.class_name(从classes /文件夹而不是package_name /)运行AND文件。

  • A test program that uses opencv runs successfully, on the server, so it seems the native libraries are correctly installed. 使用opencv的测试程序在服务器上成功运行,因此似乎正确安装了本机库。

  • The same war file works on Mac OS El Capitan with Tomcat versions 7.0.70, 7.0.73, 7.0.33, however it uses the bin shell scripts and not a service. 相同的war文件在Tomcat版本为7.0.70、7.0.73、7.0.33的Mac OS El Capitan上工作,但是它使用bin shell脚本而不是服务。

This is because tomcat does NOT respect the LD_LIBRARY_PATH setting on the Linux machine. 这是因为tomcat不遵守Linux计算机上的LD_LIBRARY_PATH设置。 So any test program run with java ... (including running java tomcat_dir/webapps/war_name/classes/File.class ) will work, but it still will break under tomcat and complain about failure to import the class. 因此,任何使用java ...运行的测试程序(包括运行java tomcat_dir / webapps / war_name / classes / File.class)都可以使用,但仍会在tomcat下崩溃并抱怨无法导入类。 The fix for this is to ignore LD_LIBRARY_PATH (or don't use Tomcat!, I wish), and symlink or copy the so file to one of the java.library.path paths. 解决此问题的方法是忽略LD_LIBRARY_PATH(或希望不使用Tomcat!),并将符号文件符号链接或复制到java.library.path路径之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM