-1

I have a maven servlet project, and I created executable jar for that project like show in this link: Is it possible to build a java project only once using eclipse and share?

But after creating jar file I run it by using

java -jar Task-jar-with-dependencies.jar

I got error

main method not found.

I am new to these concepts and I don’t know how to define main method in servlet program.

My program is

public class service extends HttpServlet{
protected void doPost(HttpServletRequest req, HttpServletResponse resp){
…..
…..
}
}

I am using tomcat.

Edited with info from comments

It is possible for me to send request using postman. I want to know how to generate an executable jar file and execute a class using the jar file also by using maven profile how to export project as a executable jar and execute it, I want to know them in general I just mentioned that example code for specifying in which area Iam working

Irina Avram
  • 1,492
  • 2
  • 20
  • 35
samkunju
  • 1
  • 1
  • 1
    First of all - you will generally need to show more code in order to get help. Second - a Java Servlet needs to be deployed to a servlet container such as Tomcat; it cannot be run from the command line – morsor Oct 07 '21 at 07:48
  • @morsor generally please give me advice about how to generate executable jar file and execute a class using the jar file Iam working in java web application with maven servlet with tomcat on eclipse – samkunju Oct 07 '21 at 07:56
  • maybe check https://stackoverflow.com/questions/9846046/run-main-class-of-maven-project – Irina Avram Oct 11 '21 at 13:11

1 Answers1

1

If you want to create an executable JAR which exposes REST endpoints, a solution could be to use Spring Boot:

https://spring.io/guides/gs/rest-service/

If it MUST be a servlet, it will need to be deployed to Tomcat.

morsor
  • 1,263
  • 14
  • 29
  • Iam using servlet and rest with jersey it is already deployed to tomcat. Can you please advice me how to do the further steps @morsor – samkunju Oct 07 '21 at 08:38
  • I don't understand what you want. If it is deployed to Tomcat, you should be able to perform HTTP requests using Postman – morsor Oct 07 '21 at 08:52
  • thank you for your response. actually it is possible for me to send request using postman. I want to know how to generate an executable jar file and execute a class using the jar file also by using maven profile how to export project as a executable jar and execute it, I want to know them in general I just mentioned that example code for specifying in which area Iam working. I want to know them in general , I am a learning student, kindly help me @morsor – samkunju Oct 07 '21 at 09:01
  • Perhaps this could help you: https://stackoverflow.com/questions/39343021/how-to-turn-my-jersey-rest-api-into-an-executable-jar – morsor Oct 07 '21 at 09:43