我可以 运行 来自 docker 的 maven 神器吗
Can I run maven artifact from docker
我的目标是使用 maven:latest 设置一个 Dockerfile,以便能够 运行 我的 javascript 代码与 org.mozilla.rhino
[=14= 的最新版本]
FROM maven:latest
RUN [ "mvn", "dependency:get", "-Dartifact=org.mozilla:rhino:LATEST:jar" ]
RUN [ "mvn", "exec:java" "-Dexec.mainClass='org.mozilla.javascript.tools.shell.Main'" "-Dexec.args='src/index.js'"]
我需要 pom.xml 才能做到这一点吗?如果我需要
我的 pom.xml 应该包含什么,因为我的项目只有 javascript 个文件?
PS: 我以前没有使用 maven 的经验
好吧,正如您所希望的,您的项目并不真的需要 pom.xml
。我不知道你是否需要它完全便携,但这是我基于 maven:latest
模拟的东西。这是通过利用下载的 rhino jar 文件包含一个 MANIFEST.MF
文件来完成的,该文件告诉 java
命令如何执行它。
rhino-1.7.10.jar的内容:/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: org.mozilla.javascript.tools.shell.Main
Implementation-Version: 1.7.10
Implementation-Title: Mozilla Rhino
Implementation-Vendor: Mozilla Foundation
Implementation-URL: http://www.mozilla.org/rhino
Built-Date: 2018-04-09
Built-Time: 20:03:34
所以:
index.js
print("Hello world");
命令行
$ mvn dependency:get -Dartifact=org.mozilla:rhino:LATEST:jar # as you have currently
... # maven output snipped
$ find .m2 -name rhino*.jar -exec java -jar {} index.js \;
Hello world!
Dockerfile(未测试)
FROM maven:latest
# Missing here is you copying your javascript into the image
RUN [ "mvn", "dependency:get", "-Dartifact=org.mozilla:rhino:LATEST:jar" ]
RUN [ "find", "/root/.m2", "-name", "rhino*.jar", "-exec", "java", "-jar", "{}", "src/index.js", "\;" ]
编辑:
我还应该注意到 .m2
用户子目录包含一个存储库,其中包含 maven 下载的所有工件。 maven:latest
Dockerfile 似乎在 /root/ 下进行设置。
我的目标是使用 maven:latest 设置一个 Dockerfile,以便能够 运行 我的 javascript 代码与 org.mozilla.rhino
[=14= 的最新版本]
FROM maven:latest
RUN [ "mvn", "dependency:get", "-Dartifact=org.mozilla:rhino:LATEST:jar" ]
RUN [ "mvn", "exec:java" "-Dexec.mainClass='org.mozilla.javascript.tools.shell.Main'" "-Dexec.args='src/index.js'"]
我需要 pom.xml 才能做到这一点吗?如果我需要 我的 pom.xml 应该包含什么,因为我的项目只有 javascript 个文件?
PS: 我以前没有使用 maven 的经验
好吧,正如您所希望的,您的项目并不真的需要 pom.xml
。我不知道你是否需要它完全便携,但这是我基于 maven:latest
模拟的东西。这是通过利用下载的 rhino jar 文件包含一个 MANIFEST.MF
文件来完成的,该文件告诉 java
命令如何执行它。
rhino-1.7.10.jar的内容:/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: org.mozilla.javascript.tools.shell.Main
Implementation-Version: 1.7.10
Implementation-Title: Mozilla Rhino
Implementation-Vendor: Mozilla Foundation
Implementation-URL: http://www.mozilla.org/rhino
Built-Date: 2018-04-09
Built-Time: 20:03:34
所以:
index.js
print("Hello world");
命令行
$ mvn dependency:get -Dartifact=org.mozilla:rhino:LATEST:jar # as you have currently
... # maven output snipped
$ find .m2 -name rhino*.jar -exec java -jar {} index.js \;
Hello world!
Dockerfile(未测试)
FROM maven:latest
# Missing here is you copying your javascript into the image
RUN [ "mvn", "dependency:get", "-Dartifact=org.mozilla:rhino:LATEST:jar" ]
RUN [ "find", "/root/.m2", "-name", "rhino*.jar", "-exec", "java", "-jar", "{}", "src/index.js", "\;" ]
编辑:
我还应该注意到 .m2
用户子目录包含一个存储库,其中包含 maven 下载的所有工件。 maven:latest
Dockerfile 似乎在 /root/ 下进行设置。