web应用,在tomcat下正常启动,部署到was下也正常启动,但是点击所有模块

web应用,在tomcat下正常启动,部署到was下也正常启动,但是点击所有模块,第1张

在eclipse中新建的Dynamic Web Project。写好代码后,选择Run on Server(当然Server配置为Tomcat),但是运行后我们发下在Tomcat的安装目录下并没有出现我们所建立的工程名字。很明显,项目并没有自动部署到Tomcat的Webapps中。

不信我们等eclipse中的tomcat启动以后。在eclipse内置的浏览器中输入http://localhost:8080/webDemo/loginjsp(其中webDemo为工程名字)。可以正常打开。但是我们在外部的浏览器上打开http://localhost:8080时确没有出现所期望的小猫画面。也就是说,toncat并没有正常启动。(经常我们都是在bin目录下点击startupbat后。在输入http://localhost:8080就可以看到期望的小猫了)

为了使我们的项目能像myelipse那样自动部署到webapps目录(可以使用插件,但是eclipse插件好像不怎么好用,反正我是不喜欢)。我们需要对我们所建立的tomcat Server做一些简单的修改。

1:将eclipse内的Tomcat服务器停止。Stop

2:删除之前run on server中的项目

3:在servers下面选择Tomcat服务器。右键点击后选择Open,出现如下提示:

修改Server Locations(默认是选择的第一个。如果没有进行1,2步操作时。该选项是灰色的无法编辑)

选择第二项(Use Tomcat installation(takes)

4:将下面的Deploy path 改成 webapps,默认是wptwebapps,上面的Server Path对应电脑上的Tomcat安装目录

5:保存设置。退出

6:点击web项目,Run as --> Run on Server--

这时。项目会自动部署到tomcat的webapps下面。启动后可以正常浏览。

注意此时tomcat--conf目录下得serverxml文件有改变(eclipse自动修改。注意修改的内容<Context >

在项目名上点击右键,选择“导出”;

在弹出来的对话框中,你可以直接搜索“WAR”或者一个一个查看,应该就在“Web”里面,选定“WAR file”,然后“下一步”;

在接下来的对话框里面,你可以指定要导出的是哪个webService工程和导出到哪个文件夹,还可以指定你要导出到哪个版本的tomcat上面,如下:

注意导出的文件是以"war"为文件后缀的;

然后把你导出的这个war文件拷贝到tomcat的安装目录下,直接把这个war文件放在webapps这个文件夹里面就可以了!

然后运行tomcat服务,可以命令行也可以通过service运行,具体看你的tomcat是怎么安装的;

通过浏览器访问“http://127001:8080/<你的webService项目名>”就可以了!

tomcat运行过程中会自动把webapps文件夹中的war文件解压缩成相应的文件夹,你运行tomcat后可以再去看看webapps文件夹,里面肯定会多了一个你的webservice项目文件夹。

项目中是否引用了jaxb相关jar, 如jaxb-api-jar, jaxb-impl-jar, jaxb-xjc-jar, 如有的话,可能与Cxf冲突。

  如果还是不行,请尝试将Cxf版本换为21x。

  一 什么是REST

 REST是REpresentational State Transfer的缩写 代表分布式超媒体系统(如World Wide Web)上的一种软件架构体系 并不仅仅是创建Web Service的一种方法 它最早由Roy Fielding于 年在其博士论文 Architectural Styles and the Design of Neork based Sofare Architectures 中提出 并定义了一些基本原则 简单的说 放到World Wide Web上 就是所有的应用程序对象和功能都可以抽象为一种资源(Resource) 并通过URI来定位并使用 因此 我们可以把符合REST原则的系统称为RESTful 也就是说 REST是一种架构风格 而不是一个标准 你永远不会看到W C发布一个叫REST的Specification

 RESTful Web Service与基于SOAP和WSDL的Web Service有着很多的不同 它有着以下特点

 ·将Web Service作为一种资源 并通过URI来定位

 ·使用HTTP中的POST GET PUT和DELETE方法来代表对资源的CREATE READ UPDATE DELETE(CRUD)操作

 ·使用无状态通信

 ·传输XML或者SON

 在JAX WS中提供了对开发和部署一个RESTful的Web Service的基本支持 即通过实现Provider接口使得Web Serivce可以对传输的XML消息进行完全的控制 因此我们可以在WAS CE中使用JAX WS开发一个RESTful的Web Service     对RESTful Web Service提供完整支持的JAX RS Specification将会加入Java EE 的大家庭中 当前的WAS CE V x是遵循Java EE 的企业级应用服务器 因此 若想使用JAX RS开发RESTful Web Service 请关注WAS CE的后续版本

  二 开发环境设置

 本文基于WAS CE的最新版本V 开发一个RESTful的Web Service 在开始编写代码之前 请确认如下的开发环境

 ·Sun JDK V

 ·Eclipse IDE for Java EE Developers Ganymede

 ·WASCE Eclipse Plug in (WEP) V

 此外 WAS CE使用Axis 作为JAX WS引擎 但是由于其存在一个已知的关于HTTP Content Type Header的问题(在Axis 中才解决) 所以我们需要将JAX WS引擎切换成Apache CXF (WAS CE使用版本为V ) 不用担心 WAS CE的模块化架构 使这个过程十分简单 过程如下

  启动WAS CE

  打开Web //localhost: /console

  进入Application > Plugins页面 点击Add Repository

 

  由于WAS CE V 是基于Geronimo V 开发 所以我们也可以使用Geronimo的Server plug ins 在New Repository中输入

  / 然后点击Add Repository

 

  选择刚刚添加的Repository 然后点击Show Plugins in selected repository

 

  勾选上以下plug ins并且点击install按钮

 

  在以上CXF相关的Plugin安装完成之后 我们需要更新WAS CE的配置文件 以使得WAS CE在启动时加载CXF以代替Axis (注意 在更改配置文件前先要停止WAS CE服务器)

  停止WAS CE后 打开<WASCE_HOME>/var/config/config xml

 去掉以下四个module的condition属性

 <module name= nfigs/axis deployer/ /car condition= … />

 <module name= nfigs/axis ejb deployer/ /car condition= … />

 <module name= nfigs/cxf deployer/ /car condition= … />

 <module name= nfigs/cxf ejb deployer/ /car condition= … />

 增加load属性 axis 相关的为false cxf相关的为true

 <module name= nfigs/axis deployer/ /car load= false />

 <module name= nfigs/axis ejb deployer/ /car load= false />

 <module name= nfigs/cxf deployer/ /car load= true />

 <module name= nfigs/cxf ejb deployer/ /car load= true />

  重新启动WAS CE服务器

  三 开发一个简单的RESTful Web Service

  在Eclipse中创建一个Dynamic Web Project作为Web Service的宿主

 选择File >New >Dynamic Web Project

 输入Project Name为HelloRestfulService

  右击Java Resources src 新建一个class 其中package Name Interfaces如下设置

 

  加入如下代码

 

 package ibm wasce samples jaxws rest;import java io ByteArrayInputStream;import javax annotation Resource;import javax servlet ServletRequest;import javax xml parsers DocumentBuilder;import javax xml parsers DocumentBuilderFactory;import javax xml transform Source;import javax xml transform dom DOMSource;import javax xml transform stream StreamSource;import javax xml ws BindingType;import javax xml ws Provider;import javax xml ws WebServiceContext;import javax xml ws WebServiceProvider;import javax xml ws handler MessageContext;import javax xml ws HTTPBinding;import javax xml ws HTTPException;import w c dom Node;import w c dom NodeList;import xml sax InputSource;@WebServiceProvider@BindingType (value = HTTPBinding HTTP_BINDING )public  class HelloWorld  implements Provider<Source> {   @Resource   protected WebServiceContext wsContext ;   public Source invoke(Source source) {       try {           String targetName = null ;           if (source == null ) {               //Get: Getting input from query string               MessageContext mc = wsContext getMessageContext();               String query = (String) mc get(MessageContext QUERY_STRING );               System out println( Query String = + query);               ServletRequest req = (ServletRequest) mc get(MessageContext SERVLET_REQUEST );               targetName = req getParameter( target );           } else {               //POST: Getting input from input box               Node n = null ;               if (source instanceof DOMSource) {                   n = ((DOMSource) source) getNode();               } else  if (source instanceof StreamSource) {                   StreamSource streamSource = (StreamSource) source;                   DocumentBuilder builder = DocumentBuilderFactory newInstance() newDocumentBuilder();                   InputSource inputSource = null ;                   if (streamSource getInputStream() != null ) {                       inputSource = new InputSource(streamSource getInputStream());                   } else  if (streamSource getReader() != null ) {                       inputSource = new InputSource(streamSource getReader());                   }                   n = builder parse(inputSource);               } else {                   throw  new RuntimeException( Unsupported source: + source);               }               NodeList children = n getChildNodes();               for ( int i = ; i < children getLength(); i++) {                   Node child = em(i);                   if (child getNodeName() equals( people )) {                       targetName = child getAttributes() getNamedItem( target ) getNodeValue();                       break ;                   }               }           }

 String body = <ns:return xmlns:ns=\ \ >                    + <ns:HelloWorldResponse> + this sayHello(targetName) + </ns:HelloWorldResponse>                    + </ns:return> ;           return  new StreamSource( new ByteArrayInputStream(body getBytes()));

 } catch (Exception e) {           e printStackTrace();           throw  new HTTPException( );       }   }

 private String sayHello(String target){       return  Hello + target;   }}

 让我们看一看代码中的几个关键点

 a) @WebServiceProvider 表明这个Web Service实现了Provider接口 可以对XML消息进行完全的处理

 b) Provider 是这类Web Service都要实现的接口 它只有一个方法需要实现 即

 public abstractjava lang Object invoke(java lang Object arg )

 c) Source 是交换信息的载体

 当Source对象为空时 表示是一个GET Request 因为这种情况下 所有信息是被拼成一个URI的参数 并传到这个URI对应的Web Service

 否则 是一个POST Request 其内容会包括在一个Source对象内

 另外 Response的内容也要放到一个Source对象内

  编写web xml

 为了使我们前面编写的Web Service能够成功部署到WAS CE中 我们需要将如下内容加入到web xml中  <servlet>    <servlet name>Hello</servlet name>    <servlet class> ibm wasce samples jaxws rest HelloWorld</servlet class></servlet><servlet mapping>    <servlet name>Hello</servlet name>    <url pattern>/Hello</url pattern></servlet mapping>

 注意 这里只是借用了<servlet>和<servlet mapping>标签来帮助暴露Web Service 并不是真是要求这个Web Service必须要实现HttpServlet接口

  部署 运行并测试这个Web Service

 右击这个HelloRestfulService工程 选择Run As > Run on Server 会将其部署到WAS CE中 当Status栏变为Synchronized时 在Console中会有类似如下信息显示

 

 通过访问如下地址 测试使用GET方式调用RESTful Web Service返回的结果

 //localhost /HelloRestfulService/Hello?target=Rex

 

  四 开发一个简单的RESTful Web Service Client

  创建一个Dynamic Web Project作为Client

 选择File >New >Dynamic Web Project

 输入Project Name为HelloRestfulClient

  新建一个testget jsp 加入如下内容  <form method= POST action= HelloGetMethodRequester >  Target Name: <input type= text name= target >  <input type= submit value= Submit ></form>

 这个JSP用来为HelloGetMethodRequester Servlet提供参数

  创建HelloGetMethodRequester Servlet 加入如下内容

 protected void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {   PrintWriter ut = response getWriter();   String target = request getParameter( target );

 String queryRequest = //localhost: /HelloRestfulService/Hellotarget= + target;   GetMethod method = new GetMethod(queryRequest);   HttpClient client = new HttpClient();   int statusCode = client executeMethod(method);   if (statusCode != ) { //HttpStatus SC_OK       System err println( Method failed: + method getStatusLine());   }

 try {       DocumentBuilder builder= DocumentBuilderFactory newInstance() newDocumentBuilder();       Document queryResponse = builder parse(method getResponseBodyAsStream());       XPath xPath = XPathFactory newInstance() newXPath();       NodeList nodes = (NodeList) xPath evaluate( /return queryResponse XPathConstants NODESET );       for ( int i = ; i < nodes getLength(); i++) {           // Get eachxpathexpression as a string           String str = (String) xPath evaluate( HelloWorldResponse em(i) XPathConstants STRING );           out println( Service return: + str);       }   } catch (Exception e) {       e printStackTrace();   }}

 在这个Servlet中我们用到了mons codec jar和mons 两个包 因此我们需要将它们加入到Build Path中

 

 这两个包在WAS CE的如下目录中可以找到

 <WASCE_HOME>\repository\mons codec\mons codec\ \mons codec jar

 <WASCE_HOME >\repository\mons client\mons client\ \mons

 让我们看一看这段Servlet代码中的一些关键点

 a) 首先创建了一个HttpClient对象 并运行了GetMethod 即使用GET请求如下URI

 //localhost /HelloRestfulService/Hello?target= + target

 b) 如果成功返回 即statusCode为 则可以从method对象中得到返回的结果

 method getResponseBodyAsStream()

 c) 因为返回的结果为自定义的一段XML文档 所以我们可以使用XPath来处理并输出到页面上

  编写部署计划geronimo web xml

 为使这个Web Client能够成功部署到WAS CE中 我们还需要在geronimo web xml的<environment>中加入如下依赖  <dep:dependencies>    <dep:dependency>        <dep:groupId>mons codec</dep:groupId>        <dep:artifactId>mons codec</dep:artifactId>        <dep:version> </dep:version>        <dep:type>jar</dep:type>    </dep:dependency>    <dep:dependency>        <dep:groupId>mons client</dep:groupId>        <dep:artifactId>mons client</dep:artifactId>        <dep:version> </dep:version>        <dep:type>jar</dep:type>    </dep:dependency></dep:dependencies>

  部署和运行

 右击这个HelloRestfulClient工程 选择Run As > Run on Server 会将其部署到WAS CE中 当Status栏变为Synchronized时 表示部署成功

 在浏览器中打开如下页面

 

 输入 Rex 并点击Submit 可得到如下结果

 

  五 总结

 本文介绍了REST的基本概念 以及如何在WAS CE V 下开发一个RESTful Web Service和一个使用GET方式的Client 如果读者朋友有兴趣的话 也可以尝试扩展这个Client 如增加testpost jsp和HelloPostMethodRequester Servlet两个文件

  testpost jsp包括一个文件上载框 用以上传一个XML文件

  HelloPostMethodRequester Servlet用于将XML文件以POST方式传送给HelloWorld这个Service

 事实上 我们的HelloWorld RESTful Web Service已经具备了处理接收一个XML文件的能力

  六 资源链接

 ·WAS CE及Samples下载

 

 ·WAS CE Eclipse Plug in (aka WEP WAS CE s WTP Server Adapter)下载

 

 ·WAS CE文档

 

 ·WAS CE主页

lishixinzhi/Article/program/Java/ky/201311/28821

一、将vue项目进行打包编译后,根目录生成dist的文件

当出现如上图显示时,说明打包编译完成,已经生成dist文件

二、打开iis服务器

打开iis服务器后选中网站后右击选添加网站,就可对网站进行配置,物理路径选择编译后的dist文件夹后选确定就行。

三、右击选择启动后出现如下报错信息:

除非Windows Activation Service (WAS)和万维网发布服务(W3SVC)均处于运行状态,否则无法启动网站

解决:

打开命令提示符中输入servicesmsc ,打开服务。

找到windows install及word wide web发布服务选项,分别右击启动,并右键属性改为启动类型就可以。

这是重新启动下,就可以访问。

先说说如何部署到NC_HOME:

1把你的UAP项目导出modules,然后把你定义的wsdl和xsd文件导出放入public对应目录下(wsdl对应接口,xsd对应VO)

2把你引入的外部jar包放入对应模块lib文件夹下面(如果有的话,例如wsdj包)

3重启中间件,访问http://服务器IP地址:端口/uapws/service,可以看到当前NCHOME发布的所有webservice

再说说部署到WAS:

部署到WAS与部署到NC_HOME需要整体是差不多的,需要注意包冲突的问题(例如wsdj),如果包冲突,体现在部署was时会报错或者访问不到所有的webservice

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » web应用,在tomcat下正常启动,部署到was下也正常启动,但是点击所有模块

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情