如何在windows机器上的docker容器中设置classpath

时间:2017-06-23 13:24:02

标签: classpath dockerfile docker-windows docker-java

我正在尝试创建一个docker镜像来在容器内运行我的java程序。我是docker的新手,我不知道如何设置类路径。我有一个datafile.properties,Sample.java,lib文件夹,其中包含我的本机中文件夹C:\ users \ accessibility中的所有依赖jar文件和我的webdriver。请在下面找到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文件。 classpath设置不正确。请帮助我使用示例dockerfile或任何有关这方面的建议会有所帮助。提前致谢

0 个答案:

没有答案