0

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

about volumes

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

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"

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.

1 Answer 1

1

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

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"

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.

Sign up to request clarification or add additional context in comments.

4 Comments

It gives the following error. mycode.java:1: error: error while writing mycode: mycode.class (Read-only file system) class mycode { ^ 1 error
Ooops - I had a spurious ":" after mycode. Try it again; I just tested and it works for me.
lol. Thats great! When my project is complete, I'll add a special thanks to you :')
hi looks like i need your help once again. Sorry but can you please guide me out?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.