Maven 运行 Spring Boot:mvn spring-boot:run 常见错误与多模块 ${revision} 问题

基本命令 在 Spring Boot 项目根目录执行: mvn spring-boot:run常用选项: # 跳过测试(开发时推荐) mvn spring-boot:run -DskipTests# 指定激活 profile mvn spring-boot:run -Dspring-boot.run.profiles=dev# 组合使用 mvn spring-boot:run -DskipTests -Dspring-boot.run.profiles=dev启动成功标志: Started XxxApplication in 3.421 seconds (process running for 4.012)打包后运行(生产推荐) mvn clean package -DskipTests java -jar target/xxx-0.0.1-SNAPSHOT.jar打包出的 fat jar 包含所有依赖,可在任意安装了 JRE 的机器上运行。 错误一:mvn 不是内部或外部命令 Maven 未加入 PATH,测试: mvn -v如果报错,检查 MAVEN_HOME 和 PATH 配置,重开终端或重启后重试。 错误二:No plugin found for prefix 'spring-boot' pom.xml 缺少 Spring Boot Maven 插件: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>如果项目继承了 spring-boot-starter-parent,插件版本已由父 POM 管理,不需要指定版本号。 错误三:多模块项目 ${revision} 无法解析 多模块项目使用 ${revision} 占位符统一版本号时: [ERROR] Could not find artifact net.xxx:parent:pom:${revision}根因是运行命令的子模块还没安装父 POM 到本地仓库。解决方法: 从根目录先执行 install: # 进入多模块根目录(有最顶层 pom.xml 的目录) cd /path/to/root# 安装所有模块到本地仓库 mvn clean install -DskipTests安装后再进入子模块运行: cd maku-server mvn spring-boot:run -DskipTests或直接在根目录指定子模块: mvn spring-boot:run -pl maku-server -am -DskipTests-pl 指定目标模块,-am 同时构建依赖的模块。 端口占用 # Windows netstat -ano | findstr 8080 taskkill /PID <PID> /F# Linux lsof -i :8080 kill -9 <PID>或在 application.yml 修改端口: server: port: 8081

Maven 跑 Spring Boot 常用命令 + 依赖解析失败排查

Spring Boot 项目用 Maven 跑,其实就三个常用命令。但组合起来 + 遇到依赖冲突时坑不少。 三个常用命令 开发时启动: mvn spring-boot:run看到 Started XxxApplication in x.xxx seconds 就通了。 跳过测试加速启动: mvn spring-boot:run -DskipTests老项目测试跑几分钟是常态,开发时基本都会跳。 指定环境: mvn spring-boot:run -Dspring-boot.run.profiles=dev读 application-dev.yml 里的配置。多环境就用这个切。 打包 + 运行 生产部署更常用两步走: mvn clean package -DskipTests java -jar target/*.jar产物是 fat jar(Spring Boot 把依赖都塞里面),直接 java -jar 起就行。加参数: java -jar target/myapp.jar \ --spring.profiles.active=prod \ --server.port=8081后台跑用 nohup: nohup java -jar target/myapp.jar > app.log 2>&1 &生产建议走 systemd 或 Docker,不是裸 nohup。 常见问题 1. mvn 不是内部或外部命令 PATH 没配好。先确认: mvn -v不通就照 Windows 追加目录到 PATH 里的方法把 MAVEN_HOME\bin 加进去。改完 新开一个终端 或注销重登。 2. No plugin found for prefix 'spring-boot' pom.xml 里没引 Spring Boot 插件。加: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>spring-boot-starter-parent 已经管好版本,不用写 version。没继承 parent 的话就得写。 3. 端口占用 Web server failed to start. Port 8080 was already in use.先查是谁: netstat -ano | findstr 8080 # Windows lsof -i:8080 # Linux/Mac杀掉: taskkill /PID 12345 /F或者改端口: server: port: 80814. artifact ${revision} not found 碰到这种: Could not find artifact net.maku:maku-boot:pom:${revision} in public问题不在 Maven 仓库、不在网络。是这个项目用了 Maven 的 CI Friendly Versions 特性——pom.xml 里的版本号写成 ${revision}: <version>${revision}</version>需要在根 pom.xml 里定义: <properties> <revision>4.11.0</revision> </properties>或者启动时传: mvn spring-boot:run -Drevision=4.11.0推荐:用 flatten-maven-plugin 生成扁平化的 pom: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>1.6.0</version> <configuration> <flattenMode>resolveCiFriendliesOnly</flattenMode> </configuration> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals><goal>flatten</goal></goals> </execution> <execution> <id>flatten.clean</id> <phase>clean</phase> <goals><goal>clean</goal></goals> </execution> </executions> </plugin>之后 mvn install 会先把 ${revision} 替换成真实版本再安装到本地库,其它模块拉的时候就不会崩了。 5. 依赖下载慢 Maven 默认仓库在国外,换阿里云或华为云: ~/.m2/settings.xml: <settings> <mirrors> <mirror> <id>aliyun</id> <mirrorOf>central</mirrorOf> <url>https://maven.aliyun.com/repository/central</url> </mirror> </mirrors> </settings>一次配好,永久生效。 6. 开发热重载 Spring Boot 自带 devtools: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>IDEA 里要开 "Build project automatically" + "Registry: compiler.automake.allow.when.app.running",代码保存自动 recompile + restart。 一句话总结 开发用 mvn spring-boot:run -DskipTests、生产用 mvn clean package + java -jar。${revision} 报错是 CI Friendly Versions,加 flatten 插件解决。

Windows 配置 Maven PATH 并用 mvn 运行 Spring Boot

PowerShell 添加 Maven 到 PATH 当前用户(永久) $addPath = "D:\soft\apache-maven-3.9.15\bin" $currentPath = [Environment]::GetEnvironmentVariable("Path", "User")if ($currentPath -notlike "*$addPath*") { [Environment]::SetEnvironmentVariable("Path", "$currentPath;$addPath", "User") Write-Host "已追加: $addPath" } else { Write-Host "PATH 已存在" }当前会话立即生效 $env:Path += ";D:\soft\apache-maven-3.9.15\bin"重新打开终端才能读到写入注册表的值,不想重开就用这行临时追加。 系统级 PATH(需管理员) $addPath = "D:\soft\apache-maven-3.9.15\bin" $currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")if ($currentPath -notlike "*$addPath*") { [Environment]::SetEnvironmentVariable("Path", "$currentPath;$addPath", "Machine") }cmd 添加 Maven 到 PATH :: 追加到当前用户 PATH(永久,写注册表) setx PATH "%PATH%;D:\soft\apache-maven-3.9.15\bin":: 当前窗口立即可用 set PATH=%PATH%;D:\soft\apache-maven-3.9.15\bin系统 PATH(需管理员): setx /M PATH "%PATH%;D:\soft\apache-maven-3.9.15\bin"setx 会写注册表,当前窗口不生效,重新打开 cmd 后验证: mvn -v用 mvn 运行 Spring Boot 在项目根目录(有 pom.xml 的那层)执行: mvn spring-boot:run常用参数: # 跳过测试(开发时推荐,速度快) mvn spring-boot:run -DskipTests# 指定 profile mvn spring-boot:run -Dspring-boot.run.profiles=dev打包后运行 mvn clean package -DskipTests java -jar target/xxx.jar生产部署通常用这种方式,不依赖 Maven 运行时。 常见错误 mvn 不是内部或外部命令 PATH 没生效。执行 mvn -v 测试,不行就重新打开终端,或确认 Maven bin 目录路径是否正确。 No plugin found for prefix 'spring-boot' pom.xml 缺少 Spring Boot Maven 插件,在 <build> 里加: <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>端口 8080 被占用 netstat -ano | findstr 8080 taskkill /PID 进程ID /F或在 application.yml 改端口: server: port: 8081多模块项目依赖解析失败 ${revision} 未替换说明父 pom 没有先 install,在项目根执行: mvn clean install -N -DskipTests-N 表示只安装父 pom,不递归子模块,之后再正常 mvn spring-boot:run。

Windows 追加目录到 PATH:CMD 和 PowerShell 的正确姿势

Windows 上装完 Maven / Java / Python,最常做的一件事就是把 bin 目录塞进 PATH。老一辈教程都写 setx PATH "%PATH%;...",看着能跑,实际有个特别坑的边界。 CMD 方式:setx 追加到当前用户 PATH: setx PATH "%PATH%;D:\soft\apache-maven-3.9.15\bin"追加到系统 PATH(需要管理员 CMD): setx /M PATH "%PATH%;D:\soft\apache-maven-3.9.15\bin"新开的 CMD 才能读到。当前窗口立即用: set PATH=%PATH%;D:\soft\apache-maven-3.9.15\bin mvn -vsetx 的两个坑 1. 会展开 %PATH%,把用户和系统 PATH 混起来 %PATH% 在 CMD 里是 系统 + 用户 PATH 的合并结果。你 setx PATH "%PATH%;X" 会把两份合起来写到用户 PATH 里,重复且混乱。 2. 1024 字符截断 setx 有个硬伤:值超过 1024 字符会静默截断。老系统 PATH 已经很长,一次 setx 直接把后半段吞掉。 PowerShell 方式(推荐) [Environment]::SetEnvironmentVariable 更精确——读用户就读用户、写用户就写用户,也没 1024 字符限制。 追加到当前用户 PATH: $addPath = "D:\soft\apache-maven-3.9.15\bin" $current = [Environment]::GetEnvironmentVariable("Path", "User")if ($current -notlike "*$addPath*") { [Environment]::SetEnvironmentVariable("Path", "$current;$addPath", "User") Write-Host "已追加:$addPath" } else { Write-Host "PATH 已存在该目录" }-notlike "*X*" 防止重复添加 "User" 参数明确只改用户 PATH,不动系统 PATH追加到系统 PATH(管理员 PowerShell): $addPath = "D:\soft\apache-maven-3.9.15\bin" $current = [Environment]::GetEnvironmentVariable("Path", "Machine") if ($current -notlike "*$addPath*") { [Environment]::SetEnvironmentVariable("Path", "$current;$addPath", "Machine") }当前会话立刻生效: $env:Path += ";D:\soft\apache-maven-3.9.15\bin" mvn -v通用检查 # 看用户 PATH [Environment]::GetEnvironmentVariable("Path", "User") -split ";"# 看系统 PATH [Environment]::GetEnvironmentVariable("Path", "Machine") -split ";"# 看合并后的 PATH $env:Path -split ";"去重: $env:Path -split ";" | Where-Object { $_ } | Sort-Object -Unique移除某条 用户 PATH 里删掉某条: $remove = "D:\soft\apache-maven-3.9.15\bin" $paths = ([Environment]::GetEnvironmentVariable("Path","User") -split ";") | Where-Object { $_ -ne $remove -and $_ } [Environment]::SetEnvironmentVariable("Path", ($paths -join ";"), "User")一句话总结CMD 只是想加一条:setx PATH "%PATH%;X",小心 1024 截断 认真加:管理员 PowerShell + [Environment]::SetEnvironmentVariable 显式指定 User/Machine 加完记得新开终端才能读到;当前窗口用 $env:Path += ";X"

YOLO 推理结果解读:置信度阈值、NMS 调参与工程部署建议

YOLO 推理输出结构 标准 YOLO API 输出格式(以 Ultralytics 为例): { "class": "vehicle", "class_id": 1, "confidence": 0.91, "bbox": { "x1": 156.15, "y1": 487.68, "x2": 653.12, "y2": 690.16, "width": 496.97, "height": 202.47 } }判断结果质量时关注两点:置信度分布:主要目标是否集中在 0.7 以上 框的空间分布:是否存在高度重叠的框四类常见问题 1. 重复框(NMS 不净) 同一辆车被检测 2~3 次,框坐标相近但不完全重合。原因是 IOU 阈值偏低,NMS 未能合并相似框。 # 默认 0.45 偏低,调高到 0.55~0.60 results = model(img, iou=0.55)2. 低置信度噪声 大量 confidence < 0.4 的框混入结果,尤其是行人、远处小目标。默认 conf=0.25 会保留大量噪声。 # 推荐生产阈值 results = model(img, conf=0.45)效果:去掉垃圾框,结果更干净,后续处理负担更小。 3. 小目标识别差 行人、远处目标置信度普遍偏低(< 0.5),框也不稳定。可能的原因:输入分辨率不够(模型内部将图缩放到 640×640 后,远处目标只占几个像素) 训练数据中远距离目标样本少优化方向: # 提高推理分辨率 results = model(img, imgsz=1280)或使用更适合小目标的模型(yolo11x 或 RT-DETR)。 4. 类别冲突(person vs two_wheel) 人骑车时同时触发 person 框和 two_wheel 框,两框高度重叠。后处理规则: def resolve_conflict(detections, iou_thresh=0.7): persons = [d for d in detections if d["class"] == "person"] bikes = [d for d in detections if d["class"] == "two_wheel"] to_remove = set() for p in persons: for b in bikes: if compute_iou(p["bbox"], b["bbox"]) > iou_thresh: # 保留置信度高的 if p["confidence"] < b["confidence"]: to_remove.add(id(p)) else: to_remove.add(id(b)) return [d for d in detections if id(d) not in to_remove]工程状态推荐参数参数 实验值 推荐生产值conf_threshold 0.25 0.45iou_threshold 0.45 0.55后处理 Pipeline results = model(img, conf=0.45, iou=0.55) detections = parse_results(results)# 1. 过滤极小框(去远处误检) detections = [d for d in detections if d["bbox"]["width"] * d["bbox"]["height"] > min_area]# 2. 类别冲突解决 detections = resolve_conflict(detections)# 3. 业务逻辑处理模型"能用"和"可上线"之间的差距主要就是以上这几个阈值和后处理步骤。