简体   繁体   English

Java 中的 Rest 服务从 Tomcat 服务器运行,但不在 Z32F72220261946F303EZEZ8787 内

[英]Rest service in Java runs from Tomcat server but not inside Eclipse

I am unable to find another article that solves my problem but am happy to hear about one if you know the answer.我找不到另一篇可以解决我的问题的文章,但如果您知道答案,我很高兴听到一篇文章。

I have a RESTful service built in Java with Eclipse.我有一个内置于 Java 和 Eclipse 的 RESTful 服务。 It uses Spring and all of its bells and whistles.它使用 Spring 及其所有的花里胡哨。

After much work with configuration files, I am able to build the service into a war file, deploy it to my Tomcat webapps folder, and run it from standalone Tomcat.在对配置文件进行大量工作之后,我能够将服务构建到一个 war 文件中,将其部署到我的 Tomcat webapps 文件夹,然后从独立的 Tomcat 运行它。 However, it still throws several errors on start when I try to start it from a service defined within Eclipse.但是,当我尝试从 Eclipse 中定义的服务启动它时,它仍然会在启动时引发几个错误。 The errors are the same errors that I was seeing before I got the config files correct for standalone Tomcat.这些错误与我在为独立 Tomcat 获得正确的配置文件之前看到的错误相同。 The errors are about the inability to create the required beans because of references to properties that can't be found.这些错误是由于对无法找到的属性的引用而无法创建所需的 bean。

How did I get it running in Tomcat?我是如何让它在 Tomcat 中运行的? I added a couple of.properties files to define properties needed by the beans that get launched at startup and then added a 'set CLASSPATH=...' line to the setenv.bat file in the Tomcat bin folder.我添加了几个 .properties 文件来定义启动时启动的 bean 所需的属性,然后在 Tomcat bin 文件夹中的 setenv.bat 文件中添加了“set CLASSPATH=...”行。 This new line adds the properties files into the CLASSPATH.这一新行将属性文件添加到 CLASSPATH 中。 That seems to have fixed everything from standalone Tomcat.这似乎已经解决了独立 Tomcat 的所有问题。

So, my question is, "How do I make these same changes inside my Eclipse server?"所以,我的问题是,“如何在我的 Eclipse 服务器中进行这些相同的更改?” I have added the properties folder with the property files under the config folder in Eclipse, just like it is in my native Tomcat folders, but I do not know how to modify the CLASSPATH string to specifically point to my.properties files (as I have done in the setenv.bat file for standalone Tomcat).我已经在 Eclipse 的 config 文件夹下添加了 properties 文件夹和属性文件,就像在我的原生 Tomcat 文件夹中一样,但我不知道如何修改 CLASSPATH 字符串以专门指向 my.properties 文件(因为我有在独立 Tomcat 的 setenv.bat 文件中完成)。

I think I understand the problem, but have no idea about the solution.我想我理解这个问题,但不知道解决方案。

Thanks for listening.谢谢收听。

Dave戴夫

Eclipse does not use any *.sh/*.bat files to startup Tomcat. Eclipse 不使用任何*.sh/*.bat文件来启动 Tomcat。 In order to modify the way the server is started you have to open the configuration UI of the server by double-clicking on the server in the Servers view.为了修改服务器的启动方式,您必须通过双击服务器视图中的服务器来打开服务器的配置 UI。

From there you will be able to modify the classpath of the system classloader through "Open launch configuration" .从那里您将能够通过"Open launch configuration"修改系统类加载器的类路径。

Another important setting is "Server path" which tells Eclipse, the value of $CATALINA_BASE .另一个重要的设置是“服务器路径” ,它告诉 Eclipse, $CATALINA_BASE的值。 You can modify it only after removing all modules and cleaning the server.只有在移除所有模块并清理服务器后才能对其进行修改。 It is useful to set it to an easily accessible directory: this way you can verify directly that Eclipse didn't mess up your application deployment (sometimes it "forgets" to copy some libraries).将其设置为易于访问的目录很有用:这样您可以直接验证 Eclipse 没有弄乱您的应用程序部署(有时它“忘记”复制一些库)。

The "Configuration path" setting tells Eclipse where to find the files (but not subdirectories) that will be copied into $CATALINA_BASE/conf . “配置路径”设置告诉 Eclipse 在哪里可以找到将被复制到$CATALINA_BASE/conf的文件(但不是子目录)。

Remark : if your application requires you to add libraries to the top classloader, there is probably a problem in your project.备注:如果您的应用程序需要您将库添加到顶级类加载器,那么您的项目中可能存在问题。 The "missing" libraries should be added to WEB-INF/lib of your application instead: look into the "Deployment assembly" of your Eclipse project configuration.应该将“缺失”库添加到应用程序的WEB-INF/lib中:查看 Eclipse 项目配置的“部署程序集”

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

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