java - Get module path not root path in Java
问题描述
I have a multi-module Java(Spring) project, which build by Gradle 6.7.1. And I use in Jetbrain IDEA to develop. The file Structure like this:
root
|--orm
| +---hibernates
|
|--web
|--mvc
|--rest
And then, I have tried some codes in my module project like below, what I get all are root path (/home/user/IdeaProjects/root/
), not module path (/home/user/IdeaProjects/root/web/mvc
). How can I get module path (/home/user/IdeaProjects/root/web/mvc
) ?
new File("").getAbsolutePath()
解决方案
Assuming for instance that your mvc project is setup like this in setting.gradle
, in the root folder :
include 'mvc'
project(':mvc').projectDir = new File('./web/mvc')
Then, to get the path /home/user/IdeaProjects/root/web/mvc
, just try this :
println project(':mvc').projectDir
Will prints :
/home/user/IdeaProjects/root/web/mvc
推荐阅读
- html - Flex-direction:反向列隐藏导航组件
- r - 根据特定列计算重复行的频率,但保留 R 中重复行之一的 ID
- android - 如何从片段中观察数据
- regex - Nginx (Perl) 正则表达式从一个 URL 重新路由到另一个
- php - 将输入值传递到下一页时出错
- javascript - 根据输入表单将页面重定向到不同的 URL
- python - 按月/年分类的分组条形图
- aws-lambda - 用户无权执行:iam:CreatePolicy 对资源:策略 AWSLambdaBasicExecutionRole?
- spring-boot - 为休眠二级缓存 RegionFactory 重用 RedissonClient bean
- c++ - 解析字符串和搜索的问题