Method for changing maven project name in Eclipse

  • 2021-07-06 11:04:20
  • OfStack

1. Modify the project name in Eclipse

Yes, this method is as simple as you expected. After the project has been imported into Eclipse, you only need to do two things

1.1 Change Project Folder Name

Select the item, press F12, and rename it.

Most people only did this step to change the project name, but later found that it didn't play a real role. For example, an original project copy was changed into a new project, then the file name was changed according to F2, and then the project was deployed to tomcat. tomcat indicated that a project with the same name had been deployed. The "same name" suggested by tomcat obviously refers not to the file name, but to something else.

1.2 Change Project Component Name

Select the item, right-click and select Properties, enter web in the input box at the top of the left menu bar, select Web Project Settings, and enter the name of the item to be changed in Context root on the right, OK.

After completing this step, the name of WEB project is really changed. In fact, what needs to be changed in the work of "changing project name" is the configuration name of this WEB project.

2. Manually change project configuration

In the end, this approach can also achieve the effect of changing the project name, but the work that Eclipse did in Method 1 was done manually.

2.1 Change project configuration

Locate the project folder and open .settings Folder, find org.eclipse.wst.common.component File, the file structure is as follows:


<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="xxx">
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<property name="context-root" value="xxx"/>
<property name="java-output-path" value="/xxx/target/classes"/>
</wb-module>
</project-modules>

snippet_file_0.txt Change all xxx in the file to the name you want to change, such as yyy

org.eclipse.wst.common.component This file is the component configuration file of eclipse web project, which configures the source code path of web project and the output path of compiled code. You can also see the modified Context root in method 1.2, which is the root path of the file.

After completing this step, the name change of the ordinary WEB project has been completed. If it is an Maven project, one more step needs to be done, and the configuration of pom. xml needs to be changed

2.2 Changes to pom. xml Configuration (Maven Project)

Open the pom. xml file and modify the following 3 configurations. xxx is the original project name


<artifactId>xxx</artifactId>
<name>xxx Maven Webapp</name>
<finalName>xxx</finalName>

Summarize


Related articles: