Intellij idea下的maven web工程

新建

新建maven项目,create from archetype,选择maven-archetype-webapp

maven

Next,填写GroupId,ArtifactId和Version

maven

Next,这里在Properties中添加一个参数archetypeCatalog=internal,不加这个参数,在maven生成骨架的时候将会非常慢,有时候会直接卡住。

来自网上的解释:

archetypeCatalog表示插件使用的archetype元数据,不加这个参数时默认为remote,local,即中央仓库archetype元数据,由于中央仓库的archetype太多了,所以导致很慢,指定internal来表示仅使用内部元数据。

maven

Next,填写项目名称和module名称。

maven

点击Finish。

项目的目录结构如下:

tree

配置Jetty(在pom.xml中)

<plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>8.1.16.v20140903</version>
        <configuration>
          <systemProperties>
            <force>true</force>
            <systemProperty>
              <name>environment</name>
              <value></value>
            </systemProperty>
            <systemProperty>
              <name>app.key</name>
              <value>d</value>
            </systemProperty>
            <systemProperty>
              <name>app.port</name>
              <value>8080</value>
            </systemProperty>
          </systemProperties>
          <stopKey>xx</stopKey>
          <stopPort>5666</stopPort>
          <scanIntervalSeconds>0</scanIntervalSeconds>
          <reload>manual</reload>
          <!-- webAppConfig is is an alias for webApp-->
          <webApp>
            <contextPath>/</contextPath>
            <parentLoaderPriority>true</parentLoaderPriority>
            <allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
          </webApp>
          <connectors>
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
              <port>8080</port>
              <maxIdleTime>60000</maxIdleTime>
            </connector>
          </connectors>
        </configuration>
      </plugin>

配置web时需要注意的几点

配置web.xml(servlet容器)
 <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
系统会自动的根据servlet-name寻找该目录下的默认文件DispatcherServlet-servlet.xml,但是为了规范,还是希望在web.xml中显示指出。

配置applicationContext.xml
<context:component-scan base-package="com.d.controller"></context:component-scan>

       <mvc:annotation-driven />
       <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
              <property name="prefix" value="/WEB-INF/pages/"/>
              <property name="suffix" value=".jsp"/>
       </bean>

在配置过程中遇到的问题
在Intellij Idea中进行web工程配置时,由于开始并没有建立maven工程,后来通过Intellij idea 的Add Framework Support来构建的maven,然后通过maven添加jetty插件,这样添加的插件,是不会将工程自动部署到jetty容器上的( 如果是在intellij中创建maven项目 intellij会给你配置好所有的配置 )。
通过后期构建maven,对应的Project Settings的Artifacts是空的,没有任何配置的,是需要自己手动去添加的。

通过构建maven项目获取的配置是这样的(图参考http://www.cnblogs.com/jifeng/p/4658765.html)

config
总的来说其实就是没有将工程自动部署到jetty容器上
如果没有部署的话,会出现404的错误。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值