IDEA编译和构建JavaWeb项目时,项目中没有target目录,且out目录下classes文件下main包下的Java包的类没有加载到

发布时间 2023-06-10 13:07:11作者: 不自觉的天才

问题如下:

1.我们在添加web框架时,如图:

添加web框架

2.在添加完框架,和配置完Tomcat我们开始运行项目,发现没有target文件和out文件下classes文件下什么都没有

原因:

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

解决方案:

1.找到 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>

2.我们只需要删除一部分代码即可,将下述代码删除

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

最后我们重新编译一下程序,out文件下的classes文件就会把Java类加进去了

注意点: 在idea中lib很有可能没有加载到out文件中,所以需要我们在项目结构中进行导入.这个教程网上很多可以去搜索.给你们一个参考链接:

https://blog.csdn.net/qipverome/article/details/105175102