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!!!
-
are you using javac on the console or netbeans to compile?Matt Wonlaw– Matt Wonlaw2011-03-31 01:00:07 +00:00Commented Mar 31, 2011 at 1:00
-
yes javac on the consoledawnoflife– dawnoflife2011-03-31 01:01:07 +00:00Commented Mar 31, 2011 at 1:01
-
How is your package structure organized? Do you have a root folder and then all of the packages beneath it? Like: ./src ./src/package1 ./src/package1/subpackage ?Matt Wonlaw– Matt Wonlaw2011-03-31 01:04:23 +00:00Commented Mar 31, 2011 at 1:04
-
only 1 package with all the classesdawnoflife– dawnoflife2011-03-31 01:11:20 +00:00Commented Mar 31, 2011 at 1:11
4 Answers
use javac -sourcepath < your source code path >
Better check -help option as it mostly solve your problems
2 Comments
cd to the directory containing your package then run:
javac -classpath . your_package_name/*
2 Comments
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:
- Created a single Java source file that held all of my classes
- 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.