从命令行打开IntelliJ IDEA及IntelliJ IDEA CE
假设我们有一个springboot项目,使用Maven构建的。当我们使用git clone xxx.git
将项目clone到本地之后,我们怎么打开项目?
打开idea,新建empty project ,然后import from desk ? 太麻烦了。通过配置快捷命令,可以使用idea pom.xml
打开项目。
在用户目录创建一个.idea.sh
,然后输入下面的一段脚本。
cd ~/
touch .idea.sh
vim .idea.sh
输入如下内容,保存退出。
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# were we given a directory?
if [ -d "$1" ]; then
# echo "checking for things in the working dir given"
wd=`ls -1d "$1" | head -n1`
fi
# were we given a file?
if [ -f "$1" ]; then
# echo "opening '$1'"
open -a "$IDEA" "$1"
else
# let's check for stuff in our working directory.
pushd $wd > /dev/null
# does our working dir have an .idea directory?
if [ -d ".idea" ]; then
# echo "opening via the .idea dir"
open -a "$IDEA" .
# is there an IDEA project file?
elif [ -f *.ipr ]; then
# echo "opening via the project file"
open -a "$IDEA" `ls -1d *.ipr | head -n1`
# Is there a pom.xml?
elif [ -f pom.xml ]; then
# echo "importing from pom"
open -a "$IDEA" "pom.xml"
# can't do anything smart; just open IDEA
else
# echo 'cbf'
open "$IDEA"
fi
popd > /dev/null
fi
创建命令别名
vim ~/.zshrc
输入 alias idea="sh ~/.idea.sh"
刷新配置,使生效:
source ~/.zshrc
测试命令行打开Maven项目
cd /path/to/maven_project
idea pom.xml
以上配置无误的话,此时立马就能看到idea启动了,Maven项目已打开。
如果你像我一样,电脑上安装了IDEA CE的话,可以再配置一个ideace
的别名。
跟上面的步骤一样,新建一个 .ideace.sh
,内容跟.idea.sh
的内容一样,只需要改变一行:
IDEA=`ls -1d /Applications/IntelliJ\ IDEA\ CE* | tail -n1`
然后创建一个别名alias ideace="sh ~/.ideace.sh"
。
接下来,便可以使用 ideace pom.xml
来打开项目了。
如果我的文章对你有帮助,欢迎微信支付打赏。

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!