0

我正在尝试创建一个 docker 映像来在容器内运行我的 java 程序。我是 docker 新手,我不知道如何设置类路径。我有一个 datafile.properties、Sample.java、lib 文件夹,其中包含我所有的依赖 jar 文件和我的 webdriver 在我本地机器的文件夹 C:\users\accessibility 中。请在下面找到 dockerfile:

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"]

我正在尝试使用以下命令运行它:

docker build -t accessibility C:\users\accessibility

我得到以下错误:

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

它不是指 jar 文件。类路径设置不正确。请帮助我提供示例 dockerfile 或任何关于此的建议会有所帮助。提前致谢

4

0 回答 0