I'm new to springboot and using springboot 2 version.
I would like to run my spring boot application using : java -jar my-app-0.0.1-SNAPSHOT.jar from the command prompt.
However, when i build the application using eclipse it calls myService.getMyMethod() directly and does not build the jar.
I want to build the jar file first and then run java -jar my-app-0.0.1-SNAPSHOT.jar from the command prompt which will invoke myService.getMyMethod()
I already have spring-boot-maven-plugin in pom.xml, running mvn package / mvn install starts the application but not generating the jar file in the target folder. mvn clean package also not working, MyApplication is using implements CommandLineRunner and starts invoking the method on build, hence not generating the build jar file
My main class:
@SpringBootApplication
public class MyApplication implements CommandLineRunner {
private static String URL = "ws://localhost:8080/spring-mvc-java/chat";
@Autowired
private MyService myService;
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
myService.getMyMethod(URL);
}
}
My service class:
@Service
public class MyServiceImpl implements MyService {
public void getMyMethod(String URL){
WebSocketClient client = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(client);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
StompSessionHandler sessionHandler = new MyStompSessionHandler();
stompClient.connect(URL, sessionHandler);
new Scanner(System.in).nextLine(); // Don't close immediately.
}
}
spring-boot-maven-plugin
to yourpom.xml
to create the correct jar? – Purposelessmvn package
doesn't generate the jar, but starts the app, you probably have a test that blocks the proces. – Purposeless