Forums de discussion

StartupAction - Importing Files

Darek B, modifié il y a 10 années.

StartupAction - Importing Files

New Member Publications: 4 Date d'inscription: 26/06/13 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?


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

Returns the system account's home directory.

Thanks
thumbnail
Krzysztof Gołębiowski, modifié il y a 10 années.

RE: StartupAction - Importing Files (Réponse)

Liferay Master Publications: 549 Date d'inscription: 25/06/11 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, modifié il y a 10 années.

RE: StartupAction - Importing Files

New Member Publications: 4 Date d'inscription: 26/06/13 Publications récentes
Thanks for the quick response.

Going the classloader route works but I'll try the Ugrade Process approach.
thumbnail
Krzysztof Gołębiowski, modifié il y a 10 années.

RE: StartupAction - Importing Files

Liferay Master Publications: 549 Date d'inscription: 25/06/11 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).