【无标题】

java tomcat maven web项目一些常见错误/需求情况解决方式

1.tomcat输出日志乱码

在idea 界面最上方找到帮助(help) ,编辑自定义VM选项,
请添加图片描述
在.vmoptions里面添加
-Dfile.encoding=UTF-8
-Dconsole.encoding=UTF-8
让idea编码变成UTF-8()
同时在idea设置中把项目编码改为utf-8
请添加图片描述
同时,把tomcat目录下的conf/logging.properties里,.encoding结尾的属性全部改为UTF-8,下图标蓝的部分只是其中一个

请添加图片描述

2. maven加入自己已有的jar包/jar包目录

假设jar包都在项目目录/src/main/resources/lib
在maven的pom.xml中找到 <artifactId>maven-compiler-plugin</artifactId>的plugin,加入设置

  <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
              <extdirs>${project.basedir}/src/main/resources/lib</extdirs>
            </compilerArguments>
          </configuration>

示例

      <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
              <extdirs>${project.basedir}/src/main/resources/lib</extdirs>
            </compilerArguments>
          </configuration>



        </plugin>

3. mysql连接,提示需要设置时区

在sql连接的url中添加参数

jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC

4. 运行项目时,执行到jdbc连接出现init datasource error, url: jdbc:mysql://localhost:3306/test

首先确认mysql-connector-java的jar包版本和mysql版本对应

url里的的test是数据库名称,确认有没有参数useSSL=false,没有的话

只需要设置jdbc连接的地址,在里面加一个参数useSSL=false

jdbc:mysql://localhost:3306/test?useSSL=false

or

jdbc:mysql://localhost:3306/test?useSSL=false&xxxxxxxx

xxxxxxx表示其它的参数

5. 运行tomcat提示8080端口已占用

win+R打开window窗口,输入命令提示符号,执行命令:netstat -ano

找到 TCP 0.0.0.0:8080开头的,找到后面的进程ID,杀死该进程即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值