0

I have a maven application running on tomcat, I start it using cargo:

mvn cargo:run

Inside the webapps folder, there is a symlink that points to an important folder:

ls /usr/local/Cellar/tomcat/8.0.15/libexec/webapps/ROOT/WEB-INF/views
admin   898 Jul 21  2016 notImplemented.jsp
admin  3355 Oct  3 15:13 genericError.jsp
admin    41 Mar 21 18:43 vhosts -> /Users/me/Project/important/folder   <<<<<< HERE

The problem is that when I start the server, tomcat follow the symlink and delete everything contained in the folder.

When I start tomcat via intellij, there is no issue. I noticed from the logs that the deletion is occurring at line 4 (Trying to delete WAR from /ROOT):

1 [INFO] [stalledLocalDeployer] Undeploying context [] from [/usr/local/Cellar/tomcat/8.0.15/libexec/webapps]...
2 [INFO] [stalledLocalDeployer] The WAR file has its context set to / and will therefore be deployed as ROOT.war
3 [INFO] [stalledLocalDeployer] Trying to delete WAR from     [/usr/local/Cellar/tomcat/8.0.15/libexec/webapps/ROOT.war]...
4 [INFO] [stalledLocalDeployer] Trying to delete WAR from [/usr/local/Cellar/tomcat/8.0.15/libexec/webapps/ROOT]...
5 [INFO] [stalledLocalDeployer] Deploying [/Users/.....war] to [/usr/local/Cellar/tomcat/8.0.15/libexec/webapps]...
6 [INFO] [stalledLocalDeployer] The WAR file has its context set to / and will therefore be deployed as ROOT.war

I am running tomcat 8.0.15 on OSX 10.11.3 and use cargo-maven2-plugin v1.6.1.

Could you please suggest a solution to prevent symlinks content to be deleted when tomcat is starting ? Thanks

Solution

At the end, I am deleting all the symlinks contained inside tomcat working directory before starting tomcat. It fixes the problem.

find ${TOMCAT_HOME}/webapps -type l -delete
  • I ran into this problem too. I had a folder of images I wanted to use and it kept getting deleted as I developed the web app. My solution was to put the image folder into the web app war file. Not ideal at all but it worked and saved me from having to recreate the link every time I deployed. Perhaps someone else has a better suggestion. – mba12 Mar 21 '17 at 19:55
  • Thanks a lot for your proposal. Unfortunately, my symlinks are pointing to several big projects that cannot be embedded inside the war. – David Wasa Mar 22 '17 at 09:18
  • Then I would build a script into your app that reestablishes the symlinks each time the app is deployed. Best I know there is no way around the problem. – mba12 Mar 22 '17 at 15:27
  • I already have a script that reestablishes the symlinks when the app is deployed. The issue is not to have the symlinks deleted, but that everything inside the symlink target is erased. – David Wasa Mar 22 '17 at 16:08
  • Everything inside my symlink targets got deleted too. To clarify my answer what I did in my script was to maintain a backup copy of my images (which I needed anyway) and when I deployed both create new symlinks and recopy the images into the folders. It's a real pain but the only thing I found that actually worked. Was hoping someone else had a better idea! – mba12 Mar 22 '17 at 17:18

0 Answers0