Erwan Maigne Montamat
Erwan Maigne Montamat

Reputation: 51

Docker, why does it fail to access my other package in a java program

I'm deeply sorry since the answer may be existing already but I've failed to found it yet and the similar question part of stack overflow pointed me to some python question that doesn't really help me to understand,

So here I am: I've done a very simple java program doing some maths and I'm trying to get it to run my functions defined in my "main" package into a "test" package, while doing it through eclipse compilation there is no problem, next step being setting up a dockerfile to allow me to keep using it everywhere (trying to learn docker)

here is my dockerfile:

FROM java:openjdk-8u111-jdk-alpine


COPY . /usr/src/javafactorielle


WORKDIR /usr/src/javafactorielle

RUN javac src/javafactorielle/main/Operations.java
RUN javac src/javafactorielle/test/Main.java

CMD [java, Main, 4]

I've got no issue importing from a package to another in eclipse and compiling it successfully Here is the structure of my Java project being: src/ (javafactorielle.main/Operations.java) || (javafactorielle.test/Main.java)

But when I try to build the dockerfile I got the following error:

------
 > [5/5] RUN javac src/javafactorielle/test/Main.java:
0.785 src/javafactorielle/test/Main.java:3: error: package javafactorielle.main does not exist
0.785 import javafactorielle.main.Operations;
0.785                            ^
0.825 src/javafactorielle/test/Main.java:14: error: cannot find symbol
0.825                   int result = Operations.FactoOf(number);
0.825                                ^
0.825   symbol:   variable Operations
0.825   location: class Main
0.835 2 errors
------

Can anyone here help me figure out where did I messed up?

I know I would probably be able to get away with it by putting my operations class in the same package as my tests but that would be super messy so I would prefer not to do that Since I'm really a beginner when it comes to docker I would appreciate if you could keep your explanations as simple as possible (and link some doc if you can, so I may learn more around those issues)

Another question: Since I'm using different package: Do I have to look at docker compose for this?

EDITS: "Try removing the statement import javafactorielle.main.Operations – Klitos Kyriacou" Well it didn't helped and I had to explicitely cast the path to the said class when using it

Upvotes: 0

Views: 86

Answers (0)

Related Questions