IDEA编译和构建JavaWeb项目时,项目中没有target目录,且out目录下没有class文件

  • Post author:
  • Post category:java




问题描述


IDEA编译和构建JavaWeb项目时,项目中没有target目录,且out目录下没有class文件





原因分析:

出现这种情况,很可能是因为未加载的模块出现在了 iml 文件中,导致生成 taget 的时候出错,进而导致 out 文件内 class 文件的缺失,所以我们只需在 iml 文件中,把相应的配置信息删除即可




解决方案:

找到 xxx.iml 文件,文件内容大概像这样:

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_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>
  <component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

接着将如下所示的代码删除

<component name="NewModuleRootManager" inherit-compiler-output="true">
    <exclude-output />
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>

重新编译构建,现在应该可以生成target目录,out目录下也有class文件了



版权声明:本文为hellokitty_nba原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。