我将我的java程序构建为uni分配的一部分,并且作为提交的一部分,它必须能够在DOS窗口中编译和运行(读取Windows命令窗口)。该程序在Netbeans中运行良好,但是当我将所有.java文件复制到一个单独的文件夹并尝试编译每个文件时,我得到了大量的编译错误。当我在Netbeans中创建文件时,我将它们作为一个包的所有部分,并让Netbeans在每个类的顶部添加“package * Project_Name *”。其余的是标准的java,没什么太复杂的。我第一次使用Netbeans(版本7.1.1是我使用的),它让我疯狂。我可以创建一个.jar文件,我可以从命令行运行它但我需要能够显示源代码可以从命令行编译,并且生成的文件也可以从命令行运行线。有没有其他人有这个问题,如果是这样,你是如何克服它或有谁知道如何解决这个问题。
我感觉它与其他文件的引用有关,因为大多数错误与创建的对象和从其他文件调用的方法有关。例如,我有一个Manager.java文件,它包含Manager对象的构造函数和方法,然后在另一个文件中(比如Proprety.java)我有使用new关键字创建Manager对象的代码。
当前使用的CLASSPATH是
CLASSPATH = .; C:\ Program Files \ java \ jdk1.7.0_03 \ lib; C:\ Program Files \ Java \ jre6 \ lib \ ext \ QTJava.zip;
PATH变量设置为
...; C:\ Program Files \ Java \ jdk1.7.0_03 \ bin; C:\ Program Files \ Java \ jre7 \ bin
就是这样。我使用的唯一库是java.util。*和java.io. *所有其他引用都是我在Netbeans中创建的类文件
任何帮助都会被贬低。
SET命令的结果:
C:\>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\Gunit\AppData\Roaming
asl.log=Destination=file
CLASSPATH=.;C:\Program Files\java\jdk1.7.0_03\lib;C:\Program Files\Java\jre6\lib
\ext\QTJava.zip;C:\Estateman
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GUNIT-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Gunit
LOCALAPPDATA=C:\Users\Gunit\AppData\Local
LOGONSERVER=\\GUNIT-PC
MOZ_PLUGIN_PATH=C:\Program Files\SumatraPDF\
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\syst
em32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v
1.0\;C:\Program Files\Common Files\Acronis\SnapAPI\;c:\Program Files\Microsoft S
QL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:
\Program Files\Windows Live\Shared;C:\Program Files\QuickTime\QTSystem\;C:\Progr
am Files\Common Files\Avid;Avid;C:\Program Files\doxygen\bin;C:\Program Files\Co
mmon Files\Adobe\AGL;C:\Program Files\Java\jdk1.7.0_03\bin;C:\Program Files\Java
\jre7\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 6 Stepping 5, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0605
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
QTJAVA=C:\Program Files\Java\jre6\lib\ext\QTJava.zip
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\Gunit\AppData\Local\Temp
TMP=C:\Users\Gunit\AppData\Local\Temp
USERDOMAIN=Gunit-PC
USERNAME=Gunit
USERPROFILE=C:\Users\Gunit
VS100COMNTOOLS=c:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\
windir=C:\Windows
命令我正在运行:
C:\Estateman>javac Manager.java
输出:
Manager.java:33: error: cannot find symbol
Property temp0 = new Rental(24,"Bogan Ave","Geelong",3040,"Bob Jones
","0420685765","Victoria","Tues 8am",280.50,"23/4/2012");
^
symbol: class Property
location: class Manager
Manager.java:33: error: cannot find symbol
Property temp0 = new Rental(24,"Bogan Ave","Geelong",3040,"Bob Jones
","0420685765","Victoria","Tues 8am",280.50,"23/4/2012");
^
symbol: class Rental
location: class Manager
Manager.java:34: error: cannot find symbol
Property temp1 = new Selling(56,"Maritime Rd","Perth",6000,"Alan Gib
s","0400345964","Perth","Wed 3pm",350485.00);
^
symbol: class Property
location: class Manager
Manager.java:34: error: cannot find symbol
Property temp1 = new Selling(56,"Maritime Rd","Perth",6000,"Alan Gib
s","0400345964","Perth","Wed 3pm",350485.00);
^
symbol: class Selling
location: class Manager
Manager.java:35: error: cannot find symbol
Property temp2 = new Selling(901,"Preston Rd","Murdoch",6505,"Alan G
ibs","0400345964","Perth","Fri 10am",890000.00);
^
symbol: class Property
location: class Manager
Manager.java:35: error: cannot find symbol
Property temp2 = new Selling(901,"Preston Rd","Murdoch",6505,"Alan G
ibs","0400345964","Perth","Fri 10am",890000.00);
^
symbol: class Selling
location: class Manager
Manager.java:36: error: cannot find symbol
Property temp3 = new Rental(83,"Joke Way","Murdoch",6505,"Grace Kell
y","0123493436","Winthrop","Fri 1pm",475.00,"18/4/2012");
^
symbol: class Property
location: class Manager
Manager.java:36: error: cannot find symbol
Property temp3 = new Rental(83,"Joke Way","Murdoch",6505,"Grace Kell
y","0123493436","Winthrop","Fri 1pm",475.00,"18/4/2012");
^
symbol: class Rental
location: class Manager
Manager.java:37: error: cannot find symbol
Property temp4 = new Selling(167,"Joke Way","Murdoch",6505,"Bob Jone
s","0420685765","Victoria","Sat 3pm","17/5/2012");
^
symbol: class Property
location: class Manager
Manager.java:37: error: cannot find symbol
Property temp4 = new Selling(167,"Joke Way","Murdoch",6505,"Bob Jone
s","0420685765","Victoria","Sat 3pm","17/5/2012");
^
symbol: class Selling
location: class Manager
Manager.java:38: error: cannot find symbol
Property temp5 = new Selling(2,"Ashbury Lane","Success",6110,"Ian Fi
elder","0895484453","Atwell","Mon 11am",900000.00);
^
symbol: class Property
location: class Manager
Manager.java:38: error: cannot find symbol
Property temp5 = new Selling(2,"Ashbury Lane","Success",6110,"Ian Fi
elder","0895484453","Atwell","Mon 11am",900000.00);
^
symbol: class Selling
location: class Manager
Manager.java:54: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:54: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:84: error: cannot find symbol
Property temp = new Selling(num,name,sub,code,person,phone,offic
e,open,price);
^
symbol: class Property
location: class Manager
Manager.java:84: error: cannot find symbol
Property temp = new Selling(num,name,sub,code,person,phone,offic
e,open,price);
^
symbol: class Selling
location: class Manager
Manager.java:92: error: cannot find symbol
Property temp = new Rental(num,name,sub,code,person,phone,of
fice,open,price,vacant);
^
symbol: class Property
location: class Manager
Manager.java:92: error: cannot find symbol
Property temp = new Rental(num,name,sub,code,person,phone,of
fice,open,price,vacant);
^
symbol: class Rental
location: class Manager
Manager.java:156: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:156: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:165: error: cannot find symbol
Rental rTemp = (Rental)(temp);
^
symbol: class Rental
location: class Manager
Manager.java:165: error: cannot find symbol
Rental rTemp = (Rental)(temp);
^
symbol: class Rental
location: class Manager
Manager.java:173: error: cannot find symbol
Selling sTemp = (Selling)(temp);
^
symbol: class Selling
location: class Manager
Manager.java:173: error: cannot find symbol
Selling sTemp = (Selling)(temp);
^
symbol: class Selling
location: class Manager
Manager.java:180: error: cannot find symbol
Selling sTemp = (Selling)(temp);
^
symbol: class Selling
location: class Manager
Manager.java:180: error: cannot find symbol
Selling sTemp = (Selling)(temp);
^
symbol: class Selling
location: class Manager
Manager.java:198: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:198: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:199: error: cannot find symbol
Property tmp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:199: error: cannot find symbol
Property tmp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:212: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:212: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:238: error: cannot find symbol
Property temp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:238: error: cannot find symbol
Property temp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:239: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:239: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:249: error: cannot find symbol
((Property)(properties.get(i))).address.setStreetNum(num);
^
symbol: class Property
location: class Manager
Manager.java:250: error: cannot find symbol
((Property)(properties.get(i))).address.setStreetName(name);
^
symbol: class Property
location: class Manager
Manager.java:251: error: cannot find symbol
((Property)(properties.get(i))).address.setSuburb(sub);
^
symbol: class Property
location: class Manager
Manager.java:252: error: cannot find symbol
((Property)(properties.get(i))).address.setPostCode(code);
^
symbol: class Property
location: class Manager
Manager.java:266: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:266: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:273: error: cannot find symbol
Property temp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:273: error: cannot find symbol
Property temp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:280: error: cannot find symbol
((Property)(properties.get(i))).contact.setContact(name,phone,office
);
^
symbol: class Property
location: class Manager
Manager.java:296: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:296: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:311: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:311: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:317: error: cannot find symbol
Property temp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:317: error: cannot find symbol
Property temp = new Property();
^
symbol: class Property
location: class Manager
Manager.java:320: error: cannot find symbol
((Property)(properties.get(i))).viewing.setTime(time);
^
symbol: class Property
location: class Manager
Manager.java:332: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:332: error: cannot find symbol
Utils u = new Utils();
^
symbol: class Utils
location: class Manager
Manager.java:341: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
Manager.java:341: error: cannot find symbol
Property temp = (Property)(itr.next());
^
symbol: class Property
location: class Manager
57 errors
C:\Estateman>
提前致谢
答案 0 :(得分:1)
好的,我想,关键在于:
我将它们作为一个软件包的一部分,让Netbeans在每个类的顶部添加一个“package * Project_Name *”。
你要编译的命令:
javac Manager.java
假设您的包名为projectname
。然后,Netbeans创建了一个目录projectname
,并将所有Java文件Manager.java
,Property.java
等放在其中。
在Java中,包结构直接对应于文件系统中的目录结构。例如。如果您在包A
中有一个类x.y.z
,则类A
的源代码文件位于文件x\y\z\A.java
中。
因此,当您复制所有*.java
个文件时,您必须确保同时复制原始目录结构。在您的情况下,您可以将课程Manager.java
,Property.java
,...复制到C:\test\projectname
。然后在你的DOS框cd
中到这个目录并用以下代码编译你的类:
javac -cp .. Manager.java
-cp ..
命令行选项的含义是,包/目录结构的根目录是C:\test
的一级。然后在编译Manager.java
时,Java编译器会找到对类Property
的引用,并假定类Property
与类Manager
位于同一个包中。所以编译器正在寻找类projectname.Property
。如果-cp
选项指向C:\ţest
,编译器就会知道它应该查看目录C:\test\projectname
。
编译完成后,您可以使用以下命令运行程序:
java -cp .. projectname.Manager