I have an existing application which is a jetty app written in Java and managed with maven. There are a few basic tasks that can be run from the browser but mainly it runs all the tasks in one go when run from the command line (or Jenkins).
It does this by calling a specific Maven profile
so the maven command line call is
mvn clean install -P autorun
The autorun profile is
<profile>
<id>autorun</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<java classname="com.app.tool.Client" >
<arg value="-h" />
<classpath>
<pathelement path="${runtime_classpath}"/>
</classpath>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
there is a main procedure in the Client class
public static void main(String... args) throws Exception { ...
which essentially
- creates an
org.eclipse.jetty.server.Server
object - uses the war file to kick off the http server app
Uses a number of
org.springframework.http.client.ClientHttpRequest
objects to fire off a number of tasks using code along the lines ofClientHttpRequest request = restTemplate .getRequestFactory() .createRequest( new URI("http://localhost:8080/tool/spring/" + jobName), HttpMethod.GET); ClientHttpResponse clientHttpResponse = request.execute(); if (clientHttpResponse.getStatusCode().value() != HttpStatus.OK_200) { throw new RuntimeException(...); }
I am going to refactor the app now for various reasons. My aim is to keep the current design as, although it's main current use points more to a console app, I would like to make add some more useful interactive functionality.
So to finally get to the point, I have started re-writing the app as a Spring Boot application. I would like to still be able to fire off the jobs I want from the command line (and Jenkins). Is there a simple (& equivalent) way to do this with Spring Boot & Maven ? I am using Main to fire off the app so possibly I need to pass a switch into here
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootStartUpConfig.class, args);
}
I'm guessing that a lot of the code currently used to start the server can be dumped but I'm struggling to find the best way to achieve this ? (I'd prefer to use Maven as this is the core tool we are using but I can use Gradle if this is something that it is better at).