linux - Maven - 无法在 shell 脚本中创建资源输出目录

标签 linux git shell maven build

我正在尝试在 shell 脚本中执行 Maven 构建。我在 EC2 实例中的 Amazon Linux 上运行。

这是我遇到问题的脚本的前两行:

sudo git clone [url of git repository]

sudo mvn clean package -f /path/to/pom.xml

如果我在命令行中分别输入它们中的每一个,那么它就会起作用。

如果我已经克隆了存储库然后执行脚本,它就可以工作。它跳过克隆存储库(因为它已经存在)并继续执行脚本的其余部分。这再次起作用。

当 repo 不存在并且我运行脚本时会出现问题。它克隆了远程仓库并且似乎是成功的。

但是当它试图打包项目时我遇到了这个错误:

您可以看到存储库已被克隆,然后构建开始,但失败了。我什至尝试在克隆和 mvn package 命令之间等待 5 秒。

[ec2-user@ip-10-0-1-16 ~]$ build_script
Cloning into 'devops'...
remote: Counting objects: 649, done.
remote: Compressing objects: 100% (548/548), done.
remote: Total 649 (delta 314), reused 88 (delta 24)
Receiving objects: 100% (649/649), 18.96 MiB | 0 bytes/s, done.
Resolving deltas: 100% (314/314), done.
Checking connectivity... done.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building UserRegistrationClient current
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ demo ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.890 s
[INFO] Finished at: 2015-08-28T18:43:04+00:00
[INFO] Final Memory: 11M/26M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project demo: Cannot create resource output directory: /home/ec2-user/devops/UserRegistrationClient/target/classes -> [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/MojoExecutionException

最佳答案

错误清楚地表明这是权限问题:

Cannot create resource output directory: /home/ec2-user/devops/UserRegistrationClient/target/classes

这与您的描述“当 repo 不存在并且我运行脚本时出现问题”一致,因为当它不存在时,您使用 sudo 创建它>,因此它属于 root,而如果 repo 已经存在,权限不会改变。

为了更好地理解实际发生的事情,您应该在脚本中添加一些跟踪,特别是一些 ls -l 以检查您正在操作的目录的所有者,以及一些whoami为了查看谁在执行给定的操作

关于linux - Maven - 无法在 shell 脚本中创建资源输出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32277854/

相关文章:

linux - 没有 bc 的时间(以毫秒为单位)

php - 通过 php 向 Linux 服务器运行 Curl 命令

linux - Linux 内核如何获取有关处理器和内核的信息?

c - TCP 连接 - 延迟 close() 和 RST

git - 使用 gitk 查看 move 文件的完整历史记录

git - .gitmodules 和在 .git/config 中指定子模块的区别?

java - Gitflow 与 Maven 的工作流程 - 何时构建什么?

linux - Shell 脚本编辑文件行

unix - "x$VARIABLE"中 x 的 shell 脚本用途

bash - 可以检查它是否在调用时后台运行的 Shell 脚本