美文网首页Idea
IntelliJ IDEA - Web(Facets/Artif

IntelliJ IDEA - Web(Facets/Artif

作者: 鬼王丶 | 来源:发表于2018-11-20 12:59 被阅读0次

IDEA上部署Web项目至Tomcat上,虽然FacetsArtifacts都配置完备,然而webapp中的内容却无法被构建进相应的目录中,其原因在于iml文件

1. 项目结构

pom.xml中配置打包方式<packaging>war</packaging>

  • part2-web,无web.xml

    part2-web
  • spring-mvc-learning,有web.xml

    spring-mvc-learning

2. Facets配置

Facets用于配置Web项目结构,用于之后的Artifacts中:

  • Deployment Descriptors: 配置web.xml文件位置
  • Web Resource Directories: 配置webapp目录,其中包括css/js/jsp等资源

具体配置如下:

  • Facets: part2-web

    Facets: part2-web
  • Facets: spring-mvc-learning

    Facets: spring-mvc-learning

3. Artifacts

  • Artifacts: part2-web
    Output directory: PARENT_FOLDER/part2-web/target/part2-web-1.0-SNAPSHOT

    Artifacts: part2-web
  • Artifacts: spring-mvc-learning
    Output directory: PARENT_FOLDER/spring-mvc-learning/target/spring-mvc-learning-1.0-SNAPSHOT

    Artifacts: spring-mvc-learning

以下说明以part2-web:war exploded为例:

通常在Modules中,每个moduleCompiler output选择的都是Use module compile output path,其对应配置大致如下:

  • Output path: PARENT_FOLDER/part2-web/target/classes
  • Test output path: PARENT_FOLDER/part2-web/target/test-classes

Available Elements:

Available Elements

Available Elements中的part2-web,包含以下几部分:

  • 'part2-web' compile output: 来源于Modules中配置的Output path/Test output path相关内容。可双击或右键选择Put into WEB-INF/classes加入到左边的Output Layout
  • Maven: **: 来源于Librariesmodule(part2-web)所依赖的jar包。可选择全部所依赖的jar包,然后右键选择Put into WEB-INF/lib加入到左边的Output Layout
  • Web facet resources: 来源于Facets中配置的内容,如: web.xmlwebapp包含的资源。可双击或右键选择Put into Output Root加入到左边的Output Layout

对于META-INF/MANIFEST.MF文件会在编译后生成。

part2-web:war引用的是part2-web:war exploded,可以不需要。

4. iml

iml文件中的配置,关系到Facets所配置的内容是否会被加入到PARENT_FOLDER/part2-web/target/part2-web-1.0-SNAPSHOT/PARENT_FOLDER/spring-mvc-learning/target/spring-mvc-learning-1.0-SNAPSHOT目录下

  • part2-web
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <webroots>
          <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
        </webroots>
        <sourceRoots>
          <root url="file://$MODULE_DIR$/src/main/java" />
          <root url="file://$MODULE_DIR$/src/main/resources" />
        </sourceRoots>
      </configuration>
    </facet>
  </component>
</module>
  • spring-mvc-learning
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
  <component name="FacetManager">
    <facet type="web" name="Web">
      <configuration>
        <descriptors>
          <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
        </descriptors>
        <webroots>
          <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
        </webroots>
        <sourceRoots>
          <root url="file://$MODULE_DIR$/src/main/java" />
          <root url="file://$MODULE_DIR$/src/main/resources" />
        </sourceRoots>
      </configuration>
    </facet>
  </component>
</module>

5. 部署

Deployment
  • part2-web对应的Application context/
  • spring-mvc-learning对应的Application context/mvc

然后运行tomcat即可

相关文章

网友评论

    本文标题:IntelliJ IDEA - Web(Facets/Artif

    本文链接:https://www.haomeiwen.com/subject/ofstqqtx.html