<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF Port</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111020390" />
  <subtitle>Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF Port</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111020390</id>
  <updated>2026-04-04T11:15:40Z</updated>
  <dc:date>2026-04-04T11:15:40Z</dc:date>
  <entry>
    <title>RE: Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111024275" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111024275</id>
    <updated>2018-09-25T03:53:12Z</updated>
    <published>2018-09-25T03:53:12Z</published>
    <summary type="html">&lt;blockquote&gt;
  &lt;div class="quote-title"&gt;Abuzar Rana:&lt;/div&gt;
  &lt;div class="quote"&gt;
    &lt;div class="quote-content"&gt;
      &lt;p&gt;I'm trying to keep (store) files into
        $TOMCAT_HOME/webapps/projectnamefolder/temp I've created folder
        manually inside webapps because I'm storing files into that folder.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;This is completely discouraged and very much unsupported by app
  servers. The webapp is not meant to be yours to to modify, it is the
  purview of the application server itself.&lt;/p&gt;
&lt;p&gt;Tomcat has always been known to be a little lax at its assertion of
  ownership on that folder allowing, for example, direct modification to
  files in the exploded war directory.&lt;/p&gt;
&lt;p&gt;That said, you still shouldn't do it.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2018-09-25T03:53:12Z</dc:date>
  </entry>
  <entry>
    <title>RE: Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111023512" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111023512</id>
    <updated>2018-09-24T20:59:10Z</updated>
    <published>2018-09-24T20:59:10Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi Abuzar,&lt;br&gt; I recently did a project where I needed to use a
  temporary folder to store some things on the file system. To create
  the temp folder I used:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code class="hljs mathematica"&gt;&amp;lt;span class="hljs-keyword"&amp;gt;Path&amp;lt;/span&amp;gt; newTempDir&amp;amp;nbsp;= Files.createTempDirectory(&amp;lt;span class="hljs-string"&amp;gt;"newTempDirPrefix"&amp;lt;/span&amp;gt;);
&amp;lt;span class="hljs-keyword"&amp;gt;File&amp;lt;/span&amp;gt; newTempFile = new &amp;lt;span class="hljs-keyword"&amp;gt;File&amp;lt;/span&amp;gt;(newTempDir, &amp;lt;span class="hljs-string"&amp;gt;"newTempFile.txt"&amp;lt;/span&amp;gt;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above&amp;nbsp;code&amp;nbsp;creates a&amp;nbsp;temporary folder in the location defined by
  the&amp;nbsp;&lt;code&gt;java.io.tmpdir&lt;/code&gt; system property.&lt;/p&gt;
&lt;p&gt;But I could have also used the app server temp dir property (and that
  might be a better option):&lt;/p&gt;
&lt;pre class="prettyprint"&gt;
&lt;code class="hljs avrasm"&gt;File tempDir = (File) FacesContext&amp;lt;span class="hljs-preprocessor"&amp;gt;.getCurrentInstance&amp;lt;/span&amp;gt;()
    &amp;lt;span class="hljs-preprocessor"&amp;gt;.getExternalContext&amp;lt;/span&amp;gt;()&amp;lt;span class="hljs-preprocessor"&amp;gt;.getApplicationMap&amp;lt;/span&amp;gt;()&amp;lt;span class="hljs-preprocessor"&amp;gt;.get&amp;lt;/span&amp;gt;(ServletContext&amp;lt;span class="hljs-preprocessor"&amp;gt;.TEMPDIR&amp;lt;/span&amp;gt;)&amp;lt;span class="hljs-comment"&amp;gt;;&amp;lt;/span&amp;gt;
File newTempFile = new File(tempDir, &amp;lt;span class="hljs-string"&amp;gt;"newTempFile.txt"&amp;lt;/span&amp;gt;)&amp;lt;span class="hljs-comment"&amp;gt;;&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there a reason that you cannot use one of these&amp;nbsp;techniques?&lt;/p&gt;
&lt;p&gt;For more information on creating and using temporary directories in
  web/portlet applications, check out this excellent StackOverflow post
  by BalusC:&amp;nbsp;&lt;a href="https://stackoverflow.com/questions/31255366/how-to-save-generated-file-temporarily-in-servlet-based-web-application"&gt;https://stackoverflow.com/questions/31255366/how-to-save-generated-file-temporarily-in-servlet-based-web-application&lt;/a&gt;.
  It's also worth checking out his related Q&amp;amp;A on
  &lt;code&gt;getRealPath()&lt;/code&gt; (he essentially says that you should never
  use &lt;code&gt;getRealPath()&lt;/code&gt;):&amp;nbsp;&lt;a href="https://stackoverflow.com/questions/12160639/what-does-servletcontext-getrealpath-mean-and-when-should-i-use-it"&gt;https://stackoverflow.com/questions/12160639/what-does-servletcontext-getrealpath-mean-and-when-should-i-use-it&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;- Kyle&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-24T20:59:10Z</dc:date>
  </entry>
  <entry>
    <title>RE: Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111023482" />
    <author>
      <name>Abuzar Rana</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111023482</id>
    <updated>2018-09-24T20:23:48Z</updated>
    <published>2018-09-24T20:23:48Z</published>
    <summary type="html">&lt;p&gt;Hi Kyle,&lt;/p&gt;
&lt;p&gt;Thanks for the reply. I'm trying to keep (store) files into
  $TOMCAT_HOME/webapps/projectnamefolder/temp I've created folder
  manually inside webapps because I'm storing files into that folder.
  But as you mentioned above getRealPath() will always return null from
  this method. You said absolutely right in the above comment.&lt;/p&gt;
&lt;p&gt;
  &lt;br /&gt;
  &lt;strong&gt;My problem is that I want to store files into temp folder if I
    create temp folder inside the project hierarchy then still I'm
    unable to find &lt;br /&gt; the path of project temp folder.&lt;/strong&gt;
  After store the files into temp folder I need to access these files
  from that folder as well.&lt;/p&gt;
&lt;p&gt;
  &lt;b&gt;What should I need to do for getting the path of temp folder even
    this temp folder is inside project hierarchy or inside webapps folder ?&lt;/b&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Thanks in advance. &lt;/p&gt;</summary>
    <dc:creator>Abuzar Rana</dc:creator>
    <dc:date>2018-09-24T20:23:48Z</dc:date>
  </entry>
  <entry>
    <title>RE: Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111022052" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111022052</id>
    <updated>2018-09-24T15:16:28Z</updated>
    <published>2018-09-24T15:16:28Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hi Abuzar,&lt;br&gt; The JavaDoc for &lt;u&gt;
    &lt;a href="https://portals.apache.org/pluto/portlet-3.0-apidocs/javax/portlet/PortletContext.html#getRealPath-java.lang.String-"&gt;&lt;code&gt;PortletContext.getRealPath()&lt;/code&gt;&lt;/a&gt;&lt;/u&gt; states:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;This method returns &lt;code&gt;null&lt;/code&gt; if the portlet container
    cannot translate the virtual path to a real path for any reason
    (such as when the content is being made available from a
    &lt;code&gt;.war&lt;/code&gt; archive).&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Liferay 7.0 handles WARs itself rather than deploying them to the
  application server, so if you take a look in the &lt;strong&gt;
    &lt;code&gt;$TOMCAT_HOME/webapps&lt;/code&gt;&lt;/strong&gt; folder, you’ll see that
  your WAR is not there. Instead it is in the&amp;nbsp;&lt;strong&gt;
    &lt;code&gt;$LIFERAY_HOME/osgi/war&lt;/code&gt;&lt;/strong&gt;&amp;nbsp;folder. Since the
  file(s) you are looking for are being served from a WAR archive
  (rather than the file system or an exploded war),
  &lt;code&gt;getRealPath()&lt;/code&gt; will always return &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you provide some more context about what you are trying to do (and
  perhaps an&amp;nbsp;&lt;a href="https://sscce.org"&gt;SSCCE&lt;/a&gt;),&amp;nbsp;we might be able
  to&amp;nbsp;give you&amp;nbsp;a different solution.&lt;/p&gt;
&lt;p&gt;- Kyle&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-24T15:16:28Z</dc:date>
  </entry>
  <entry>
    <title>Moved to the Liferay Faces - English category.</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111022026" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111022026</id>
    <updated>2018-09-24T15:05:05Z</updated>
    <published>2018-09-24T15:05:05Z</published>
    <summary type="html">Moved to the Liferay Faces - English category.</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-09-24T15:05:05Z</dc:date>
  </entry>
  <entry>
    <title>Unable to get the real path (tomcat/webapps/any folder) Liferay7.0 JSF Port</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111020389" />
    <author>
      <name>Abuzar Rana</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111020389</id>
    <updated>2018-09-24T11:11:15Z</updated>
    <published>2018-09-24T11:11:15Z</published>
    <summary type="html">&lt;p&gt;Hi everyone,&lt;/p&gt;
&lt;p&gt;I'm unable to get the real path of tomcat webapps folder in Liferay
  7.0 using JSF Portlet. &lt;strong&gt;Below is the code which I've tried from
    different ways&lt;br /&gt; to get the path but this code returns the null value. &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Method 1:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;String path =
  FacesContext.getCurrentInstance().getExternalContext().getRealPath(&amp;quot;&amp;quot;);
  // return null&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Method 2:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;PortletRequest req = (PortletRequest)
  FacesContext.getCurrentInstance().getExternalContext().getRequest();&lt;br /&gt;
  PortletContext pc = req.getPortletSession().getPortletContext();&lt;br /&gt;
  String path = pc.getRealPath(&amp;quot;.&amp;quot;);  //Even I've given the
  exact folder name instead of dot but no luck.&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;How can I get the real path of tomcat webapps folder in
    Liferay 7.0 using JSF Portlet any suggestions?&lt;/strong&gt; Thanks in Advance.&lt;/p&gt;</summary>
    <dc:creator>Abuzar Rana</dc:creator>
    <dc:date>2018-09-24T11:11:15Z</dc:date>
  </entry>
</feed>
