Intellij IDEA配置maven环境变量

有时候项目中会使用到tools.jar,一般我们会在maven的pom文件中配置:

1
2
3
4
5
6
7
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>

一般公司的服务器上的jAVA_HOME是固定的,而大家电脑上的JAVA_HOME很可能不一样,那么在使用maven clean命令的时候很可能会出现下面的异常:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/bin/java -Dvisualvm.id=106646863982958 -Dmaven.multiModuleProjectDirectory=/Users/xkrivzooh/IdeaProjects/bistoury "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-Dmaven.ext.class.path=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven-event-listener.jar" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=49260:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds.license:/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.6.0.jar" org.codehaus.classworlds.Launcher -Didea.version2020.1.1 --update-snapshots clean
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${JAVA_HOME}/lib/tools.jar @ line 133, column 16
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.wormpex.fd:bistoury-ui:1.0.0 (/Users/xkrivzooh/IdeaProjects/bistoury/bistoury-ui/pom.xml) has 1 error
[ERROR] 'dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${JAVA_HOME}/lib/tools.jar @ line 133, column 16
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

其中的'dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${JAVA_HOME}/lib/tools.jar @ line 133, column 16提示我们需要一个绝对路径,那么就是${JAVA_HOME}
没有被识别,我们可以在idea的maven中设置一下环境变量来解决这个事情:

IDEA为maven设置环境变量

保存之后在执行一下maven clean就会发现成功了。当然了你也可以设置全局环境变量来解决这个问题。

Intellij IDEA中搜索yaml中的key

因yaml文件相比于properties文件来结构更加清晰,所以现在无论是公司项目中还是开源的项目中,yaml文件越来越常见。
曾经的特别讨厌使用yaml文件主要是因为搜索yaml文件中的key的时候太麻烦:

比如有下面的yaml文件:

1
2
3
wsearch:
zk:
address: xxxxxxxx

在Idea中使用Command+Shitf+F搜索wsearch.zk.address的时候是搜索不到的

就因为这个原因,导致我特别的厌烦yaml的配置。

今天才发现原来在IDEA可以使用如下的方式搜索到。那就是使用Idea的Search everywhere功能。按2下shift,然后在搜索就好了:

发现在Stack Overflow也有人问这个问题How to find specific property key in a yaml file using intellij idea?

Intellij IDEA 2019.2 对http client的功能增强

在Intellij IDEA 2019.2中对http client的功能进行了增强,主要有2个:

  • HTTP client supports cURL requestsULTIMATE
  • HTTP client keeps cookies

HTTP client supports cURL requestsULTIMATE

Now you can paste a cURL request string into the HTTP client and have the IDE automatically convert it to a full request.

https://www.jetbrains.com/idea/whatsnew/2019-2/img/RESTClient.gif

HTTP client keeps cookies

Suppose you’ve made one request to authenticate on the service, and in subsequent requests you would like to call some endpoints that require additional permissions. Previously, you would lose the cookies from the first response. But not anymore: the IDE now keeps all the cookies for you and transfers them in the next requests.

https://www.jetbrains.com/idea/whatsnew/2019-2/img/HTTPCookies.gif

以及早期的对http client 中host的支持。

比如http-client.env.json文件内容为:

1
2
3
4
5
6
7
8
{
"local": {
"host": "http://localhost:8080"
},
"dev":{
"host" : "http://xxx.xxx.xxx.250:10000"
}
}

你可以在.http文件中这么使用:

1
2
3
4
5
6
7
POST {{host}}/xxxxxx/v1
Content-Type: application/json
x

{
"a" : 1
}

参考资料

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×