Search code examples
javajax-wsbitcoinwebservice-clientjson-rpc

Is it possible to run java application in both commandline / as a webservice


I wantto create a java application like a bitcoin client.But it will work on command-line cmd and as a webservice to to other client consulting my client.Which tecnology should I use to handle my task.Please show me an example explanining issue


Solution

  • Expections

    Guess this is what you are expecting

    1. Run a Java program from command line or as OS service
    2. That program should be a webservice exposing some APIs to other consumers

    Solution

    • You can do that with the help of Spring MVC, Spring Boot and Maven

    Reasons

    • Spring MVC could be used for exposing your businesses as REST webservice
    • Spring Boot could be used to start a webservice application as a normal Java Application(using main class), without use of external web servers like Tomcat or Jetty
    • Maven build tool could be used for creating a fat jar(single jar file with all dependencies) from the Spring Boot application
    • You will be running the generated fat jar from command line still the services will be exposed as REST services

    Reference

    • Use https://start.spring.io/
    • This Spring's own hosted tool will generate all the boiler plate codes for you. You just have to import the downloaded zip into your workspace and add your business logic
    • For building a fat jar you don't have to do anything special. Just run mvn clean install. The boiler plate will have a pom.xml file that will take care of generating fat jar