|
| 1 | +# Simple Measurement Converter Written in Java |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +Please refer to the |
| 6 | +[original repo of this project](https://github.com/xdvrx1/converter-app). |
| 7 | + |
| 8 | +This repo focuses on how to use the Spring Boot to create |
| 9 | +a production-grade executable jar file. Spring Boot is concerned with the |
| 10 | +infrastructure while you focus on writing your program. Take note, this is |
| 11 | +non-web GUI application. It's really that simple to build |
| 12 | +and run **any** of your existing Java program through Spring Boot. If |
| 13 | +I have to put web features or to connect to a server |
| 14 | +in this project, I can do that easily too in my code and Spring Boot |
| 15 | +will take care of the infrastructure. |
| 16 | + |
| 17 | +First, there must be the `maven plugin` to create the executable jar file |
| 18 | +in the `pom.xml`: |
| 19 | + |
| 20 | +``` |
| 21 | +<groupId>org.springframework.boot</groupId> |
| 22 | +<artifactId>spring-boot-maven-plugin</artifactId> |
| 23 | +``` |
| 24 | + |
| 25 | +Second, you tell Spring Boot the main method of your program |
| 26 | +because it has its own main method. |
| 27 | + |
| 28 | +``` |
| 29 | +<configuration> |
| 30 | + <mainClass>xdvrx1ProjectSwing.MainMethod</mainClass> |
| 31 | +</configuration> |
| 32 | +``` |
| 33 | + |
| 34 | +And finally, when your program launches GUI, you must set |
| 35 | +the headless mode in the SpringMainMethod file to false or else it |
| 36 | +will throw a `HeadlessException`. |
| 37 | + |
| 38 | +``` |
| 39 | +SpringApplicationBuilder builder = |
| 40 | + new SpringApplicationBuilder(SpringMainMethod.class); |
| 41 | + builder.headless(false); |
| 42 | + ConfigurableApplicationContext context = builder.run(args); |
| 43 | +``` |
| 44 | + |
| 45 | +What others are doing is relying on `CommandLineRunner`. This is needed |
| 46 | +when you want to trap user inputs on the command line once the |
| 47 | +Spring Boot is started and before your program runs. In our case here, |
| 48 | +we don't need that. |
| 49 | + |
| 50 | +See the project for the complete codes and setup! |
| 51 | + |
| 52 | +## Q&A |
| 53 | + |
| 54 | +If you have questions, please feel free to ask me: |
| 55 | + |
| 56 | +<mongAlvarez@gmail.com> |
| 57 | + |
| 58 | +You can also create a pull request or raise |
| 59 | +an issue to start the discussion or query/ies. |
| 60 | + |
| 61 | +## Compile, Build & Run |
| 62 | +Before you compile and build, make sure you are at the project directory. |
| 63 | +I'm using Maven build tool here. |
| 64 | + |
| 65 | +In Windows, |
| 66 | + |
| 67 | +to package your program as an executable jar file: |
| 68 | + |
| 69 | + mvn clean package |
| 70 | + |
| 71 | +to simply clean and compile: |
| 72 | + |
| 73 | + mvn clean compile |
| 74 | + |
| 75 | +to just clean your project: |
| 76 | + |
| 77 | + mvn clean |
| 78 | + |
| 79 | +to run the program: |
| 80 | + |
| 81 | + mvn spring-boot:run |
| 82 | + |
| 83 | +to build and run the program: |
| 84 | + |
| 85 | + mvn clean install |
| 86 | + |
| 87 | + |
| 88 | +## Contributing |
| 89 | + |
| 90 | +1. Fork it! |
| 91 | +2. Then, made changes, and create a pull request. |
| 92 | +I'm much more willing to collaborate with you! |
| 93 | + |
| 94 | +## License |
| 95 | + |
| 96 | +MIT - the permissive license |
0 commit comments