我有一个 JAVA-EE 项目,它在我的 Intellij 13.1.4 中使用“reSTLet-2.2”框架。
我想将此项目部署到 apache tomcat 服务器,但我遇到了一些问题。
项目结构
1.我有一些 JAVA 类,它们基本上是不同的 Web 服务。所有这些类都扩展了 ServerResource 类。这些类内部有 @Get 方法,可以响应客户端请求。
2.然后我有一个类 MyServer 扩展了 Application 类,在 MyServer 中我有一个 Router 类对象,它基本上将请求路由到适当的网络服务,具体取决于URI。
3.web.xml - 默认情况下,Intellij 创建一个 version="3.1"的 web.xml 并向其中添加任何内容。所以我修改了那个 web.xml(添加下面的 web.xml)
我已经完成了工件配置,在我的“ war 爆炸”中我有以下结构
WEB-INF
--classes
-----| All compiled class files
--lib
-----| restlet jar files and json jar files (org.json.jar org.restlet.jar org.restlet.ext.json.jar org.restlet.ext.servlet.jar)
--web.xml
当我将这个爆炸性的 war 放入我的 apache tomcat webapps 文件夹并重新启动 tomcat 时,我就可以访问 html/css/js 文件。但是我的 AJAX 调用总是给出错误 404。我已经尝试了 stackoverflow 和其他网站的所有解决方案,但没有任何帮助。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Application class name -->
<context-param>
<param-name>org.restlet.application</param-name>
<param-value>
MyServer
</param-value>
</context-param>
<!-- Restlet adapter -->
<servlet>
<servlet-name>ServerServlet</servlet-name>
<servlet-class>
org.restlet.ext.servlet.ServerServlet
</servlet-class>
</servlet>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>ServerServlet</servlet-name>
<url-pattern>/Projects/*</url-pattern>
</servlet-mapping>
</web-app>
MyServer 类
Router classpublic class MyServer extends Application{
public static void main(String []args)
{
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8080);
Application application = new MyServer();
// Attach the application to the component and start it
component.getDefaultHost().attach(application);
try {
component.start();
} catch (Exception e) {
e.printStackTrace();
}
}
//Method for attaching the URIs for web services
public synchronized Restlet createInboundRoot()
{
Router router = new Router(getContext());
//System.out.println("In router");
//Attaching URIsl
router.attach("/Projects/{projectID}/Enclosures/{enclID}/getStructure", StructureCalculations.class);
}
}
我的 AJAX 调用 URI 如下所示
http://localhost:8080/Projects/p1/Enclosures/e1/getStructure?param1=x¶m2=y
最佳答案
你可以引用这里: https://vatsalad.wordpress.com/2010/01/13/how-to-setup-a-servlet-based-restlet-webservice/
但是,我认为您为什么不将您的 reSTLet 项目部署为窗口服务而不是 Web 应用程序? 因为,无论如何,Web 应用程序都必须在 tomcat 的 Web 服务平台上运行。真的,当你运行 reSTLet 应用程序时,它也像 tomcat 一样。它将监听来自您在代码中设置的特定端口的请求。
关于xml - 将 ReSTLet web 项目从 Intellij 部署到 apache tomcat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27733243/