0

i'm trying to create a docker image to run my java program inside the container. i new to docker i have no idea how to set the classpath. i have a datafile.properties, Sample.java,lib folder which contains all my dependancy jar files and my webdriver inside the folder C:\users\accessibility in my local machine. Please find the dockerfile below:

FROM java8:jdk

WORKDIR C:\\accessibility

COPY Sample.java C:\\accessibility\\Sample.java

COPY ./lib C:\\accessibility\\lib

ENV CLASSPATH C:\\accessibility\\lib\\axe-selenium-2.0.jar;C:\\accessibility\\lib\\java-json;C:\\accessibility\\lib\\json-simple-1.1;C:\\accessibility\\lib\\selenium-java-2.45.0;C:\\accessibility\\lib\\selenium-server-standalone-3.4.0

RUN javac Sample.java

CMD ["java","Sample"]

i'm trying to run it using the below command:

docker build -t accessibility C:\users\accessibility

i get shown the below error:

Sending build context to Docker daemon 29.33 MB
Step 1/6 : FROM java8:jdk
 ---> 97491cd5aa74
Step 2/6 : WORKDIR C:\\accessibility
 ---> Using cache
 ---> 0c8cfb951153
Step 3/6 : COPY Sample.java C:\\accessibility\\Sample.java
 ---> d083489522eb
Removing intermediate container f794396cc8eb
Step 4/6 : ENV CLASSPATH C:\\accessibility\\lib\\axe-selenium-2.0.jar;C:\\accessibility\\lib\\java-json;C:\\accessibility\\lib\\json-simple-1.1;C:\\accessibility\\lib\\selenium-java-2.45.0;C:\\accessibility\\lib\\selenium-server-standalone-3.4.0
 ---> Running in 3f0da277efaa
 ---> 2c32806352cb
Removing intermediate container 3f0da277efaa
Step 5/6 : RUN javac Sample.java
 ---> Running in 8ba2e1e7b45c
Sample.java:9: error: package org.json does not exist
import org.json.JSONArray;
               ^
Sample.java:10: error: package org.json does not exist
import org.json.JSONException;
               ^
Sample.java:11: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                          ^
Sample.java:12: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
                          ^
Sample.java:13: error: package org.openqa.selenium.chrome does not exist
import org.openqa.selenium.chrome.ChromeDriver;
                                 ^
Sample.java:14: error: package com.nft.parsing does not exist
import com.nft.parsing.Parsing;
                      ^
Sample.java:15: error: package com.nft.testing does not exist
import com.nft.testing.Testing;
                      ^
Sample.java:22: error: cannot find symbol
        static Testing t=new Testing();
               ^
  symbol:   class Testing
  location: class Sample
Sample.java:24: error: package org.json.simple does not exist
        ArrayList<org.json.simple.JSONArray> final10=new ArrayList<org.json.simple.JSONArray>();
                                 ^
Sample.java:26: error: cannot find symbol
        static JSONArray jsonresults=null;
               ^
  symbol:   class JSONArray
  location: class Sample
Sample.java:32: error: package org.json.simple.parser does not exist
        public static void main(String[] args) throws FileNotFoundException, IOException, org.json.simple.parser.ParseException, JSONException{
                                                                                                                ^
Sample.java:32: error: cannot find symbol
        public static void main(String[] args) throws FileNotFoundException, IOException, org.json.simple.parser.ParseException, JSONException{
                                                                                                                                 ^
  symbol:   class JSONException
  location: class Sample
Sample.java:22: error: cannot find symbol
        static Testing t=new Testing();
                             ^
  symbol:   class Testing
  location: class Sample
Sample.java:24: error: package org.json.simple does not exist
        ArrayList<org.json.simple.JSONArray> final10=new ArrayList<org.json.simple.JSONArray>();
                                                                                  ^
Sample.java:59: error: cannot find symbol
                WebDriver driver = new ChromeDriver();
                ^
  symbol:   class WebDriver
  location: class Sample
Sample.java:59: error: cannot find symbol
                WebDriver driver = new ChromeDriver();
                                       ^
  symbol:   class ChromeDriver
  location: class Sample
Sample.java:62: error: cannot find symbol
                driver.findElement(By.id("userName")).sendKeys("admin");
                                   ^
  symbol:   variable By
  location: class Sample
Sample.java:63: error: cannot find symbol
                driver.findElement(By.id("passWord")).sendKeys("welcome");
                                   ^
  symbol:   variable By
  location: class Sample
Sample.java:64: error: cannot find symbol
                driver.findElement(By.id("login")).click();
                                   ^
  symbol:   variable By
  location: class Sample
Note: Sample.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
19 errors

it is not referring the jar files. classpath is not set properly. Kindly help me with the sample dockerfile or any advise on this would be helpful. Thanks in advance

syndy1989
  • 403
  • 10
  • 25
  • is your docker image/container a windows os? can you share the link of the docker hub? and I would use the `/` instead of `\\ ` for the paths – Edwin Jun 23 '17 at 13:34
  • Yes it is a windows OS.Please find the docker hub link below: https://hub.docker.com/r/474614/my_repo/ – syndy1989 Jun 23 '17 at 13:35
  • I cannot access yours, but I meant the public one: `java8:jdk` – Edwin Jun 23 '17 at 13:38
  • Why do you think it's CLASSPATH related? I suggest create Windwos Server Core instance in Hyper-V, login locally to console and run those entries manually one by one and see if it works – Gregory Suvalian Jun 23 '17 at 13:40
  • 1
    instead of `ENV CLASSPATH` try to set it with `RUN SET CLASSPATH=...` – Edwin Jun 23 '17 at 13:50

0 Answers0