1. 安装idea

这里一定要安装idea ultra 版本,community没有spring boot框架

创建项目时选择spring initialize…
image.png

实现项目:

启动程序demoApplication

  1. package com.example.demo;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class DemoApplication {
  6. public static void main(String[] args) {
  7. SpringApplication.run(DemoApplication.class, args);
  8. }
  9. }
  1. 服务程序HelloController
  1. package com.example.demo;
  2. import org.springframework.web.bind.annotation.PostMapping;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RestController;
  5. import org.springframework.web.multipart.MultipartFile;
  6. /**
  7. * 测试控制器
  8. *
  9. * @author: @肖朋伟CSDN
  10. * @create: 2018-11-18
  11. */
  12. @RestController
  13. public class HelloController {
  14. static {
  15. System.load("/root/IdeaProjects/hw/src/libMYRELOC.so");
  16. }
  17. @RequestMapping("/hello")
  18. public String hello() {
  19. return "Simple test!";
  20. }
  21. @PostMapping("/what")
  22. public String what(MultipartFile file, String username){
  23. System.out.println(username);
  24. System.out.println(file.getSize());
  25. System.out.println(file.getName());
  26. System.out.println(file.getOriginalFilename());
  27. //do something to file
  28. HelloWorld hw = new HelloWorld();
  29. int[] dir = hw.getCoordI();
  30. return Integer.toString(dir[0]);
  31. }
  32. }

2. 用maven打包项目

image.png
选中clean compile package三项,点击绿色的三角形,等待打包完成
完成后生成jar包,根据提示信息找到位置

3. 在服务器运行jar包

将生成的jar包上传到服务器

先生成一个日志文件存放输出信息
touch log.txt

使用nohup命令让服务器挂在后台一直运行
nohup java -jar ARserver-0.0.1-SNAPSHOT.jar > log.txt 2>&1 &

4. 完成

效果如下
image.png