- 我们重头开始,先创建一个新的工作空间
File->Swith Workspace->Other
- 切换视图
先将左边的Project Explorer叉掉
Window->Show View->Navigator
然后继续把Package Explorer视图也调出来(会出现在下面,将其移到左边
- 修改编码格式.
Window->Preferences->General->Workspace
编码格式都设置统一之后后面就会省去好多麻烦事
- 设置maven
Window->Preferences->Maven
在installations中添加你的maven
在User Settings中添加你的settings.xml文件
Settings.xml中的一些配置
阿里云中央仓库镜像:
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
设置成你的jdk版本:
<profile>
<id>jdk18</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
- 开始创建项目
在Package Explorer中右键NEW->Maven Project
可能你项目创建后是下面这样的
居然有个红叉,我们来解决他
点击Window->Show View->Servers
好,问题还是没有解决吧,别急我们继续
鼠标放到我们的项目上右键-》Properties->Java Build Path->Add Library->Server Runtime
保存退出,发现讨厌的红叉终于消失了
现在我们需要在pom.xml中添加tomcat插件来启动
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8091</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
- 运行项目
鼠标放到项目上右击->Run As->Run Configurations
出来了,先别激动,下面才是见证奇迹的时刻,我们不要关闭这个tomcat继续启动别的端口,步骤如下:
访问一下
Nice!