简体   繁体   English

我的Java应用程序是否在OpenShift上运行

[英]Is my Java app running on OpenShift

I am just getting started with server applications and cloud services, and have signed up to OpenShift. 我刚刚开始使用服务器应用程序和云服务,并且已经注册了OpenShift。

I have set everything up successfully using the Tomcat 7 cartridge, and pushed my first (very simple) code to the remote Git repository. 我已经使用Tomcat 7墨盒成功设置了所有内容,并将我的第一个(非常简单的)代码推送到了远程Git存储库。 It compiles and builds, but as far as I can see, when the application is restarted, doesn't run. 它可以编译和构建,但据我所知,当应用程序重新启动时,它无法运行。 I have checked all the logs, and there are no errors. 我已经检查了所有日志,并且没有错误。

I have also tried going into the target folder of the repo and running java Main , but I get this error: 我也尝试进入存储库的目标文件夹并运行java Main ,但出现此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name: helloworld/Main)

even though the Main.class file is right there. 即使Main.class文件就在那里。

The class is as follows: 该类如下:

public class Main
{

  public static void main(String[] args)
  {
      System.out.println("It works!");
  }   
}

I'm obviously missing something and I've searched most of the similar answers to no avail - can someone tell me what I'm doing wrong? 我显然遗漏了一些东西,并且搜索了大多数类似的答案,但无济于事-有人可以告诉我我在做什么错吗?

You can not run static main method (any java app entry point) in any application server environment (such as Tomcat, Jboss, Glassfish etc.). 您不能在任何应用程序服务器环境(例如Tomcat,Jboss,Glassfish等)中运行静态主方法(任何Java应用程序入口点)。 Application container search for class derived from the HttpServlet (for most of times), other words: your class have to inherit javax.servlet.http.HttpServlet . 应用程序容器搜索(大多数情况下)从HttpServlet派生的类,换句话说:您的类必须继承javax.servlet.http.HttpServlet

As you can see in your exception: a java thread was already running, so the required first main method (application entry point) was started. 正如您在异常中看到的那样:一个Java线程已经在运行,因此启动了所需的第一个主方法(应用程序入口点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM