iT邦幫忙

1

古典 java tomcat server 專案 dockerize 踩坑全記錄

如標題所述,這裡分享的 java tomcat server 專案具有以下特點:

  1. JDK 8 的開發環境
  2. 非 maven 專案
  3. 非 gradle 專案
  4. 絕對不是 spring boot 專案 /images/emoticon/emoticon16.gif

https://ithelp.ithome.com.tw/upload/images/20211103/20109107ZIZx3dNJdH.png

----- 以下開始採坑全記錄!

MacBook-Pro ~ % docker run -d --name=tomcat-ithelp -p 8088:8080 tomcat:9.0-jdk8-openjdk 

https://ithelp.ithome.com.tw/upload/images/20211103/20109107LhVGPc7ZLM.png
container 長出來後,興沖沖地在 safari 鍵入 localhost:8088
https://ithelp.ithome.com.tw/upload/images/20211103/20109107ibhNC7RwDp.png
/images/emoticon/emoticon20.gif

解決方法:

https://ithelp.ithome.com.tw/upload/images/20211103/201091077ttFZ4zhwZ.png
https://ithelp.ithome.com.tw/upload/images/20211103/201091077OUaDwqaNF.png
看起來正常了!/images/emoticon/emoticon12.gif
既然 docker image 是宣稱 tomcat:9.0-jdk8-openjdk
https://ithelp.ithome.com.tw/upload/images/20211103/20109107hGIJVU3u1w.png
確實是 java 8。/images/emoticon/emoticon12.gif
接下來把專案檔 managerWeb.war 複製一份到 container 的 webapps 目錄下。

MacBook-Pro ~ % docker cp ~/managerWeb/managerWeb.war tomcat-ithelp:/usr/local/tomcat/webapps

container log 噴錯了!
https://ithelp.ithome.com.tw/upload/images/20211103/20109107KmUqPlS1Ao.png
『 Failed to instantiate [com.mchange.v2.c3p0.ComboPooledDataSource]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError』

解決方法:

https://ithelp.ithome.com.tw/upload/images/20211103/20109107e4oRHTl139.png

RESTART container 後,繼續噴錯!/images/emoticon/emoticon20.gif
https://ithelp.ithome.com.tw/upload/images/20211103/201091074dLrYCrHnM.png
『com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure』

解決方法:

https://ithelp.ithome.com.tw/upload/images/20211103/201091073kjx4uHuep.png

RESTART container 後,繼續噴錯!/images/emoticon/emoticon02.gif
https://ithelp.ithome.com.tw/upload/images/20211103/20109107hvq8NGHleW.png
『Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext/applicationContext-sessionFactory.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name()Ljava/lang/String;』

經過google大神的指點後,
直接刪除 WEB-INF/lib 下的 persistence.jar
https://ithelp.ithome.com.tw/upload/images/20211103/20109107LUj4ojGuaR.png
總算 ... /images/emoticon/emoticon01.gif
https://ithelp.ithome.com.tw/upload/images/20211104/201091074nUW7CPMS9.png

後記:
這篇主要是寫給未來的自己看的。
未來再處理到這種 Jar 檔沒有控管的專案,只好耐心地把這堆有衝突的 Jar 檔逐步移除了。
/images/emoticon/emoticon32.gif


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言