泽西岛2.0“入门”指南,找不到mainClass [英] Jersey 2.0 "Getting Started" guide, mainClass not found

查看:126
本文介绍了泽西岛2.0“入门”指南,找不到mainClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试关注使用入门指南泽西岛2.0。

Hi I am trying to follow the Getting Started guide for Jersey 2.0.

我按原样执行了步骤1.1和1.2。没问题。

I did steps 1.1 and 1.2 as is. No problem there.

对于步骤1.3,我遇到了问题,因为maven找不到javax-annotation 1.2但我按照建议解决了另一个Stackoverflow用户并向我的pom添加了一个存储库。

For step 1.3 I had a problem cause maven could not find the javax-annotation 1.2 but I solved it following the advice of another Stackoverflow user and added a repository to my pom.

所以 mvn clean test 传递没有问题,但是当我尝试运行 mvn时clean exec:java 我回来了

Somvn clean test passes with no problems, BUT when I try to run mvn clean exec:java I get back

[WARNING] java.lang.ClassNotFoundException: com.example.Main
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:722)

pom.xml是由以下命令创建的:

The pom.xml is the one created by the following command:

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \
-DarchetypeVersion=2.0

我所做的唯一补充如下:

where the only addition I 've made is the following:

<repositories>
  <repository>
    <id>java.net.repo</id>
    <url>https://maven.java.net/content/groups/promoted/</url>
    <layout>default</layout>
  </repository>
</repositories>

如果感兴趣,这是 mvn -version <的输出/ code>

In case it is of interest this is the output of mvn -version

 Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
 Maven home: /usr/share/maven
 Java version: 1.7.0_21, vendor: Oracle Corporation
 Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/jre
 Default locale: el_GR, platform encoding: UTF-8
 OS name: "mac os x", version: "10.8.3", arch: "x86_64", family: "mac" 


推荐答案

我能够重现你的错误。这跟泽西没什么关系;这是你用Maven制作的一个错误。 mvn clean exec:java 说:删除所有.class文件,然后尝试运行 Main .class文件。由于你删除了它,Maven找不到它。这是一个解决方案:

I am able to reproduce your error. This has nothing to do with Jersey; it's an error you're making with Maven. mvn clean exec:java says: "delete all the .class files and then try to run the Main .class file". Since you deleted it, Maven can't find it. Here's a solution:

mvn clean compile exec:java

这应该可以解决您问题中的问题。这说删除所有.class文件,从源代码重新编译它们然后尝试运行 Main .class文件

This should fix the problem in your question. This says "delete all the .class files, recompile them from source and then try to run the Main .class file"

要了解您将看到的下一个错误,请从pom.xml中的客户端依赖项中删除< scope> test< / scope> 行: / p>

To get past the next error you'll see, delete the <scope>test</scope> line from the client dependency in the pom.xml:

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <scope>test</scope>
</dependency>

收件人:

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
</dependency>

这篇关于泽西岛2.0“入门”指南,找不到mainClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆