简体   繁体   English

在没有 Maven 码头的情况下从命令行运行战争

[英]running war from command line without maven jetty

I am trying to put a piece of open source software in a docker container ( https://github.com/att/XACML ) but in this container I can not use maven.我正在尝试将一个开源软件放入 docker 容器( https://github.com/att/XACML )中,但在此容器中我无法使用 maven。 The documentation for running this service says to use mvn jetty, which does work fine, but in order to get this in a container I don't want to include a build step (maven).运行此服务的文档说要使用 mvn jetty,它确实可以正常工作,但是为了将其放入容器中,我不想包含构建步骤 (maven)。

Instead, I'd like a way to compile the a war, so I can copy just the war into the container and execute it from there.相反,我想要一种编译战争的方法,这样我就可以只将战争复制到容器中并从那里执行它。

I have tried many attempts to get the war running without maven jetty but none of them work.我已经尝试了很多尝试来让战争在没有 Maven 码头的情况下运行,但没有一个奏效。

  1. java -jar /path/to/jar no main manifest attribute error. java -jar /path/to/jar 没有主清单属性错误。 There is no main class, it extends an HttpServlet没有主类,它扩展了一个 HttpServlet

  2. using jetty-runner when I launch the war with jetty-runner through the command line I do not get any errors, but it boots up to a page showing the directory of files, and not the actual project.当我通过命令行启动与 jetty-runner 的战争时使用 jetty-runner 我没有收到任何错误,但它启动到显示文件目录的页面,而不是实际项目。

  3. Making an 'uber-jar' to package all deps same issue as 1, get a no main manifest issue.制作一个 'uber-jar' 来打包所有与 1 相同的问题,得到一个没有主要的清单问题。

I can include more code if that would be helpful (pom files etc), but I don't want to add too much if it is unneeded.如果有帮助(pom 文件等),我可以包含更多代码,但如果不需要,我不想添加太多。 I am super unfamiliar with how java projects are packaged and deployed, so I am having a difficult time figuring out what needs to be done.我非常不熟悉 java 项目是如何打包和部署的,所以我很难弄清楚需要做什么。

Thanks!谢谢!

Minimal Dockerfile to work with your webapp / war file is ...与您的 webapp/war 文件一起使用的最小Dockerfile是...

FROM jetty:9.4.18
ADD ROOT.war /var/lib/jetty/webapps/

This uses the official jetty docker image at这使用官方码头泊坞窗图像
https://hub.docker.com/_/jetty https://hub.docker.com/_/jetty

Managed at管理于
https://github.com/eclipse/jetty.docker https://github.com/eclipse/jetty.docker

The name ROOT.war is special, and will deploy your webapp in the "root" context path of "/" ROOT.war这个名字很特殊,它会将你的 webapp 部署在"/"的“root”上下文路径中

Building Image建筑形象

If you build it like this ...如果你像这样构建它......

$ docker build -t stackoverflow/jetty:latest .

Running Image运行图像

Interactively (so you can the logs)交互式(这样您就可以查看日志)

$ docker run --interactive --tty --rm --publish 80:8080 stackoverflow/jetty:latest

As Daemon作为守护进程

$ docker run --detach --publish 80:8080 stackoverflow/jetty:latest

The server will be available on port 80 of the machine you ran the docker run command on.服务器将在您运行docker run命令的机器的端口 80 上可用。

Configuring Jetty Base配置码头基地

If you need to configure the jetty image you can use any of the standard start.jar commands.如果您需要配置 jetty 映像,您可以使用任何标准的start.jar命令。

Example:例子:

FROM jetty:9.4.18
WORKDIR $JETTY_BASE
RUN java -jar $JETTY_HOME/start.jar --add-to-start=jsp
ADD ROOT.war /var/lib/jetty/webapps/

How This Works Without Maven在没有 Maven 的情况下这是如何工作的

See the official image details ...看官方图片详情...

https://github.com/eclipse/jetty.docker/blob/master/9.4-jdk11/Dockerfile https://github.com/eclipse/jetty.docker/blob/master/9.4-jdk11/Dockerfile

The key commands are ...关键命令是...

WORKDIR $JETTY_BASE
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["java","-jar","/usr/local/jetty/start.jar"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM