Jersey hello world example

本文详细介绍了如何使用Jersey库开发基于JAX-RS规范的简单 HelloWorld REST Web 应用程序。通过创建标准 Maven Web 项目结构、引入相关依赖、实现 REST 服务接口、配置 web.xml 文件来注册 Jersey 服务,并演示了如何在 Eclipse 中部署和测试应用。

Jersey, reference implementation to develope RESTful web service based on the JAX-RS (JSR 311) specification.

In this tutorial, we show you how to develop a simple hello world REST web application with Jersey.

Technologies and Tools used in this article:

  • Jersey 1.8
  • JDK 1.6
  • Tomcat 6.0
  • Maven 3.0.3
  • Eclipse 3.6

1. Directory Structure

This is the final web project structure of this tutorial.
folder directory

2. Standard Web Project

Create a standard Maven web project structure.

mvn archetype:generate -DgroupId=com.mkyong.rest -DartifactId=RESTfulExample 
    -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Note

To support Eclipse, use Maven command :

mvn eclipse:eclipse -Dwtpversion=2.0

3. Project Dependencies

Jersey is published in Java.net Maven repository. To develop Jersey REST application , just declares “jersey-server” in Maven pom.xml.

File : pom.xml

<project ...>

    <repositories>
        <repository>
            <id>maven2-repository.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>

    </dependencies>

</project>

4. REST Service

Simple REST service with Jersey.

package com.mkyong.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/hello")
public class HelloWorldService {

    @GET
    @Path("/{param}")
    public Response getMsg(@PathParam("param") String msg) {

        String output = "Jersey say : " + msg;

        return Response.status(200).entity(output).build();

    }

}

5. web.xml

In web.xml, register “com.sun.jersey.spi.container.servlet.ServletContainer“, and puts your Jersey service folder under “init-param“, “com.sun.jersey.config.property.packages“.

File : web.xml

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
                     com.sun.jersey.spi.container.servlet.ServletContainer
                </servlet-class>
        <init-param>
             <param-name>com.sun.jersey.config.property.packages</param-name>
             <param-value>com.mkyong.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

6. Demo

In this example, web request from “projectURL/rest/hello/” will match to “HelloWorldService“, via @Path("/hello").

And the “{any values}” from “projectURL/rest/hello/{any values}” will match to parameter annotated with @PathParam.

URL : http://localhost:8080/RESTfulExample/rest/hello/mkyong
demo

内容概要:本文介绍了基于噪声抑制半监督学习的锂离子电池SOH(State of Health,健康状态)估计方法的Python代码实现。该方法融合半监督学习框架与先进的噪声抑制机制,旨在利用少量标注样本和大量未标注数据,有效提升电池健康状态预测的精度与模型鲁棒性,特别适用于实际工程中电池老化数据标注成本高、样本稀缺的挑战性场景。通过设计高效的特征提取网络与可靠的伪标签生成及优化策略,模型能够有效识别并抑制训练过程中的噪声干扰,增强在复杂工况和数据波动下的泛化能力与稳定性。; 适合人群:具备一定机器学习理论基础和Python编程能力,从事电池管理系统(BMS)、新能源汽车、储能系统等领域的科研人员、工程师,以及专注于电池寿命预测、设备状态监测与智能运维等方向的硕博研究生;; 使用场景及目标:①解决锂离子电池SOH估计中标注数据获取困难、成本高昂的核心痛点;②提升模型在存在测量误差、传感器漂移或异常数据等噪声环境下的预测准确性与可靠性;③为相关科研课题提供可复现、可扩展的算法基准与开源代码框架,加速算法迭代与工程落地; 阅读建议:此资源以Python代码为核心载体,强调算法的完整复现与实验验证过程,建议读者结合代码逐模块剖析模型架构、损失函数设计与训练流程细节,并积极在自有电池数据集上进行迁移学习、参数调优与性能对比,以深入掌握半监督学习与噪声抑制技术在电池退化建模中的关键应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值