Home java How to collect .jar project Spring Boot + Maven?

How to collect .jar project Spring Boot + Maven?

Author

Date

Category

Collected in Eclipse is not a large skeleton (“config” template) for its projects that plan to further post on some cloud provider. Eclipse everything works well. Assembled with Maven (“Run” menu = & gt; Instal) and as a result received a project file called ConfigSPringBoot-0.0.1-Snapshot.jar in the Target folder. I launch this JAR through the Windows command line, and in the end I get the error “WhiteLabel Error Page …. (Type = Internal Server Error, Status = 500).” What am I doing wrong?

The project in general is empty, but contains 5 classes and 4 HTML pages (for verifying THYMELEAF and database interaction). In addition to pom.xml and one line in Application.Properties (“Spring.mvc.hiddenmethod.Filter.Enabled: True”), no additional configuration files are not. This looks like the latest version of POM.xml (I tried different options Executable Jar With Maven ) But nothing helped:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Project XMLNS = "http://maven.apache.org/pom/4.0.0"
  XMLNS: XSI = "http://www.w3.org/2001/xmlschema-Instance"
  XSI: Schemalocation = "http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  & lt; Modelversion & GT; 4.0.0 & lt; / Modelversion & GT;
  & lt; parent & gt;
    & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
    & lt; artifactid & gt; Spring-boot-starter-parent & lt; / artifactid & gt;
    & lt; version & gt; 2.4.4 & lt; / version & gt;
  & lt; / parent & gt;
  & lt; groupid & gt; com.example & lt; / groupid & gt;
  & lt; artifactid & gt; configspringboot & lt; / artifactid & gt;
  & lt; Version & GT; 0.0.1-Snapshot & lt; / Version & GT;
  & lt; Name & gt; configspringboot & lt; / name & gt;
  & lt; description & gt; config spring boot & lt; / description & gt;
  & lt; Packaging & gt; jar & lt; / packaging & gt;
  & lt; Properties & gt;
    & lt; project.build.sourceencoding & gt; UTF-8 & lt; /project.build.sourceencoding>
    & lt; project.reporting.outputencoding & gt; UTF-8 & lt; /project.Reporting.outPutencoding>
    & lt; maven-jar-plugin.version & gt; 3.1.1 & lt; /maven-jar-plugin.version>
    & lt; failonmissingwebxml & gt; false & lt; / failonmissingwebxml & gt;
  & lt; / Properties & gt;
  & lt; Dependencies & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-Boot-Starter-Web & Lt; / ArtifactID & GT;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-boot-starter-thymeleaf & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.apache.tomcat.Embed & lt; / groupid & gt;
      & lt; artifactid & gt; Tomcat-Embed-Jasper & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; Groupid & gt; Org.hibernate.Validator & lt; / GroupID & GT;
      & lt; artifactid & gt; hibernate-validator & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; mysql & lt; / groupid & gt;
      & lt; artifactid & gt; mysql-connector-java & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-boot-starter-jdbc & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-boot-DevTools & lt; / artifactid & gt;
      & lt; optional & gt; True & lt; / optional & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; junit & lt; / groupid & gt;
      & lt; artifactid & gt; junit & lt; / artifactid & gt;
      & lt; scope & gt; Test & lt; / scope & gt;
    & lt; / dependency & gt;
  & lt; / dependencies & gt;
  & lt; Build & gt;
    & lt; plugins & gt;
      & lt; plugin & gt;
        & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
        & lt; artifactid & gt; Spring-Boot-Maven-plugin & lt; / artifactid & gt; 
& lt; Executions & gt;
          & lt; execution & gt;
            & lt; goals & gt;
              & lt; goal & gt; repackage & lt; / goal & gt;
            & lt; / goals & gt;
            & lt; Configuration & gt;
              & lt; Classifier & gt; Spring-boot & lt; / classifier & gt;
              & lt; Mainclass & gt;
                Bootmain.
              & lt; / Mainclass & gt;
            & lt; / configuration & gt;
          & lt; / execution & gt;
        & lt; / executions & gt;
      & lt; / plugin & gt;
    & lt; / plugins & gt;
  & lt; / build & gt;
& lt; / Project & gt;

I’m not sure about the correctness of Prefix with an indication of the folder “/ Web-inf /” in the TEMPLATERESOLVER BINE, which is located in the bootmain class.

@bean
     Public SpringResourceTemplateresolver Templateresolver () {
        SpringResourceTemplateResolver Templateresolver = New SpringResourceTemplateresolver ();
        TEMPLATERESOLVER.SETAPPLICATIONCONTEXT (CONTEXT);
        templatesolver.setprefix ("/ Web-INF /");
        templateresolver.setsuffix (". HTML");
        templatesolver.setcharacteranscoding ("UTF-8");
        Return Templateresolver;
      }


In POM.xml specifically added the dependence of the Spring-Boot-DevTools (True) in the hope of seeing an error in the browser and make printstacktrace. However, besides the message Server Error, Status = 500 did not see anything. In this case, the controller is made in such a way that when accessing the address LocalHost: 8080, I must receive an error 404 (the page is not found). It works 🙂 And when accessing HTTP: // Localhost: 8080 / PEPLE / INDEX (project start page) I get Status = 500. I want to note again that everything works through Eclipse. Such a misunderstanding arises only after assembling the project and run JAR through the CMD Windows.

Template architecture (project) is as follows:


Answer 1, Authority 100%

First you need to pack web project not in .jar, and in .war otherwise it does not create a WEB-INF folder with all contents, including the .html and .jsp pages for this need to be changed in pom.xml & lt; packaging & gt; jar & lt; / packaging & gt; on & lt; packaging & gt; war & lt; / packaging & gt; Answer this question is on StackOverFlow . In this case, pom.xml should look like this:

& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& lt; Project XMLNS = "http://maven.apache.org/pom/4.0.0"
  XMLNS: XSI = "http://www.w3.org/2001/xmlschema-Instance"
  XSI: Schemalocation = "http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  & lt; Modelversion & GT; 4.0.0 & lt; / Modelversion & GT;
  & lt; parent & gt;
    & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
    & lt; artifactid & gt; Spring-boot-starter-parent & lt; / artifactid & gt;
    & lt; version & gt; 2.4.4 & lt; / version & gt;
  & lt; / parent & gt;
  & lt; groupid & gt; com.example & lt; / groupid & gt;
  & lt; artifactid & gt; configspringboot & lt; / artifactid & gt;
  & lt; Version & GT; 0.0.1-Snapshot & lt; / Version & GT;
  & lt; Name & gt; configspringboot & lt; / name & gt;
  & lt; description & gt; config spring boot & lt; / description & gt;
  & lt; Packaging & GT; War & LT; / Packaging & GT;
  & lt; Properties & gt;
    & lt; project.build.sourceencoding & gt; UTF-8 & lt; /project.build.sourceencoding>
    & lt; project.reporting.outputencoding & gt; UTF-8 & lt; /project.Reporting.outPutencoding>
    & lt; failonmissingwebxml & gt; false & lt; / failonmissingwebxml & gt;
  & lt; / Properties & gt;
  & lt; Dependencies & gt;
    & lt; dependency & gt; 
& lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-Boot-Starter-Web & Lt; / ArtifactID & GT;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-boot-starter-thymeleaf & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.apache.tomcat.Embed & lt; / groupid & gt;
      & lt; artifactid & gt; Tomcat-Embed-Jasper & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; Groupid & gt; Org.hibernate.Validator & lt; / GroupID & GT;
      & lt; artifactid & gt; hibernate-validator & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; mysql & lt; / groupid & gt;
      & lt; artifactid & gt; mysql-connector-java & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-boot-starter-jdbc & lt; / artifactid & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
      & lt; artifactid & gt; Spring-boot-DevTools & lt; / artifactid & gt;
      & lt; optional & gt; True & lt; / optional & gt;
    & lt; / dependency & gt;
    & lt; dependency & gt;
      & lt; groupid & gt; junit & lt; / groupid & gt;
      & lt; artifactid & gt; junit & lt; / artifactid & gt;
      & lt; scope & gt; Test & lt; / scope & gt;
    & lt; / dependency & gt;
  & lt; / dependencies & gt;
  & lt; Build & gt;
    & lt; plugins & gt;
      & lt; plugin & gt;
        & lt; groupid & gt; org.springframework.boot & lt; / groupid & gt;
        & lt; artifactid & gt; Spring-Boot-Maven-plugin & lt; / artifactid & gt;
      & lt; / plugin & gt;
       & lt; plugin & gt;
        & lt; groupid & gt; org.apache.maven.plugins & lt; / groupid & gt;
        & lt; artifactid & gt; Maven-compiler-plugin & lt; / artifactid & gt;
        & lt; Configuration & gt;
          & lt; Source & gt; 8 & lt; / source & gt;
          & lt; target & gt; 8 & lt; / target & gt;
        & lt; / configuration & gt;
      & lt; / plugin & gt;
    & lt; / plugins & gt;
  & lt; / build & gt;
& lt; / Project & gt;

To start the project through the Windows command line, you need to properly prescribe the path to the JDK installed (on the local computer) and the project executable file. The “target” folder structure and the command line window (CMD Windows) should look approximately like this:
If everything is done correctly, all errors for the developer (Exception printStackTrace) are displayed in the console (CMD), and the client part is displayed in the browser at http: // LocalHost: 8080.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions