rest api如何创建
REST:创建注册应用程序 (REST: Creating the Registration Application)
The prerequisites for developing the registration application are:
开发注册应用程序的前提条件是:
- Maven configured on the machine. 在机器上配置了Maven。
- Eclipse (IDE) installed on the machine. 在机器上安装了Eclipse(IDE)。
- Apache Tomcat Server installed in the machine. 在机器上安装了Apache Tomcat Server。
发展步骤 (Steps of Development)
- Choose the directory where you want to keep the files related to this application. 选择您要保留与此应用程序相关的文件的目录。
cd {your directory}
→ run the below mentioned command in the command prompt.cd {your directory}
→在命令提示符下运行以下提到的命令。mvn archetype:generate -DgroupId=com.rest.tutorials -DartifactId=RegistrationApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
Make sure that Maven is setup before running the above command. This command will create the web application structure in your directory and
pom.xml
file. Thispom.xml
file is the metadata of your application.运行上述命令之前,请确保已安装Maven。 此命令将在目录和
pom.xml
文件中创建Web应用程序结构。 此pom.xml
文件是您的应用程序的元数据。Your pom.xml will look something like this,
您的pom.xml看起来像这样,
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.rest.tutorials</groupId> <artifactId>RegistrationApp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>RegistrationApp Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>RegistrationApp</finalName> </build> </project>
pom.xml
file, just like the Junit dependency is added.pom.xml
文件中添加Jersey依赖项,就像添加了Junit依赖项一样。<dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-moxy</artifactId> <version>2.25.1</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> <version>2.22.1</version> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.22.1</version> </dependency>
mvn eclipse:eclipse
mvn eclipse:eclipse
This will generate a .classpath and a .project file so that you can import this project into the eclipse.
这将生成一个.classpath和.project文件,以便您可以将该项目导入eclipse中。
The project structure should look like this in the eclipse now.
现在,项目结构在Eclipse中应该看起来像这样。
翻译自: https://www.studytonight.com/rest-web-service/creating-the-registration-application
rest api如何创建