开发者

compiling multiple java classes in linux

开发者 https://www.devze.com 2023-02-20 17:40 出处:网络
i used netbeans to code the classes and they a开发者_如何学JAVAre all included in a package but when i try to compile the application class in linux it spits out errors on class definitions for the cl

i used netbeans to code the classes and they a开发者_如何学JAVAre all included in a package but when i try to compile the application class in linux it spits out errors on class definitions for the classes i am working with. points at the class names for the objects and says "cannot find symbol" i need help!!!


use javac -sourcepath < your source code path >

Better check -help option as it mostly solve your problems


cd to the directory containing your package then run:

javac -classpath . your_package_name/*


I'm not a Java guru, but I have a small java project that I developed years ago and have recently ported to compile with javac on Linux.

I got this to work in two different ways:

  1. Created a single Java source file that held all of my classes
  2. Put each of my classes in a separate file but all in the same directory

In each case, I can compile and run with the following:

javac *.java && java name_of_main_class

Notice that I did not specify a "-classpath" option when I compiled. I guess this works because I have not used a directory substructure or created a package. If you are dealing with those issues, this page appears to have some examples that may help you: Help with packages in java - import does not work

A key thing to understand about Java packages: They correspond to subdirectories where the classes are defined (or to JAR files which just bundle and compress those subdirectories into a single file). Therefore, anytime you specify the package keyword in your source, you need to make sure that the source files (and the class files) are distributed to subdirectories correspondingly. The -classpath option to javac may provide a workaround when subdirectory structures do not exactly match what is specified by the package keyword.


If you built the project using NetBeans, you can use Ant to build the project on command line. NetBeans generate Ant Build script.

just cd into the directory where the project is located then type 'ant' it should build the project for you automagically

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号