Main.java $ c $的文件,则在我的/ home目录下创建一个 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屋!