Home > Software engineering >  Using $PROJECT_DIR$ in the path String in IntelliJ Idea
Using $PROJECT_DIR$ in the path String in IntelliJ Idea

Time:10-18

I have a simple question, but I can't find the answer anywhere. I would like to use $PROJECT_DIR$default path variable in IntelliJ.

I wanted to add an icon to the Stage:

stage.getIcons().add(new Image("$PROJECT_DIR$/src/main/resources/com/example/demo/money.png"));

But this doesn't work, unfortunately :(

I tried also using PROJECT_DIR or MODULE_DIR or $MODULE_DIR$, but nothing works. Maybe it's impossible to use those path variables in such way (?). Please, explain it to me.

Using Absolute Path to the image works, but I would like to share my project and that's why I decided to replace it with a path variable.

CodePudding user response:

You don't have to use directory like this one. Intellij already know where is the project.

You have to check according to where will be located the file when it will be exported.

In you case, you have to use :

stage.getIcons().add(new Image("com/example/demo/money.png"));

Because resources are already consider as resources and so will be in main folder in exported jar.

If it failed, you can try with less package, for example put money.png directly in the resource folder

  • Related