How to create a executable jar containing a jetty based REST resource in 10 mins.
- Install sdkman with
curl -s "https://get.sdkman.io" | bash
- Install gradle with
sdk install gradle
- Create an app folder
mkdir app
cd app
- Init a gradle java application
gradle init --type java-application
- Build the app
./gradlew buid
- Run the app
./gradlew run
- Add the sparkjava dependency
compile "com.sparkjava:spark-core:2.5.5"
- Create a basic app in
src/main/java/App.java
public class App {
public static void main(String[] args) {
path("/api", () -> {
get("/hello-world", (req, res) -> {
});
});
}
}
- Test it by running
./gradlew run
and open browser onhttp://localhost:4567/api/hello-world
- Add the shadow gradle plugin
https://github.com/johnrengelman/shadow
- Build the app
./gradlew buid
- Run the jar
java -jar build/libs/<appnam>-all.jar
- Test it by opening a browser on
http://localhost:4567/api/hello-world
- Download apache cxf
curl http://www-eu.apache.org/dist/cxf/3.1.10/apache-cxf-3.1.10.zip
- Extract the wsdl2java binary and add it to your path
- Generate the java code from
wsdl2java -client http://www.webservicex.com/globalweather.asmx?WSDL
- Include the generated code in your project and call the web service e.g.
GlobalWeather ss = new GlobalWeather();
GlobalWeatherSoap port = ss.getGlobalWeatherSoap12();
return port.getCitiesByCountry("Norway");
./gradlew -h
./gradlew tasks
./gradlew build
./gradlew run
- Download the wsdl and generate a soap client with gradle e.g.
https://github.com/nilsmagnus/wsdl2java
- Add validation
- Add environment properties
- Add service scripts