简体   繁体   中英

compiling multiple java classes in linux

i used netbeans to code the classes and they are 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到包含您的软件包的目录,然后运行:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM