Custom Java Components - Accessing Workspace Directory

Hi,

I have a Custom Java Component that collects a file from my project workspace for processing based on an input port field value. Everything works fine, however, in order to access the file I need to provide the full file path from my C Drive despite the file sitting in a project directory. This is inconvenient as if I ever move the component to a different project I would need to rekey in the project location.

Here is a snippet of my current code

String WorkingFolder = "C:/Users/<My User>/clover_workspace/<clover project>";
		String Dir = getProperties().getStringProperty("Directory");
		
		DataRecord inRecord = inRecords[0];
		DataRecord outRecord = outRecords[0];
		
		while ((inRecord = readRecordFromPort(0)) != null) {
			
			String fileUrl = WorkingFolder+Dir+inRecord.getField(0).getValue().toString();
...

Is there a more elegant way to achieve this? I tried using the project Graph Parameter via graph.getGraphParameters() but it returns “.” as opposed to the full file path.

Thanks,
Paul

Hi,

After some more exploration of the graph parameters I found SANDBOX_ROOT which gives me the path I was looking for.

String WorkingFolder = getGraph().getGraphParameters().getGraphParameter("SANDBOX_ROOT").getValue();

Paul

Hi Paul,

Yes, the SANDBOX_ROOT parameter is exactly what I would suggest in your case. You can find the list of parameters on the following page:
https://doc.cloverdx.com/latest/server/graph-parameters.html
Please don’t get confused by the fact that this documentation page points to the Server related topic. These parameters can be all used by the Designer as well.

Have a nice day, Eva