• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

koddas/war-web-project: A demo Java WAR project for Maven.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

koddas/war-web-project

开源软件地址(OpenSource Url):

https://github.com/koddas/war-web-project

开源编程语言(OpenSource Language):

Java 98.4%

开源软件介绍(OpenSource Introduction):

About this project

This project is a simple demo web application using Java annotations. It runs on Java 7 and requires an application server, such as Glassfish, to run*. The project, built using Maven, will produce a deployable WAR file. It outputs JSON using Google's Gson library, which is imported and bundled at build time.

The annotations used are defined in the JAX-RS API.

*) Well, it actually doesn't. You can just as well embed a Java web container in your project, such as Jetty, and be done with it. Using an application server is probably easier for beginners, though.

How do I build this project?

You can easily build the code directly from within your IDE of choice (I'm personally rather fond of Eclipse), using its build features (in Eclipse, right click the project and select Run As -> Maven build, type package into the Goals field, then Run). If you prefer doing stuff more old school, you can use the command line to build the project as well. To do so, you need to have Maven installed on your machine. Navigate to your project location. Then, simply type

mvn package

in your terminal. Your generated WAR file can be found as ./target/wwp-1.0.0.war.

How do I run this project?

First of all, you'll need an application server. For this guide, I'll assume you've installed Glassfish (for a guide on doing so, please refer to Glassfish's get started guide).

Navigate to Glassfish's directory. Start Glassfish by executing the following command from the command line:

glassfish4/bin/asadmin start-domain

Open a new browser window/tab and type in localhost:4848. Find the Applications link in the menu and click it. Next, click the Deploy button and select ./target/wwp-1.0.0.war. Once done, click the Launch link and you're all set to try your new application. It will be made available at http://localhost:8080/wwp-1.0.0.

How do I configure my application?

The web page

The web application (or servlet in Java lingo) comes with a very simple web page. It is written in JSP, a web language akin to ASP or PHP (although I only use standard HTML in this example). You can put as many JSP pages as you wish in the src/main/webapp/ folder. Static resources, such as CSS files or images, are put in src/main/webapp/static/ and accessed by linking to static/style.css (for an example CSS file).

The application path

As you'll see, your application's URL needs to be amended with /webapi/service/ in order to actually do something. This isn't something that is selected at random, but is set in your web.xml file (which you'll find in src/main/webapp/WEB-INF/), as well as in your servlet Java file.

The /webapi/ part is set by the directive in web.xml. The /service/ part is set by altering the argument to the initial @Path annotation in the servlet's source code. In this case, that file is WebService.java, that you'll find in src/main/java/koddas/web/war.

By changing these values and rebuilding (and consequent redeploying) your project, you'll be able to reach your application with your fancy new path. Please note that the links displayed on the web page will not change accordingly, as they are set manually.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap