Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Problem to access files in war
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?
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.
I'm not trying to acess to parameter.json, so I imagin that you are in rong place.
I faced similar kind of issue last time, I am still searching for some proper solution.
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.
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.
Powered by Liferay™