How to get current project directory path using a microflow or java action?

0
I have a file which I have added in project_directory/resources folder. I want to access that file using FileDocumentFromFile java action. For this to work I need to pass in full file path of the file that I want to get contents of. Providing relative paths isn’t working but when absolute path is provided then it works.   Is there any way to get the project directory path via a microflow or javaaction ?  
asked
1 answers
5

You might want to use a JavaAction to get the resource path. Have a look at the package com.mendix.cor.conf, Interface Configuration, method getResourcesPath():

https://apidocs.rnd.mendix.com/8/runtime/com/mendix/core/conf/Configuration.html#getResourcesPath

  1. Create a new JavaAction in Studio Pro, call it “JA_GetResourcePath”. Set Return Type to “String”
  2. Deploy for Eclipse
  3. Import the project in Eclipse
  4. Navigate to the javasource folder and search for the package with the same name as the Mendix module where you created the Java Action in, appended by “.actions” (e.g. “MyFirstModul.actions”)
  5. Open “JA_GetResourcesPath.java” and add line “import com.mendix.core.Core;” in the import section
  6. Replace the line between // BEGIN USER CODE and // END USER CODE with this: 
    return Core.getConfiguration().getResourcesPath().toString()

     

The Java Action in Mendix Studio Pro should look like this:

And in Eclipse like this:

answered