Where do files go when deployed as war on Tomcat

11 views
Skip to first unread message

Ognen Duzlevski

unread,
Sep 11, 2017, 6:04:45 PM9/11/17
to scalatra-user
Hello,

I have a basic example of a Scalatra servlet going where I read a text file and fork it off to be processed in a distributed fashion and results served back via Scalatra. This works from sbt/jetty when I put the file in the base directory of a scalatra project (along side build.sbt and one level up from src, project etc.).

However, when I package the servlet into a war and deploy it on Tomcat, the file is not visible anymore. Where do I put the file so it is accessible?

Thanks!

Naoki Takezoe

unread,
Sep 11, 2017, 8:07:08 PM9/11/17
to scalat...@googlegroups.com
Does your scalatra app reads a file from a relative path on your file system? If yes, you have to put the file in the relative location from the current directory of Tomcat.

But generally, it's not prefered because it depends on an environment.

You should update your app to read a file from a specific absolute path which is provided by configuration, or also it's possible to package a file in a war file by putting it in src/main/resources if you don't need modify that file after packaging. In this case, you can read it with a specific path using ClassLoader.

2017/09/12 7:04 "Ognen Duzlevski" <ognen.d...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "scalatra-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatra-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ognen Duzlevski

unread,
Sep 11, 2017, 8:17:20 PM9/11/17
to scalat...@googlegroups.com
On Mon, Sep 11, 2017 at 8:07 PM, Naoki Takezoe <tak...@gmail.com> wrote:
Does your scalatra app reads a file from a relative path on your file system? If yes, you have to put the file in the relative location from the current directory of Tomcat.

But generally, it's not prefered because it depends on an environment.

You should update your app to read a file from a specific absolute path which is provided by configuration, or also it's possible to package a file in a war file by putting it in src/main/resources if you don't need modify that file after packaging. In this case, you can read it with a specific path using ClassLoader.

Hello, can you be more specific? How do I read a file using ClassLoader?

Thanks! 

Naoki Takezoe

unread,
Sep 12, 2017, 1:18:19 AM9/12/17
to scalat...@googlegroups.com
You can find a lot of examples by searching Google.

Here is good one I found:
http://www.vertigrated.com/blog/2011/02/reading-data-from-a-file-on-the-classpath-in-java/
> --
> You received this message because you are subscribed to the Google Groups
> "scalatra-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalatra-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Naoki Takezoe

Ognen Duzlevski

unread,
Sep 12, 2017, 7:41:44 AM9/12/17
to scalat...@googlegroups.com
Thanks! :)


> For more options, visit https://groups.google.com/d/optout.



--
Naoki Takezoe

--
You received this message because you are subscribed to a topic in the Google Groups "scalatra-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalatra-user/c-pdm2r3R2k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalatra-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages