简体   繁体   English

运行Spring的.class而不是.jar文件

[英]Run Spring's .class instead of .jar file

I have a Java Spring application which I built with maven , and a .jar file together with .class files were generated. 我有一个用maven构建的Java Spring应用程序,并生成了一个.jar文件和.class文件。

Instead of running the .jar file, is there a way for me to run the .class files instead? 除了运行.jar文件以外,还有其他方法让我运行.class文件吗?

I tried executing java -cp . hello.Application 我尝试执行java -cp . hello.Application java -cp . hello.Application in the same directory as the Application.class (source code of Application.java below), but was given Error: Could not find or load main class hello.Application . java -cp . hello.Application在相同的目录中Application.class (源代码Application.java下文),但被赋予Error: Could not find or load main class hello.Application Removing the hello. 删除hello. did not work either. 也不起作用。

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

我正在做Spring boot应用程序。我想你也可以使用maven创建一个jar文件,然后使用linux命令来运行它。

you can run a class by executing follow command : 您可以通过执行follow命令来运行一个类:

java Application

for only simple console application. 仅适用于简单的控制台应用程序。 to run Spring Boot application you need maven to build jar file and executing jar file to call main method to load spring boot context. 要运行Spring Boot应用程序,您需要maven来构建jar文件并执行jar文件来调用main方法来加载spring boot上下文。 Spring Boot need several requirements and dependencies to run. Spring Boot需要几个要求和依赖项才能运行。 Spring load context and create a special structure to load. Spring加载上下文并创建一个特殊的结构进行加载。 for more you can see following links: 有关更多信息,请参见以下链接:

https://spring.io/guides/gs/spring-boot/ https://spring.io/guides/gs/spring-boot/

http://www.logicbig.com/tutorials/spring-framework/spring-boot/boot-exploded-structure/ http://www.logicbig.com/tutorials/spring-framework/spring-boot/boot-exploded-structure/

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

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