我能够在 Eclipse 中编译我的 Main.java 文件而没有任何问题。
在 Main.java 我有
package com.selenium.zLoadProfilerPkg;
在其他 3 个文件中,我也有
package com.selenium.zLoadProfilerPkg;
但是,当我将整个结构上传到 linux 并尝试编译它时,出现错误:
[sgalkov@zpub zLoadProfilerPkg]$ pwd
/home/sgalkov/zpp_tech_git_checkout/profiler/zLoadProfiler/zLoadProfiler/src/com/selenium/zLoadProfilerPkg
[sgalkov@zpub zLoadProfilerPkg]$ cd /home/sgalkov/zpp_tech_git_checkout/profiler/zLoadProfiler/zLoadProfiler/src/com/selenium/zLoadProfilerPkg/; javac -cp ".:/home/sgalkov/zpp_tech_git_checkout/profiler/selenium-2.30.0/selenium-java-2.30.0.jar:/home/sgalkov/zpp_tech_git_checkout/profiler/selenium-2.30.0/libs/*:/home/sgalkov/zpp_tech_git_checkout/profiler/selenium-2.30.0/selenium-server-standalone-2.30.0.jar:/home/sgalkov/zpp_tech_git_checkout/profiler/browsermob-proxy-2.0-beta-7/browsermob-proxy-2.0-beta-7-sources.jar:/home/sgalkov/zpp_tech_git_checkout/profiler/browsermob-proxy-2.0-beta-7/lib/*:/home/sgalkov/zpp_tech_git_checkout/profiler/zLoadProfiler/zLoadProfiler/src/com/selenium/zLoadProfilerPkg" Main.java
Main.java:54: error: cannot find symbol
BrowsermobProxy bmp = new BrowsermobProxy(PROXY_API_HOST, PROXY_API_PORT);
^
symbol: class BrowsermobProxy
location: class Main
Main.java:54: error: cannot find symbol
BrowsermobProxy bmp = new BrowsermobProxy(PROXY_API_HOST, PROXY_API_PORT);
^
symbol: class BrowsermobProxy
location: class Main
Main.java:310: error: cannot find symbol
HarStorage hs = new HarStorage(HARSTORAGE_HOST, HARSTORAGE_PORT);
^
symbol: class HarStorage
location: class Main
Main.java:310: error: cannot find symbol
HarStorage hs = new HarStorage(HARSTORAGE_HOST, HARSTORAGE_PORT);
^
symbol: class HarStorage
location: class Main
4 errors
[sgalkov@zpub zLoadProfilerPkg]$
如果我注释掉“package com.selenium.zLoadProfilerPkg;” 在 4 个文件中的每一个中并一个一个地编译它们,一切正常。
另外,如果我尝试以这种方式编译它:
cd /home/sgalkov/zpp_tech_git_checkout/profiler/zLoadProfiler/zLoadProfiler/src/com/selenium/zLoadProfilerPkg/;
javac -cp ".\
:/home/sgalkov/zpp_tech_git_checkout/profiler/selenium-2.30.0/selenium-java-2.30.0.jar\
:/home/sgalkov/zpp_tech_git_checkout/profiler/selenium-2.30.0/libs/*\
:/home/sgalkov/zpp_tech_git_checkout/profiler/selenium-2.30.0/selenium-server-standalone-2.30.0.jar\
:/home/sgalkov/zpp_tech_git_checkout/profiler/browsermob-proxy-2.0-beta-7/browsermob-proxy-2.0-beta-7-sources.jar\
:/home/sgalkov/zpp_tech_git_checkout/profiler/browsermob-proxy-2.0-beta-7/lib/*\
:/home/sgalkov/zpp_tech_git_checkout/profiler/zLoadProfiler/zLoadProfiler/src/com/selenium/zLoadProfilerPkg" \
BrowsermobProxy.java HarStorage.java HttpRequest.java Main.java
它确实可以编译,但我为 Main.java 获得了一个额外的类
rw-r--r-- 1 sgalkov users 1422 Mar 11 20:30 Main$1.class
rw-r--r-- 1 sgalkov users 8264 Mar 11 20:30 Main.class
rw-r--r-- 1 sgalkov users 14864 Mar 11 19:32 Main.java
我无法运行程序,我收到错误:
Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name: com/selenium/zLoadProfilerPkg/Main)
at java.lang.ClassLoader.defineClass1(Native Method)
我环顾四周并尝试了各种选项,但无法编译该项目,并希望得到任何指示。