Hi, 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
ENV CLASSPATH .;./lib/axe_method.jar;axe-selenium-2.0.jar;java-json;json-simple-1.1;selenium-java-2.45.0;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 .;./lib/axe_method.jar;axe-selenium-2.0.jar;java-json;json-simple-1.1;selenium-java-2.45.0;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. . Also i’m trying to copy the file from docker container to local machine how would i do that.any advise on this would be helpful. Thanks in advance