How to get the path of Katalon Studio installation folder

I needed to find a way how to get the path of Katalon Studio installation folder programmatically.

I wrote a “Test Case/getInstallationFolder”:

// getInstallationFolder

import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.CodeSource;

import com.kms.katalon.core.configuration.RunConfiguration

public Path getCodeSourcePathOf(Class<?> clazz) {
	CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
	URL url = codeSource.getLocation();
	try {
		return Paths.get(url.toURI());
	} catch (URISyntaxException e) {
		throw new RuntimeException(e);
	}
}

Path jarPath = getCodeSourcePathOf(RunConfiguration.class)
println jarPath.toString()

Path pluginsPath = jarPath.getParent()
Path eclipsePath = pluginsPath.getParent()
Path contentsPath = eclipsePath.getParent()
Path installationFolderPath = contentsPath.getParent()

println installationFolderPath   // on Mac, "/Applications/Katalon Studio.app"

I ran this, got the following output in the console:

2024-06-01 10:43:47.902 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-06-01 10:43:47.906 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/getInstallationFolder
/Applications/Katalon Studio.app/Contents/Eclipse/plugins/com.kms.katalon.core_1.0.0.202310232352.jar
/Applications/Katalon Studio.app
2024-06-01 10:43:48.943 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/getInstallationFolder

On Windows, the folder path will be something different. But no need to change the code. It will run on Linux as well.

1 Like