Maven「there is no POM in this directory」の原因と直し方
there is no POM in this directory は、pom.xml のある場所で実行すれば直る。
Maven は実行したディレクトリの pom.xml しか見ないので、別の場所からは -f で pom.xml を指す。
公開: 更新:
mvn package … [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/tmp/tmp.YZ1ycCCYIz/repo). Please verify you invoked Maven from the correct directory. -> [Help 1] [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.
mvn package … [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.058 s [INFO] Finished at: 2026-10-31T02:18:38Z [INFO] ------------------------------------------------------------------------
2026-10-31 に maven:3-eclipse-temurin-21(Git 2.53.0) で実際に打って取った出力。検証環境の詳細
要約
mvn compile や mvn package を実行すると、ビルドが始まる前に止まる。
Maven 3.10.0 では次の行が出る。
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/user/app). Please verify you invoked Maven from the correct directory. -> [Help 1]there is no POM in this directory は、実行したディレクトリに pom.xml が無いという意味だ。compile や package のようなフェーズは、プロジェクトの設定である pom.xml を読んでから動くので、それが無いと何もできない。
括弧の中には Maven が探したディレクトリが出る。
まずここが、pom.xml を置いたディレクトリと同じかを見る。
Maven が見るのは、実行したディレクトリの pom.xml だけだ。
Maven 3.10.0 では、pom.xml のあるディレクトリの子(src の中)で実行しても、その親で実行しても、同じエラーになる。
実行例
maven:3-eclipse-temurin-21 のコンテナで、pom.xml の無いディレクトリや backend/src の中から mvn package を打つと、there is no POM in this directory で終了コード 1 になった。pom.xml のあるディレクトリで打ち直した mvn package と、mvn -f backend/pom.xml package は BUILD SUCCESS で終了コード 0 だった。
$ mvn -v
Apache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: /usr/share/maven
Java version: 21.0.13, vendor: Eclipse Adoptium, runtime: /opt/java/openjdk
Default locale: en_US, platform encoding: UTF-8, time zone: Etc/UTC
OS name: "linux", version: "6.6.87.2-microsoft-standard-wsl2", arch: "amd64", family: "unix"$ ls pom.xml
ls: cannot access 'pom.xml': No such file or directory$ mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.054 s
[INFO] Finished at: 2026-10-31T02:18:36Z
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/tmp/tmp.YZ1ycCCYIz/repo). Please verify you invoked Maven from the correct directory. -> [Help 1]
[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/MissingProjectException
$ echo $?
1$ mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.051 s
[INFO] Finished at: 2026-10-31T02:18:37Z
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/tmp/tmp.YZ1ycCCYIz/repo/backend/src). Please verify you invoked Maven from the correct directory. -> [Help 1]
[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/MissingProjectException
$ echo $?
1$ ls pom.xml
pom.xml$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 1.0
[INFO] from pom.xml
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.058 s
[INFO] Finished at: 2026-10-31T02:18:38Z
[INFO] ------------------------------------------------------------------------
$ echo $?
0$ mvn -f backend/pom.xml package
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 1.0
[INFO] from pom.xml
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.061 s
[INFO] Finished at: 2026-10-31T02:18:38Z
[INFO] ------------------------------------------------------------------------
$ echo $?
0— 2026-10-31 時点の出力
検証環境Git 2.53.0 / 2026-10-31 検証
- 検証日
- 実行環境
maven:3-eclipse-temurin-21Ubuntu 26.04.1 LTS- バージョン
- Git 2.53.0
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. pom.xml のあるディレクトリで実行する
ls pom.xml # ここに無ければ実行している場所が違う
cd backend # pom.xml のあるディレクトリへ移動する
mvn packageファイル名が違うだけなら、pom.xml に直せば通る。
2. 移動せずに -f で POM を指す
スクリプトや CI でディレクトリを移動したくないときは、-f(--file)で POM の場所を渡す。
CLI リファレンス(新しいタブで開く)のとおり、pom.xml そのものでも、それを含むディレクトリでもよい。
mvn -f backend/pom.xml package
mvn -f backend packageGitHub Actions なら、ステップの working-directory を pom.xml のあるディレクトリにしても同じことになる。
- run: mvn -B package
working-directory: backend3. 新しく作るなら archetype:generate の後に cd する
archetype:generate 自体は pom.xml の無い場所でも動く。
生成が終わったら、できたディレクトリへ入ってからビルドする(Maven in 5 Minutes(新しいタブで開く))。
mvn archetype:generate -DgroupId=com.example -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.5 -DinteractiveMode=false
cd my-app
mvn packageよくある原因
- 実行している場所が違う。
モノレポのルートから実行した、ターミナルがsrcの中にいた、といった場合だ。
Maven は親ディレクトリへさかのぼってpom.xmlを探さない。 archetype:generateの後に移動していない。mvn archetype:generateは、artifactIdと同じ名前のディレクトリを作ってその中にpom.xmlを置く。
生成したディレクトリの外で続けてmvn packageを打つと、このエラーになる。- ファイル名が違う。
Maven が既定で読むのはpom.xmlという名前のファイルだけだ。pom.xml.txtのように拡張子が付いたものは見つからない。
大文字小文字を区別するファイルシステム(Linux など)ではPom.xmlも見つからない。 - CI の作業ディレクトリが違う。
pom.xmlがサブディレクトリにあるのに、ジョブはリポジトリのルートでmvnを実行している。