用自己的路径编译一个使用docker的java文件 [英] Compile a java file using docker with own path

查看:518
本文介绍了用自己的路径编译一个使用docker的java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HY。我试图用docker编译一个.java文件。我在docker的网站上阅读了这些文件,我也阅读了这些链接:


docker的网站

Hy. I'm trying to compile a .java file using docker. I read the files on docker's website, also I read these links:

docker's website


关于卷


和另一个问题我已经为gcc编译器提供了$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
但是java一个。如果我使用以下命令并编译一个名为 Main.java Main.class c>


sudo docker运行--rm -v$ PWD:/ usr / src / myapp -w / usr / src / myapp java:7 javac Main.java

and another question I had put up for gcc compiler

I understood the concept for the gcc compiler since it doesn't create any extra file for compiling. But the java one does. It creates a Main.class file on my /home directory if I use the following command and compile a file named Main.java

sudo docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac Main.java


从上述链接学习后,我能够用自己的程序成功编译一个java文件路径使用:

after learning from the above links I was able to successfully compile a java file with my own path using:

docker run --rm -v /mypathhere/mycode.java:/mycode.java: java:7 javac mycode.java"


如果有任何错误,它显示错误,但如果没有它只是编译,并给我没有输出,这是有道理的,因为它创建一个 Main.class 文件


我的问题是我找不到 Main.class 文件,我不知道docker在哪里创建它,我没有理解请帮助我。

if there is any error it shows an error but if there isn't it just compiles and gives me no output, and that's justified because it creates a Main.class file.

My problem is that I am unable to find that Main.class file. I don't know where docker is creating it and I have zero understanding for it. Please help me out.

推荐答案

.class 将在容器内部的根目录下。

The .class file will be inside the container, under the root directory.

最好的方案是挂载整个源目录,并且具有 javac 将结果放在同一目录下,例如:

The best plan is to mount the whole source directory and have javac put the result to the same directory e.g:

docker run --rm -v /mypathhere:/mycode java:7 sh -c "cd mycode; javac mycode.java"

这样,你应该把类文件写到 mypathhere 目录。

That way, you should get the class file written to the mypathhere directory.

道歉,如果这不行 - 这是我的头顶,希望你得到想法。

Apologies if that doesn't quite work - it's off the top of my head. Hopefully you get the idea though.

这篇关于用自己的路径编译一个使用docker的java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆