IntelliJ IDEA - Web(Facets/Artifacts)

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

1. 项目结构

pom.xml中配置打包方式war

  • part2-web,无web.xml

    IntelliJ IDEA - Web(Facets/Artifacts)_第1张图片
    part2-web

  • spring-mvc-learning,有web.xml

    IntelliJ IDEA - Web(Facets/Artifacts)_第2张图片
    spring-mvc-learning

2. Facets配置

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

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

具体配置如下:

  • Facets: part2-web

    IntelliJ IDEA - Web(Facets/Artifacts)_第3张图片
    Facets: part2-web

  • Facets: spring-mvc-learning

    IntelliJ IDEA - Web(Facets/Artifacts)_第4张图片
    Facets: spring-mvc-learning

3. Artifacts

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

    IntelliJ IDEA - Web(Facets/Artifacts)_第5张图片
    Artifacts: part2-web

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

    IntelliJ IDEA - Web(Facets/Artifacts)_第6张图片
    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:

IntelliJ IDEA - Web(Facets/Artifacts)_第7张图片
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


  
    
      
        
          
        
        
          
          
        
      
    
  

  • spring-mvc-learning


  
    
      
        
          
        
        
          
        
        
          
          
        
      
    
  

5. 部署

IntelliJ IDEA - Web(Facets/Artifacts)_第8张图片
Deployment
  • part2-web对应的Application context/
  • spring-mvc-learning对应的Application context/mvc

然后运行tomcat即可

你可能感兴趣的:(IntelliJ IDEA - Web(Facets/Artifacts))