简体   繁体   English

Tomcat:为基于Jersey的Rest Service获取简短URL

[英]Tomcat: Get short URL for Jersey based Rest Service

I have a Jersey based Rest service running on a tomcat server. 我在雄猫服务器上运行了基于Jersey的Rest服务。 There is no UI, just a server that offers some rest services. 没有用户界面,只有提供一些休息服务的服务器。 Now, to access this service the URL that i have to type in is pretty long. 现在,要访问此服务,我必须输入的URL很长。 Something like localhost:8080/MyApp/url_pattern/classPath/method where MyApp is the webapp that i deployed, url_pattern is the pattern that i defined in the servlet-mapping in web.xml, classPath and method being the @Path annotations for the Class and method respectively. localhost:8080/MyApp/url_pattern/classPath/method ,其中MyApp是我部署的Webapp,url_pattern是我在web.xml的servlet映射中定义的模式,classPath和method是Class的@Path注释和方法。 Is it possible to shorten it such that I get rid of the MyApp and url_pattern part of this URL. 是否可以将其缩短,以使我摆脱该URL的MyApp和url_pattern部分。 Something like localhost:8080/classPath/method . 类似于localhost:8080/classPath/method

PS: There is just one webApp running on this server, so no point having the MyApp part PS:此服务器上仅运行一个webApp,因此没有MyApp部分的意义

I don't think you can remove all what you desire from the url but you can definitely remove the MyApp part by making it the root application for tomcat. 我认为您无法从url中删除所有您想要的内容,但是您绝对可以通过将MyApp部分设置为tomcat的根应用程序来删除它。

Answer on this related link describes it pretty well, how to set your application as the root application. 这个相关链接的答案很好地描述了如何将您的应用程序设置为根应用程序。 So you can access your REST services without having the app name in url: 因此,您无需使用url中的应用程序名称即可访问REST服务:

Setting default application in tomcat 7 在tomcat 7中设置默认应用程序

Content copied from the above link: 从以上链接复制的内容:

First Method : 第一种方法

first shutdown your tomcat [from the bin directory (sh shutdown.sh)] then you must delete all the content of your tomcat webapps folder (rm -fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)] 首先从[bin目录(sh shutdown.sh)]关闭您的tomcat,然后必须删除tomcat webapps文件夹的所有内容(rm -fr *),然后将WAR文件重命名为ROOT。war最后从[从bin目录(sh startup.sh)]

Second Method : 第二种方法

leave your war file in CATALINA_BASE/webapps, under its original name - turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. 将您的war文件以其原始名称保留在CATALINA_BASE / webapps中-在server.xml文件的Host元素中关闭autoDeploy和deployOnStartup。 explicitly define all application Contexts in server.xml, specifying both path and docBase. 在server.xml中显式定义所有应用程序上下文,同时指定path和docBase。 You must do this, because you have disabled all the Tomcat auto-deploy mechanisms, and Tomcat will not deploy your applications anymore unless it finds their Context in the server.xml. 您必须这样做,因为您已禁用了所有Tomcat自动部署机制,并且Tomcat将不再部署您的应用程序,除非它在server.xml中找到了它们的上下文。

Note: 注意:

that this last method also implies that in order to make any change to any application, you will have to stop and restart Tomcat. 最后一种方法还意味着,为了对任何应用程序进行任何更改,您都必须停止并重新启动Tomcat。

Third Method : 第三种方法

Place your war file outside of CATALINA_BASE/webapps (it must be outside to prevent double deployment). 将您的war文件放置在CATALINA_BASE / webapps之外(该文件必须在外部以防止重复部署)。 - Place a context file named ROOT.xml in CATALINA_BASE/conf//. -在CATALINA_BASE / conf //中放置一个名为ROOT.xml的上下文文件。 The single element in this context file MUST have a docBase attribute pointing to the location of your war file. 此上下文文件中的单个元素必须具有docBase属性,该属性指向您的war文件的位置。 The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. 不应设置path元素-它是从.xml文件的名称派生的,在本例中为ROOT.xml。 See the Context Container above for details. 有关详细信息,请参见上面的上下文容器。

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

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