在eclipse中使用maven
maven插件设置:
1.maven插件:eclipse内置:
2.maven插件设置:
- installations:指定maven核心程序的位置,不建议使用插件自带的maven程序,而应该使用我们自己解压的maven程序;
- user settings:指定conf/settings.xml的位置,进而获取本地仓库的位置;
3.maven解压目录\config\settings.xml:
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 21 22 46 <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" 47 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 48 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> 49 55 <localRepository>/Users/lixiuming/.m2/repositorylocalRepository> 56 64 65 72 73 78 <pluginGroups> 79 83 pluginGroups> 84 85 90 <proxies> 91 105 proxies> 106 107 111 <servers> 112 125 126 133 servers> 134 135 146 <mirrors> 147 159 <mirror> 160 <id>maven-default-http-blockerid> 161 <mirrorOf>external:http:*mirrorOf> 162 <name>Pseudo repository to mirror external repositories initially using HTTP.name> 163 <url>http://0.0.0.0/url> 164 <blocked>trueblocked> 165 mirror> 166 mirrors> 167 168 189 <profiles> 190 219 220 254 profiles> 255 256 264 settings>
创建maven版java工程
创建maven工程--选择简单的工程--选择创建位置(/或者就是勾选住 user default workspace location)
填写对应的坐标信息和 packaging 为jar,
jre 环境:
默认jdk1.5;修改环境
如果想要默认加入的maven项目就是jdk1.8,就需要在setting.xml中找到profiles标签加入即可;
<profile> <id>jdk-1.8id> <activation> <activeByDefault>trueactiveByDefault> <jdk>1.8jdk> activation> <properties> <maven.compiler.source>1.8maven.compiler.source> <maven.compiler.target>1.8maven.compiler.target> <maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion> properties> profile>
执行maven命令:
pom.xml右键 执行对应的 maven命令即可;
如果需要执行cmpile,在build...中,添加goles:为compile ,run 即可;
创建maven版web工程
和创建java工程类似,唯一的区别是packaging 不是jar,是war;
项目配置:
默认创建的项目 没有web.xml ,没有web-info 等,需要配置;右键项目名称;选择project Facets 选择Dynamic Web Module 直到下面出现furter configuration avi...,(如果不出现,反复勾选几次)点击他配置web目录和web.xml;
web工程的自动部署配置:
1 2 <build> 3 <plugins> 4 <plugin> 5 <groupId>org.eclipse.jettygroupId> 6 <artifactId>jetty-maven-pluginartifactId> 7 <version>${jettyVersion}version> 8 <configuration> 9 <scan>10scan> 10 <webApp> 11 12 <contextPath>/testcontextPath> 13 webApp> 14 configuration> 15 plugin> 16 plugins> 17 build>
pom.xml完整文件:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0modelVersion> 5 <groupId>org.muses.mavengroupId> 6 <artifactId>webproject-simpleartifactId> 7 <version>0.0.1-SNAPSHOTversion> 8 <packaging>warpackaging> 9 <properties> 10 <org.muses.spring.versin>5.3.0org.muses.spring.versin> 11 <jettyVersion>9.3.9.v20160517jettyVersion> 12 properties> 13 14 <dependencies> 15 <dependency> 16 <groupId>javax.servletgroupId> 17 <artifactId>servlet-apiartifactId> 18 <version>2.5version> 19 <scope>providedscope> 20 dependency> 21 <dependency> 22 <groupId>javax.servlet.jspgroupId> 23 <artifactId>jsp-apiartifactId> 24 <version>2.1.3-b06version> 25 <scope>providedscope> 26 dependency> 27 <dependency> 28 <groupId>org.springframeworkgroupId> 29 <artifactId>spring-ormartifactId> 30 <version>${org.muses.spring.versin}version> 31 dependency> 32 <dependency> 33 <groupId>org.eclipse.jettygroupId> 34 <artifactId>jetty-serverartifactId> 35 <version>${jettyVersion}version> 36 dependency> 37 dependencies> 38 39 40 <build> 41 <plugins> 42 <plugin> 43 <groupId>org.eclipse.jettygroupId> 44 <artifactId>jetty-maven-pluginartifactId> 45 <version>${jettyVersion}version> 46 <configuration> 47 <scan>10scan> 48 <webApp> 49 50 <contextPath>/testcontextPath> 51 webApp> 52 configuration> 53 plugin> 54 plugins> 55 build> 56 project>
web项目启动
jetty:run 即可启动程序:
jetty 配置参考了https://www.eclipse.org/jetty/documentation/jetty-11/programming-guide/index.html#developing-standard-webapp-with-jetty-and-maven