0

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!!!

4
  • are you using javac on the console or netbeans to compile? Commented Mar 31, 2011 at 1:00
  • yes javac on the console Commented 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 ? Commented Mar 31, 2011 at 1:04
  • only 1 package with all the classes Commented Mar 31, 2011 at 1:11

4 Answers 4

1

use javac -sourcepath < your source code path >

Better check -help option as it mostly solve your problems

Sign up to request clarification or add additional context in comments.

2 Comments

i did this and had all my classes in a separate folder but it said files not found.
put more details on error your getting, may copy and paste the error. Is it class not found error in compiling?
1

cd to the directory containing your package then run:

javac -classpath . your_package_name/*

2 Comments

how exactly do i create a package in linux? right now i have my .java files in one folder. that's it.
your folder is the package. I.e., if your java file has: package myPackage; then it just needs to be in a fold called myPackage. If you java file's package is: myPackage.subPackage.otherPackage then it would be in folder: myPackage/subPackage/otherPackage
1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.