【问题标题】:Deploying the Restlet web project from Intelij to apache tomcat?将 Restlet Web 项目从 Intellij 部署到 apache tomcat?
【发布时间】:2015-02-28 06:12:27
【问题描述】:

我有一个 JAVA-EE 项目,它在我的 Intellij 13.1.4 中使用“restlet-2.2”框架。

我想将此项目部署到 apache tomcat 服务器,但我遇到了一些问题。

项目结构

1.我有一些 JAVA 类,它们基本上是不同的 Web 服务。所有这些类都扩展了 ServerResource 类。这些类内部有 @Get 方法,它们将响应客户端请求。

2.然后我有一个扩展 Application 类的类 MyServer 并且在 MyServer 中我有一个 Router 类对象,它基本上将请求路由到适当的 Web 服务,具体取决于URI。

3.web.xml - Intellij 默认创建一个带有 version="3.1" 的 web.xml 并在其中添加 nothing。所以我修改了那个web.xml(在下面添加web.xml)

我已经完成了工件配置,并且在我的“战争爆发”中我有以下结构

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

当我把这个爆炸的战争放在我的 apache tomcat webapps 文件夹中并重新启动 tomcat 时,我就可以访问 html/css/js 文件了。但是我的 AJAX 调用总是给出 ERROR 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&param2=y

【问题讨论】:

    标签: xml tomcat restlet intellij-13


    【解决方案1】:

    您可以参考这里: https://vatsalad.wordpress.com/2010/01/13/how-to-setup-a-servlet-based-restlet-webservice/

    但是,我认为您为什么不将 restlet 项目部署为窗口服务而不是 Web 应用程序? 因为,无论如何,Web 应用程序都必须运行在一个 Web 服务平台,即 tomcat 中。真的,当你运行 restlet 应用程序时,它也像 tomcat 一样。它将侦听来自您在代码中设置的特定端口的请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      相关资源
      最近更新 更多