Idea使用中的问题记录

版权声明:本文来自 Crocutax 的博客 , 转载请注明出处 http://www.crocutax.com

idea配置Tomcat,启动Web项目

  1. Run->Edit Configuration
  2. 添加TomcatServer->Local Server,在Server选项卡中选择Tomcat服务器,并进行Tomcat名称,默认部署后启动的浏览器等信息
    • 编辑器已有默认配置
  3. 选择Deployment选项卡,按绿色+号 添加需要部署的项目,右侧Application context为项目名称.
    • 如果Application context不配置,默认为/,那么通过http://localhost:8080/index.jsp即可访问项目页面
    • 如果Application context配置为/test,那么访问路径变为http://localhost:8080/test/index.jsp

注意

如果发现配置的部署的项目无法Apply,或者无法通过绿色铅笔按钮进行编辑 , 那么采用如下方法:

  • idea编辑器左上角File->Project Structure->Project Settings->Artifacts->绿色按钮添加->Web Application Exploded
  • 左边output root为编译文件输出目录 , 右侧Available Elements为可用项目元素 , 默认编辑器已配置好可用项目元素 , 双击 , 或右键选择 , 即可将指定目录左移到output root目录.
  • 回到Edit Configuration->Deployment界面 , 重新添加部署的项目 , 来源选择Artifacts即可

4.此时Apply之后发现tomcat并没有添加成功 , 还差最后一步 . 在Edit Configuration页面下方 , 有Befor launch:Build,Build Artifacts,Activate tool window选项 , 默认只有一个Build条目 , 再添加一个Build Artifacts条目 , 再Apply->OK

配置成功!完事!

错误:找不到或无法加载主类

环境状况:

  • 环境变量配置没有问题,通过windows命令行窗口可以正常查看版本号
  • 电脑里的其他Java和Android项目都运行正常

在此前提下,运行Demo时报出 错误:找不到或无法加载主类. 说明是Idea配置问题导致的.

原因

  1. 没有给Project设置编译文件的输出路径,即Project Structure -> Project Settings -> Project compiler output没有设置,但是却在Modules -> Paths 中选择了 Inherit project compile output path
  2. Project Structure -> Modules -> Paths 中,选择了Use module compile output path , 但是只是默认的相对路径.

解决方案

首先,确保Project Structure -> Project,已为Project指定SDK

其次:

方案1:使用Project的编译输出路径

  • 在Project Settings -> Project compiler output中设置Project的编译输出路径
  • 在Project Settings -> Modules中选择 Inherit project compile output path 即继承Project的路径

方案2:使用Module的编译输出路径

Project Structure -> Modules -> Paths,改变Output pathTest output path的路径.

两个路径默认是:

  • \out\lib
  • \out\test\lib

改为项目绝对路径+上述目录,比如项目文件路径为E:\JavaEE\HelloWorld,那么修改后的两个Path分别为:

  • E:\JavaEE\HelloWorld\out\lib
  • E:\JavaEE\HelloWorld\out\test\lib

实现接口方法报错

当实现一些接口方法时,报出@Override is not allowed when implementing Interface method

override报错.png

由于项目所使用的java语言版本所导致的,打开File->Project Structure->Modules->选择项目目录->Sources选项卡->Language Level,更换Language Level即可,比如更换为8-Lambdas. 即可解决问题,如下图所示

更换LanguageLevel.png

pom.xml中配置的依赖库提示not found

情况1:maven Reposity 仓库里有
解决:右键-->Maven-->Reimport , 搞定

情况1:maven Reposity 仓库里没有,比如一些第三方服务商的库
解决: 将jar包安装到本地仓库 , 见[maven安装及添加本地jar包到maven仓库 ,重新build即可

mybatis的Mapper和xml关联失败,找不到xml文件

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.crocutax.mybatisdemo.mapper.UserMapper.findUserList

    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:225)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)

解决方案:在pom.xml中配置

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

参考 http://blog.csdn.net/shifangwannian/article/details/48882201

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,001评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,974评论 6 342
  • IntellijIDEAWeb部署 目录[-] 1.前言2.项目配置(Project Structure)2.1 ...
    勿以浮沙筑高台阅读 1,995评论 0 7
  • 眼里望着窗外 心里住着一座城 要怎么 安心知足。
    F_llee阅读 378评论 0 0
  • 愿意陪你晚睡 众所周知 早起早睡是好的习惯 那如果你爱上晚睡的人呢? 1 - 爱她就是陪她做她喜欢的事 - 我是程...
    浪迹音乐厅阅读 385评论 0 0