Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何更改springboot应用程序启动目录?_Java_Linux_Spring Boot_Systemctl - Fatal编程技术网

Java 如何更改springboot应用程序启动目录?

Java 如何更改springboot应用程序启动目录?,java,linux,spring-boot,systemctl,Java,Linux,Spring Boot,Systemctl,我在CENTOS7上运行springboot应用程序作为服务。默认的开始目录是“/”,现在我想更改为配置文件所在的“/home/centos/fpcyproxy”。 如何改变它 日志文件: 2018-08-28 14:38:21.645 INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application : Starting Application v1.0.0 on ip-172-31-26-206.cn-northwest-1.com

我在CENTOS7上运行springboot应用程序作为服务。默认的开始目录是“/”,现在我想更改为配置文件所在的“/home/centos/fpcyproxy”。
如何改变它

日志文件:

2018-08-28 14:38:21.645  INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application           : Starting Application v1.0.0 on ip-172-31-26-206.cn-northwest-1.compute.internal with PID 2075 (/home/centos/fpcyproxy/fpcyproxy-1.0.0.jar started by root in /)
2018-08-28 14:38:21.662  INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application           : No active profile set, falling back to default profiles: default
2018-08-28 14:38:21.828  INFO 2075 --- [main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@19e1023e: startup date [Tue Aug 28 14:38:21 CST 2018]; root of context hierarchy
2018-08-28 14:38:24.673  INFO 2075 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8443 (https)
2018-08-28 14:38:24.739  INFO 2075 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-08-28 14:38:24.739  INFO 2075 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-08-28 14:38:24.773  INFO 2075 --- [localhost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2018-08-28 14:38:24.928  INFO 2075 --- [localhost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-08-28 14:38:24.928  INFO 2075 --- [localhost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3100 ms
2018-08-28 14:38:25.186  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-08-28 14:38:25.189  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-08-28 14:38:25.190  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-08-28 14:38:25.190  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-08-28 14:38:25.190  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-08-28 14:38:25.493  INFO 2075 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-28 14:38:25.918  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@19e1023e: startup date [Tue Aug 28 14:38:21 CST 2018]; root of context hierarchy
2018-08-28 14:38:26.114  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/fpcy],methods=[POST]}" onto public ljis.ykk.fpcyproxy.domain.FpcyResult ljis.ykk.fpcyproxy.MainController.fpcy(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
2018-08-28 14:38:26.135  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-08-28 14:38:26.136  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-08-28 14:38:26.176  INFO 2075 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-28 14:38:26.176  INFO 2075 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-28 14:38:26.487  INFO 2075 --- [main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-28 14:38:26.879  INFO 2075 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8443 (https) with context path ''
2018-08-28 14:38:26.886  INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application           : Started Application in 6.306 seconds (JVM running for 7.104)
[Unit]
Description=fpcy proxy
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/java -jar /home/centos/fpcyproxy/fpcyproxy-1.0.0.jar

[Install]
WantedBy=multi-user.target
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
操作系统版本:

CentOS Linux release 7.5.1804 (Core)
Linux version 3.10.0-862.3.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) ) #1 SMP Mon May 21 23:36:36 UTC 2018
Java版本:

2018-08-28 14:38:21.645  INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application           : Starting Application v1.0.0 on ip-172-31-26-206.cn-northwest-1.compute.internal with PID 2075 (/home/centos/fpcyproxy/fpcyproxy-1.0.0.jar started by root in /)
2018-08-28 14:38:21.662  INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application           : No active profile set, falling back to default profiles: default
2018-08-28 14:38:21.828  INFO 2075 --- [main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@19e1023e: startup date [Tue Aug 28 14:38:21 CST 2018]; root of context hierarchy
2018-08-28 14:38:24.673  INFO 2075 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8443 (https)
2018-08-28 14:38:24.739  INFO 2075 --- [main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-08-28 14:38:24.739  INFO 2075 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-08-28 14:38:24.773  INFO 2075 --- [localhost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2018-08-28 14:38:24.928  INFO 2075 --- [localhost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-08-28 14:38:24.928  INFO 2075 --- [localhost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3100 ms
2018-08-28 14:38:25.186  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-08-28 14:38:25.189  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-08-28 14:38:25.190  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-08-28 14:38:25.190  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-08-28 14:38:25.190  INFO 2075 --- [localhost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-08-28 14:38:25.493  INFO 2075 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-28 14:38:25.918  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@19e1023e: startup date [Tue Aug 28 14:38:21 CST 2018]; root of context hierarchy
2018-08-28 14:38:26.114  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/fpcy],methods=[POST]}" onto public ljis.ykk.fpcyproxy.domain.FpcyResult ljis.ykk.fpcyproxy.MainController.fpcy(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
2018-08-28 14:38:26.135  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-08-28 14:38:26.136  INFO 2075 --- [main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-08-28 14:38:26.176  INFO 2075 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-28 14:38:26.176  INFO 2075 --- [main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-28 14:38:26.487  INFO 2075 --- [main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-28 14:38:26.879  INFO 2075 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8443 (https) with context path ''
2018-08-28 14:38:26.886  INFO 2075 --- [main] ljis.ykk.fpcyproxy.Application           : Started Application in 6.306 seconds (JVM running for 7.104)
[Unit]
Description=fpcy proxy
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/java -jar /home/centos/fpcyproxy/fpcyproxy-1.0.0.jar

[Install]
WantedBy=multi-user.target
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

如果您正在谈论应用程序的homedir,请尝试设置WorkingDirectory属性:

[Service]
WorkingDirectory=/home/centos/fpcyproxy
但是,如果您正在谈论加载位于外部目录中的
application.properties
,请尝试设置下一个属性

ExactStart=/usr/bin/java -jar /home/centos/fpcyproxy/fpcyproxy-1.0.0.jar --spring.config.location=/home/centos/fpcyproxy/