Java Eclipse 中的 Jersey Maven 快速入门原型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30018111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:59:17  来源:igfitidea点击:

Jersey Maven quickstart archetype in Eclipse

javamavenjerseyjersey-2.0maven-archetype

提问by Mr Asker

I am trying to create Jersey normally with the aid of maven but I am always getting this structure as in the scrennshoot and without error as normally?! It does not look as Jersey commonly layout.

我试图在 maven 的帮助下正常创建 Jersey,但我总是像在 scrennshoot 中一样获得这种结构,并且没有像往常一样出错?!它看起来不像泽西岛通常的布局。

I am using this one:

我正在使用这个:

org.glassfish.jersey.archetypes
jersey-quickstart-webapp
2.16

enter image description here

在此处输入图片说明

pom.xml:

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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.test</groupId>
  <artifactId>serverSide</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>serverSide</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

采纳答案by Paul Samsotha

I highly doubt you are creating the archetype project correctly. What you are showing is a product of the org.apache.maven.archetypes : maven-archetype-quickstart

我非常怀疑您是否正确创建了原型项目。你展示的是产品org.apache.maven.archetypes : maven-archetype-quickstart

Here's a quick walk-through of how to create the Jersey archetype in Eclipse

这是如何在 Eclipse 中创建 Jersey 原型的快速演练

  1. Go to FileNewOther

  2. In the dialog, select the Mavenfile the Maven Project, then Next

    enter image description here

  3. In the next dialog keep all the defaults, and hit Next

    enter image description here

  4. In this next dialog we will select the Maven archetype. In the search box, type jersey-quickstart-webapp. All the archetypes takes a few moments to load. You can see the progress at the bottom right of the IDE is they are still loading. This shouldn't take more than maybe 5 seconds. If you are not seeing any results come up from the search, then it's likely you don't have the archetypes installed. See this Stackoverflow answerfor how you can get the archetypes.

    Once the archetypes load, and you see the jersey-quickstart-webappin the results list, uncheck "Show the last version of Archetype only". So once you have unchecked that, you should see more version available. Scroll down to the org.glassfish.jersey.archetypesand select the version 2.16 (or whatever the latest version is, if you choose). Then hit Next

    enter image description here

  5. In the next dialog, enter the groupId, artifactId, and package, then hit Finish

    enter image description here

  6. You should now see a project with the following structure. There will be an error in the project because of you jsp page. We have no use for it here, so you can delete it if you want. This should get rid of the error.

    enter image description here

  1. 前往FileNewOther

  2. 在对话框中,选择Maven文件Maven Project,然后Next

    在此处输入图片说明

  3. 在下一个对话框中保留所有默认值,然后点击 Next

    在此处输入图片说明

  4. 在下一个对话框中,我们将选择 Maven 原型。在搜索框中,键入jersey-quickstart-webapp。所有原型都需要一些时间来加载。您可以在 IDE 的右下角看到它们仍在加载的进度。这应该不会超过 5 秒。如果您没有看到任何搜索结果,那么您可能没有安装原型。有关如何获取原型的信息,请参阅此 Stackoverflow 答案

    加载原型后,您会jersey-quickstart-webapp在结果列表中看到,取消选中“仅显示原型的最新版本”。因此,一旦取消选中该选项,您应该会看到更多可用版本。向下滚动到org.glassfish.jersey.archetypes并选择版本 2.16(或任何最新版本,如果您选择)。然后打Next

    在此处输入图片说明

  5. 在下一个对话框中,输入 groupId、artifactId 和 package,然后点击 Finish

    在此处输入图片说明

  6. 您现在应该看到一个具有以下结构的项目。项目中会因为你的jsp页面出现错误。我们在这里没有用,因此您可以根据需要删除它。这应该摆脱错误。

    在此处输入图片说明



See Also:

也可以看看:

回答by Deepak Acharya

One point I want to add, If you are getting following error while installing the archetype showed in image 1

我想补充一点,如果您在安装图 1 中显示的原型时遇到以下错误

Can't resolve Archetype org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.21 org.eclipse.core.runtime.CoreException: Could not resolve artifact org.glassfish.jersey.archetypes:jersey-quickstart-webapp:pom:2.21

无法解析 Archetype org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.21 org.eclipse.core.runtime.CoreException: 无法解析工件 org.glassfish.jersey.archetypes:jersey-quickstart-webapp:pom: 2.21

Image 1: enter image description here

图 1: 在此处输入图片说明

Then before procedding with the solution specified in this stackoverflow answer, try to complete the following steps in eclipse:

然后在继续使用此 stackoverflow answer 中指定的解决方案之前,尝试在 eclipse 中完成以下步骤:

Steps:

脚步:

  1. Go to Eclipse Help-> Install New Software...
  2. Enter "http://download.eclipse.org/technology/m2e/releases" inside Work withfield and click on Addbutton.
  3. Give any name. For example "remote archetypes" and click on OKbutton. enter image description here
  4. Then click on Select Allbutton. enter image description here
  5. click Nextbutton two times.
  6. Accept the licence and install the updated maven.
  1. 转到 Eclipse帮助->安装新软件...
  2. Work with字段中输入“ http://download.eclipse.org/technology/m2e/releases” ,然后单击“添加”按钮。
  3. 给任何名字。例如“远程原型”并单击“确定”按钮。 在此处输入图片说明
  4. 然后单击全选按钮。 在此处输入图片说明
  5. 单击“下一步”按钮两次。
  6. 接受许可证并安装更新的 maven。

回答by sarav

Can't resolve Archetype org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.21 org.eclipse.core.runtime.CoreException: Could not resolve artifact org.glassfish.jersey.archetypes:jersey-quickstart-webapp:pom:2.21

无法解析 Archetype org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.21 org.eclipse.core.runtime.CoreException: 无法解析工件 org.glassfish.jersey.archetypes:jersey-quickstart-webapp:pom: 2.21

To resolve the issues with respect to archetypes while creating a new maven project ,please follow the same.

要在创建新的 maven 项目时解决与原型有关的问题,请遵循相同的操作。

Navigate as follows in your Eclipse IDE,

在 Eclipse IDE 中按如下方式导航,

Hover to windows-->Click on Preferences

将鼠标悬停在 Windows--> 单击首选项

Search for maven and select Archetype(first option under the hood as in screen shot)enter image description here

搜索 maven 并选择 Archetype(引擎盖下的第一个选项,如屏幕截图所示)在此处输入图片说明

This above URL could be changed in future;in that case please refer the below link under location of catalog filesfor latest URL http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html

以上 URL 将来可能会更改;在这种情况下,请参阅目录文件位置下的以下链接以获取最新 URL http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html

  • Under Description,enter your own description of choice & click ok & apply the main menu.
  • 在描述下,输入您自己的选择描述并单击确定并应用主菜单。

Give eclipse sometime to load your archetypes.(Check progress menu for the download status)

给 eclipse 一些时间来加载你的原型。(检查下载状态的进度菜单)

And this worked out for me. Thanks

这对我有用。谢谢

enter image description here

在此处输入图片说明