在github上发现了一个想参考的Java Web项目,下载下来发现是myeclipse的项目,试着用VS Code运行,过程中遇到了一些问题,记录一下:
1.作者在源码里提供了数据库相关sql文件,在导入过程中报错,原因是新版mysql开启了严格模式,不再支持日期默认'0000-00-00 00:00:00',例如
`createtime` datetime DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间',
需要修改为:
`createtime` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
2.项目使用了log4j用来记录日志,配置如下:
log4j.appender.file.File=sunjob.log
因为我是macOS环境,所以改了路径,并将权限修改为777。
3.修改jdbc相关连接配置,依然报错:
[apache-tomcat-9.0.33]: java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
[apache-tomcat-9.0.33]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
更新为最新的mysql-connector-java-8.0.19.jar问题解决。
4.继续Debug,报如下错:
Caused by: org.hibernate.search.SearchException: Unable to create index directory: /c:/index for index goods
项目用到了hibernate,搜索c:/index,发现索引文件保存位置设置如下:
<property name="hibernate.search.default.indexBase">
c:/index
</property>
修改路径,并设置对应路径为777权限。
至此,项目终于跑起来了😄