Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Darek B
StartupAction - Importing Files
5 novembre 2013 06:54
Réponse

Darek B

Rang: New Member

Publications: 4

Date d'inscription: 26 juin 2013

Publications Récentes

Hi,

I would like to import documents located in the WEB-INF directory of my portlet app using a Startup Action. I cannot find a Util class that will return a relative path to the source directory. Has anyone come across this?

1
2    public void run(String[] ids) throws ActionException {
3        // ...
4        File dir = new File(".");
5        System.out.println("Current dir : " + dir.getAbsolutePath());
6    }

Returns the system account's home directory.

Thanks
Krzysztof Gołębiowski
RE: StartupAction - Importing Files
5 novembre 2013 07:04
Réponse

Krzysztof Gołębiowski

Rang: Liferay Master

Publications: 508

Date d'inscription: 25 juin 2011

Publications Récentes

You can use this instruction

InputStream is = PortletClass.class.getClassLoader().getResourceAsStream("filename")

It gets file from main folder of plugin classloader (you need to copy files to 'src' folder before building plugin).

Howewer it is better to load files with UpgradeProcess (you need to create Hook for this) or via ResourcesImporter (https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/6-1-importing-resources-with-themes).
Darek B
RE: StartupAction - Importing Files
5 novembre 2013 07:37
Réponse

Darek B

Rang: New Member

Publications: 4

Date d'inscription: 26 juin 2013

Publications Récentes

Thanks for the quick response.

Going the classloader route works but I'll try the Ugrade Process approach.
Krzysztof Gołębiowski
RE: StartupAction - Importing Files
5 novembre 2013 08:36
Réponse

Krzysztof Gołębiowski

Rang: Liferay Master

Publications: 508

Date d'inscription: 25 juin 2011

Publications Récentes

You can check how it is done in Knowledge Base plugin. There is a portlet and hook with upgradeProcess within one plugin (https://github.com/liferay/liferay-plugins/tree/master/portlets/knowledge-base-portlet).