Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.getProperty("user.dir") does not work

Tags:

java

I need to get relative path from my project to upload photos, however when I run System.getProperty("user.dir"); in my test, it returns /home/user/workspace/Myproject, but if I run it from my spring controller, it just returns /home/user.

Can anyone provide a insight that probably is happening?

like image 405
Danilo M. Avatar asked Nov 30 '22 23:11

Danilo M.


1 Answers

The user.dir property is the current working directory where you are running Java. You're starting java in /home/user/workspace/Myproject when you run your project but when Spring runs it, it's not guaranteed to be the same working directory. Are you looking for user.home (which should always be /home/user) instead?

like image 81
Jon Lin Avatar answered Dec 09 '22 12:12

Jon Lin