您的位置:新葡亰496net > 电脑系统 > 新葡亰496net:0在win10中的安装及环境变量配置,

新葡亰496net:0在win10中的安装及环境变量配置,

发布时间:2019-12-12 11:23编辑:电脑系统浏览(137)

    索引:

    maven3.5.0在win10中的安装及环境变量配置,maven3.5.0win10

    1.maven的下载地址

    新葡亰496net 1

    2.解压缩到自己指定的文件下,maven目录如下

    新葡亰496net 2

    3.配置环境变量

    在配置maven之前,先安装并配置好jdk,maven3.5.0要求jdk1.7及以上版本。我使用的是jdk1.8.0,下载地址:

    (1)此电脑右键-属性-高级系统设置-环境变量,在系统变量中新建M2_HOME变量,变量值为maven目录

    新葡亰496net 3

    (2)系统变量的path目录中添加%M2_HOME%bin;

    新葡亰496net 4

    4.测试

    执行cmd打开命令行窗口,输入mvn -v;

    新葡亰496net 5

    若输出如上图的结果,则配置成功。

     

    1.maven的下载地址 2.解压...

    参考

    1. search maven - maven
    2. search maven - mvnrepository
    3. Maven教程 - 易百教程

     

    商业开发实战总结--lm.solution

    教学视频

    1. 慕课网: 项目管理利器——maven

    - - 使用Myeclipse搭建maven项目 

      1. ### 准备工作

        #### 安装maven

    参看代码 GitHub:

    安装

    • 下载安装包并解压到指定目录项目地址:maven - download

      官网下载安装(

    maven.txt

    配置

    • Maven Home

      • 文件~/.zshrc 或 ~/.bashrc 或 ~/.bash_profile
      • 配置项

        # mavenexport M2_HOME=/Users/mingwang/tmp/install-software/apache-maven-3.5.0export M2=$M2_HOME/bin
        
    • Maven 本地仓库的位置

      • 文件:conf/settings.xml
      • 配置项:

        <settings ...> <!-- 中国镜像的位置 --> <localRepository>/Users/mingwang/tmp/Library/maven-repo</localRepository></settings>
        
    • Maven 远程仓库中国镜像

      • 文件:conf/settings.xml
      • 配置项:

        <mirrors> <!-- 阿里源 --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror></mirrors>
        
    • Maven部署项目到Tomcat(配置Tomcat用户)

      • 文件:conf/settings.xml
      • 配置项:

        <servers> <server> <id>TomcatServer</id> <username>admin</username> <password>admin</password> </server></servers>
        

            配置环境变量

             新葡亰496net 6    新葡亰496net 7

          配置完后,使用命令行输入mvn -version查看是否配置成功,出现以下界面表示配置成功。

              新葡亰496net 8

     

     

    一、Linux (DeepinOS) 环境

    maven常见项目目录结构

    • 普通Java Application项目

      .├── pom.xml└── src ├── main │ └── java │ └── com │ └── imooc │ └── maven02 │ └── App.java └── test └── java └── com └── imooc └── maven02 └── AppTest.java
      
    • Java Web项目

      .├── pom.xml└── src ├── main │ ├── java │ │ └── ServletDemo.java │ ├── resources │ └── webapp │ └── WEB-INF │ └── web.xml └── test └── java
      

        2. 在MyEclipse中配置maven

            打开MyEclipse2015————点击菜单栏Window———选项栏Preference ,搜索Maven,进入Installations,点击Add引入安装的maven。

            新葡亰496net 9

            进入User Setting,设置Global Setting,选中安装的maven的settings.xml配置文件(以上步骤已经完成maven配置)

            新葡亰496net 10

     

          

      1.官网下载

        3. 创建项目(检测是否配置成功,这里创建的是web项目)

            新葡亰496net 11新葡亰496net 12新葡亰496net 13

            点击项目右键->Run as->Maven install将依赖install至本地maven库,有可能会报:

            -Dmaven.multiModuleProjectDirectorysystem propery is not set. Check $M2_HOME environment variable and mvn scriptmatch.,

            表示JDK版本和maven有冲突,更改一下jdk版本,并且加上-Dmaven.multiModuleProjectDirectory=$M2_HOME即可;

            如运行过程中控制台如下图所示,表示成功。

            新葡亰496net 14

     

    新葡亰496net:0在win10中的安装及环境变量配置,仓源配置。 

     

            

    1 https://maven.apache.org/download.cgi
    

    - - 在maven项目中搭建spring springMVC MyBatis

      2.解压

          修改pom.xml添加对应的包依赖

              

    新葡亰496net 15新葡亰496net 16

    <!-- servlet -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
    
            <!-- 数据库连接池 -->
            <dependency>
                <groupId>c3p0</groupId>
                <artifactId>c3p0</artifactId>
                <version>0.9.1</version>
            </dependency>
    
            <!-- 阿里巴巴druid连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.0.25</version>
                <exclusions>
                    <exclusion>
                      <groupId>com.alibaba</groupId>
                      <artifactId>jconsole</artifactId>
                    </exclusion>
                    <exclusion>
                      <groupId>com.alibaba</groupId>
                      <artifactId>tools</artifactId>
                    </exclusion>
                </exclusions> 
            </dependency>
    
            <!-- 1、先添加spring相关的包 -->
            <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-tx</artifactId>
         <version>4.1.7.RELEASE</version>
        </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    
    
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
    
            <!--aspectjweaver包:面向切面要用到的包 -->
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>1.8.5</version>
            </dependency>
    
            <!--4、单元测试相关的包 -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
    
            <!-- 2、mybatis -->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.4.1</version>
            </dependency>
    
            <!-- 日志 -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
    
            <!-- 整合插件包 -->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
                <version>1.3.0</version>
            </dependency>
    
            <!-- mysql驱动 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.38</version>
            </dependency>
            <dependency>
                <groupId>com.mchange</groupId>
                <artifactId>mchange-commons-java</artifactId>
                <version>0.2.10</version>
            </dependency>
    
            <!-- 工具包 -->
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.10</version>
            </dependency>
    
            <!-- xml文件解析 -->
            <dependency>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
                <version>1.6.1</version>
            </dependency>
            <dependency>
                <groupId>com.thoughtworks.xstream</groupId>
                <artifactId>xstream</artifactId>
                <version>1.3.1</version>
            </dependency>
    
            <!-- json-lib -->
            <dependency>
                <groupId>net.sf.json-lib</groupId>
                <artifactId>json-lib</artifactId>
                <version>2.4</version>
                <classifier>jdk15</classifier>
            </dependency>
            <dependency>
                <groupId>xom</groupId>
                <artifactId>xom</artifactId>
                <version>1.2.5</version>
            </dependency>
    
            <!-- HttpClient -->
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.2.5</version>
            </dependency>
    
            <!-- 分页组件 -->
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>4.0.0</version>
            </dependency>
    
            <!-- 通用Mapper -->
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper</artifactId>
                <version>3.3.8</version>
            </dependency>
            <dependency>
                <groupId>commons-httpclient</groupId>
                <artifactId>commons-httpclient</artifactId>
                <version>3.1</version>
                </dependency>
    
    
            <dependency>
            <groupId>org.jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>1.1.3</version>
            </dependency>
    

    修改pom.xml,添加ssm相关jar包依赖

     

     

    1 tar -zxvf apache-maven-3.5.3-bin.tar.gz -C /home/liumeng/dev/Maven/
    

          修改web.xml文件

    新葡亰496net 17新葡亰496net 18

    <welcome-file-list>  
        <welcome-file>index.html</welcome-file>  
        <welcome-file>index.htm</welcome-file>  
        <welcome-file>index.jsp</welcome-file>  
        <welcome-file>default.html</welcome-file>  
        <welcome-file>default.htm</welcome-file>  
        <welcome-file>default.jsp</welcome-file>  
      </welcome-file-list>  
        <listener>  
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
       </listener> 
          <!-- 加入spring -->  
       <context-param>  
         <param-name>contextConfigLocation</param-name>  
         <param-value>classpath:applicationContext*.xml</param-value>  
       </context-param> 
    
        <!-- 配置DispatchcerServlet -->
        <servlet>
            <servlet-name>springDispatcherServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <!-- 配置Spring mvc下的配置文件的位置和名称 -->
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:springmvc.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>springDispatcherServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    

    修改web.xml,配置驱动及过滤器和加载Spring配置文件

     

      3.配置环境变量

          创建并配置applicationContext.xml

            

    新葡亰496net 19新葡亰496net 20

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
    
    
        <!-- 扫描 -->
        <context:component-scan base-package="cn.ft.mapper,cn.ft.service.impl,cn.ft.service.rest.impl"></context:component-scan>
        <!-- 导入db.properties -->
        <context:property-placeholder location="classpath:db.properties" />
    
        <!-- 先配置数据源:c3p0 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${driverClassName}"></property>
            <property name="jdbcUrl" value="${jdbc_url}"></property>
            <property name="user" value="${jdbc_username}"></property>
            <property name="password" value="${jdbc_password}"></property>
             <property name="testConnectionOnCheckin" value="false"/>
            <property name="testConnectionOnCheckout" value="true"/>
        </bean>
    
        <bean id="sqlsessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <!-- 加载mybatis.cfg.xml文件 -->
            <property name="configLocation" value="classpath:mybatis-config.xml"></property>
            <!-- 自动扫描需要定义类别名的包,将包内的JAVA类的类名作为类别名 -->
            <property name="typeAliasesPackage" value="cn.ft.model"></property>
        </bean>
    
    
    
        <!-- 自动扫描所有的Mapper接口与文件 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="cn.ft.mapper"></property>
        </bean>
        <!-- 事务的配置 -->
        <bean id="txManager"
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>
        <!-- 拦截器方式配置事物 -->
        <tx:advice id="transactionAdvice" transaction-manager="txManager">
            <tx:attributes>
                <!-- 以如下关键字开头的方法使用事物 -->
                <tx:method name="add*" propagation="REQUIRED" />
                <tx:method name="save*" propagation="REQUIRED" />
                <tx:method name="update*" propagation="REQUIRED" />
                <tx:method name="modify*" propagation="REQUIRED" />
                <tx:method name="edit*" propagation="REQUIRED" />
                <tx:method name="delete*" propagation="REQUIRED" />
                <tx:method name="remove*" propagation="REQUIRED" />
                <tx:method name="buyfood" propagation="REQUIRED" />
                <tx:method name="order" propagation="REQUIRED" />
                <!-- 以如下关键字开头的方法不使用事物 -->
                <tx:method name="get*" read-only="true" />
                <tx:method name="find*" read-only="true" />
                <tx:method name="load*" read-only="true" />
                <tx:method name="query*" read-only="true" />
                <!-- 其他方法不使用事物 -->
                <tx:method name="*" propagation="SUPPORTS" />
            </tx:attributes>
        </tx:advice>
    
        <!-- 切面,将事物用在哪些对象上 -->
        <aop:config>
            <aop:pointcut id="transactionPointcut"
                expression="execution(* cn.ft.service.impl.*Impl.*(..))" />
            <aop:advisor pointcut-ref="transactionPointcut"
                advice-ref="transactionAdvice" />
        </aop:config>
    
    </beans>
    

    applicationContext.xml

     

    1 vim ./.profile
    2 追加内容:
    3 # maven 3.5.3
    4 export M2_HOME=$HOME/dev/Maven/apache-maven-3.5.3
    5 export MAVEN_OPTS="-Xms128m -Xmx1024m"
    6 export PATH=$M2_HOME/bin:$PATH
    

          创建并配置springmvc.xml

    新葡亰496net 21新葡亰496net 22

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
    
    
        <!-- 扫描 -->
        <context:component-scan base-package="cn.ft.controller"></context:component-scan>
    
    
        <!-- 视图解析器 -->
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
    
    
    
    
    
    
    
        <bean
            class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            <property name="exceptionMappings">
                <props>
                    <prop key="org.apache.shiro.authz.UnauthorizedException">
                        /refuse
                    </prop>
                </props>
            </property>
        </bean>
            <mvc:annotation-driven>
                    <mvc:message-converters>
                        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                            <property name="supportedMediaTypes">
                                <list>
                                    <value>application/json;charset=UTF-8</value>
                                </list>
                            </property>
                        </bean>
                    </mvc:message-converters>
                </mvc:annotation-driven>
        <!-- Ajax中文乱码暂时无效<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
            <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> 
            <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> 
            </list> </property> </bean> </list> </property> </bean> -->
    
    </beans>
    

    springmvc.xml

     

      4.配置 maven 仓库地址

          配置数据源db.properties

    新葡亰496net 23新葡亰496net 24

    driverClassName=com.mysql.jdbc.Driver
    validationQuery=SELECT 1
    
    jdbc_url=jdbc:mysql://localhost:3306/ft?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
    jdbc_username=root
    jdbc_password=8888
    

    db.properties

     

     1 文件:/home/liumeng/dev/Maven/apache-maven-3.5.3/conf/settings.xml
     2 修改内容:
     3       <mirror>
     4           <id>alimaven</id>
     5           <mirrorOf>central</mirrorOf>
     6           <name>aliyun maven</name>
     7           <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
     8       </mirror>
     9       <profile>
    10           <id>jdk-1.8</id>
    11           <activation>
    12               <activeByDefault>true</activeByDefault>
    13               <jdk>1.8</jdk>
    14           </activation>
    15           <properties>
    16               <maven.compiler.source>1.8</maven.compiler.source>
    17               <maven.compiler.target>1.8</maven.compiler.target>
    18               <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    19           </properties>
    20       </profile>
    

          配置mybatis-config.xm

    新葡亰496net 25新葡亰496net 26

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
      PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
      "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
    
      <settings>
         <setting name="cacheEnabled" value="true"/>
      </settings>
    
      <typeAliases>
         <!--  
         <typeAlias type="cn.hd.model.Userbean" alias="userbean"/>
         -->
    
        <!-- 批量设置别名:别名就是类名(把第一个字母改小写) -->
        <package name="cn.ft.model"/>
      </typeAliases>
    
    
    
    
    </configuration>
    

    mybatis-config.xml

     

      5.生效

          配置log4j.properties

    新葡亰496net 27新葡亰496net 28

    log4j.rootCategory=DEBUG, stdout , R
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n
    
    log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.R.File=D:\Tomcat 5.5\logs\qc.log
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n
    

    View Code

     

    1 . ~/.profile
    

      6.验证

    1 mvn -v
    

     

     

    新葡亰496net:0在win10中的安装及环境变量配置,仓源配置。 

                                             蒙

                                        2018-05-23 22:05 周三

     

    本文由新葡亰496net发布于电脑系统,转载请注明出处:新葡亰496net:0在win10中的安装及环境变量配置,

    关键词: