Message Boards

Problem to access files in war

thumbnail
Eunice Silva, modified 2 Years ago.

Problem to access files in war

New Member Posts: 17 Join Date: 9/27/17 Recent Posts

I’m converting an war maven project from Liferay CE 6.2 to Liferay CE 7.3. In this project we access directly to files, mainly xsl but not only, and these files are inside the war. But now we cannot access them because the war is not unpacked / exploded like before, for example in Tomcat 7 webapps folder (in production we are using Liferay 6.2 in Glassfish).

Is there any solution without changing the base of the application? Can’t believe that this functionality disappeared… Am I missing something?

I am steel working in develop environment with bundle Liferay CE 7.3 GA6 - Tomcat. Is beaver in production environment will be the same?

I spouse this´s related to deploying changes also… For every change I made in a java class I must wait to deploy of all app in Liferay. That tacks a lot of time extra… From the little I've seen so far it seems to me that it's the same in a normal module created from scratch and with the Liferay IDE.

Can anyone help me? Even if it is to point me in the way, give me some guidelines?

Miranda Michel, modified 2 Years ago.

RE: Problem to access files in war

New Member Post: 1 Join Date: 6/8/21 Recent Posts

Your question states you are attempting to access a file called parameter.json, while your code excerpt shows parameters.json. Perhaps that discrepancy indicates a typo in your source code?

If not, there are various ways to access a file from the classpath in Spring, with the first step for each being to ensure the file is in the project's src/main/resources directory.

thumbnail
Eunice Silva, modified 2 Years ago.

RE: RE: Problem to access files in war

New Member Posts: 17 Join Date: 9/27/17 Recent Posts

  I'm not trying to acess to parameter.json, so I imagin that you are in rong place.

Cruz Moore, modified 2 Years ago.

RE: Problem to access files in war

New Member Post: 1 Join Date: 6/22/21 Recent Posts

I faced similar kind of issue last time, I am still searching for some proper solution.

thumbnail
Eunice Silva, modified 2 Years ago.

RE: RE: Problem to access files in war

New Member Posts: 17 Join Date: 9/27/17 Recent Posts

Accessing files in war and jar is possible with getClass.getResourceAsStream() like Olaf sad (or getClassLooder.getResourceAsStream()) . Just put the files in the right place, in WEB-INF/classes (if file path/filename start with “/” in GetClass). In my case they aren’t.

thumbnail
Olaf Kock, modified 2 Years ago.

RE: Problem to access files in war

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

You could never rely on a WAR file to be unzipped to disk - it just happens to be the default configuration for Tomcat, so that everybody uses this method and is shocked that there are other ways of accessing data embedded in JAR files (or WAR files for that matter).

Class.getResourceAsStream() is your friend, for any resource that's bundled in your classpath and accessible to your classloader. If you desperately need it on disk, you'll have to extract it to a temporary directory yourself and use that location.