eclipse solves the problem that the right run as maven project does not run on server:

problem:

When running the maven project, I found that right-click run as no run on server option on the project;

Solution: When creating a new maven project, choose war instead of jar in packaging.

As shown in the figure, choose war in packaging when building a web project through maven:

I have tested that if jar is selected in Packaging, the project cannot be started normally as a web project anyway.

I also tested another method, which seems to be invalid:

This method is to select jar in Packaging when creating a new maven, but the middle is changed into a dynamic web project in the following way.

The specific practices are as follows:

Right-click on the maven project > properties> Project Facets:

You can see that it is not currently a web project, so check two options: Dynamic Web Module, JavaScript:

If there is no web.xml in the project, you can pre-set it here

You can click on the "Further configuration avaliable" in the picture above

After that you can see the default configuration:

If you do not modify its default configuration, webcontent will be generated directly in the project release path, as shown in the following figure:

So you need to modify the configuration as follows:

Check Generate web.xml (if not checked, web.xml will not be generated), and modify the folder where web.xml is generated to be webapp.

Click OK, then click Apply.

As shown below, the webapp and internal web.xml have been generated:

Then according to the normal project structure, you can drag the webapp to the main folder under src:

After that, you can right-click run as on the project to see Run on server:

After the service is started, the browser can also start normally, but it will still be wrong before it is finished.

My matching welcome page is invalid, it will show 404:

It seems that the jar declared cannot run successfully.

Basically, in addition to changing to the war package, no other solution has been found.

You can look at the difference between the two pom files generated by the jar package and the war package when building the maven project:

jar:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.changping.shirodemo</groupId>
  <artifactId>shirodemo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>

war:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.changping.shirodemo01</groupId>
  <artifactId>shirodemo01</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
</project>

By comparing pom files, you can find that there are more wars than jars in <packaging> war </ packaging>.

So if you don't want to create a new maven project or the welcome page does not want to change to 404, you can add <packaging> war </ packaging> to the pom file and update it after modification.

As shown in the figure, packaging is changed to war. After the service is started, the welcome page can be displayed normally:

As for the solution if there is no web.xml in the webapp in the maven project, in addition to the right-click> properties> Project Facets method just mentioned , you can also directly paste one from another project:

Guess you like

Origin www.cnblogs.com/timingstarts/p/12729811.html