Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to convert normal java project to springboot project?

I have a java project which executes a batch file. I would like to know if it is possible to change a normal java project to a spring boot project. If it is, can i know how do i roughly go about doing it?

I have read what is spring boot. However i am totally confused as to how do i apply that into this task of a java class executing a batch file.

Here are my codes:

RunBatchMain.java

public static void main(String args[])
{
    //Run batch file using java
    String filePath = "C:/Users/attsuap1/Desktop/test.bat";
    try {            
        Process p = Runtime.getRuntime().exec(filePath);
      } catch (Exception e) {
        e.printStackTrace();
    }
}

GetResponseMain.java

public static void main(String args[])
{
    String filePath = "C:/Users/attsuap1/Desktop/test.bat";
    try {
       Process p = Runtime.getRuntime().exec(filePath);
        p.waitFor();          

        InputStream in = p.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();            

        int c = -1;
        while((c = in.read()) != -1){
            baos.write(c);
        }

        String response = new String(baos.toByteArray());
        System.out.println("Response From Batch File : "+response);

        int exitVal = p.waitFor();
        System.out.println("ExitValue: " + exitVal);

    } catch (Exception e) {
        e.printStackTrace();
    }           
}

Someone please help me. Thank you so much.

like image 352
Susha Naidu Avatar asked Oct 31 '25 08:10

Susha Naidu


2 Answers

Yes it's possible. You can start by going to Spring Initializr page. You can generate a starter project there. Download the generated project then import to your IDE. The starter project contains a sample class with a main method. You can simply copy paste your code there as a start.

like image 65
Raymund Arthur Avatar answered Nov 02 '25 22:11

Raymund Arthur


Yes, you can convert your project into spring boot in two ways.

  1. Through Spring initializr(https://start.spring.io/). Go through the steps there, download a zip file and finally import project into your favorite IDE and copy your existing code there.

  2. Through your IDE also you can create Spring boot project and copy paste your existing code, that's it. Please refer below on how to create spring boot project from your STS IDE.

enter image description here

Since it's a normal java project, no need to add any special dependencies in maven pom.xml file, it should work.

like image 40
Rakesh Avatar answered Nov 02 '25 23:11

Rakesh