Spring boot - How to Specify Java path in Process Builder

karthick

I am Having Java 7 in my system as Default Configuration. But I have to use Java 8 only for spring boot.

The below command is working fine in my terminal.

ubuntu@karthick:~$ JAVA_HOME=/opt/jdk1.8.0_181 mvn spring-boot:run

But When I tried to execute it from Process Builder it is showing error.

Code:

ProcessBuilder pb = new ProcessBuilder("JAVA_HOME=/opt/jdk1.8.0_181", "mvn", "spring-boot:run");
pb.directory(new File("/home/ubuntu/project/springbootexample"));
Process p = pb.start();

I am getting the Below Error

error=2, No such file or directory. Stacktrace follows:
java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
    at java.lang.ProcessImpl.start(ProcessImpl.java:130)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
    ...
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:150)
    at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:281)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:202)
    at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:180)
    at com.brandseye.cors.CorsFilter.doFilter(CorsFilter.java:82)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

How to resolve the issue?

Deepak Jain

I would suggest create a script file(test.sh below) in which you can set java home and add other command to run spring boot and just invoke that script from java using below code:

  String[] args = { "/bin/bash", "test.sh"};

        StringBuilder builder = new StringBuilder();
        Process p2 = null;
        String result = null;
        String[] cmd = { "sudo", "-s" };
        Runtime.getRuntime().exec(cmd);
        p2 = Runtime.getRuntime().exec(args);
        BufferedReader reader = new BufferedReader(new 
       InputStreamReader(p2.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        result = builder.toString();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring Boot: How to specify the PasswordEncoder?

How specify a path in Java shortcut?

spring-boot - how to specify path of application.properties in envrionment or system properties?

How to run multiple threads of the same process in Java - Spring Boot

Specify options available on API endpoint for a path variable with Swagger in Spring Boot

How to specify Java 11 version in Spring/Spring Boot pom.xml?

How to specify prefix for all controllers in Spring Boot?

How do I specify a BeanNamingStrategy with Spring Boot?

How to specify the Launcher in Spring Boot Gradle?

How to specify a fallback request mapping in Spring Boot

Process Builder and Process in Java - how to execute a process with a timeout :?

How to specify the path for getResourceAsStream() method in java

how to get process id of a spring boot application

how to accept any path in Spring boot + MVC

How to specify a profile when deploying a Spring boot war file to Tomcat?

How to specify external properties files in application.properties in Spring Boot?

Spring boot - How to specify different location for rotated tomcat log file

How to specify UTC timezone for Spring Boot JPA Timestamp

Liquibase with Spring Boot and multiple schemas, how to specify execution order

How to specify a newer version of Elasticsearch in spring-boot

How do I specify a default value for an identity variable in Spring Boot?

How to see specify class list in spring-boot?

How to prevent a Spring Boot / Tomcat (Java8) process be OOM-killed?

How to access Builder() of a JPA entity using Lombok with Spring Boot?

How to filter records using Boolean Builder Spring Boot

How to get the full system path of a directory (not file) in Spring boot with Java 8

How to calculate (and specify) the total memory space allowed for java process?

How to run NPM Command in Java using Process Builder

How to manually specify java path in exec-maven-plugin