-1

I have root-like this

├── appointment
└── src
    └── main
         └── java
               └── com
                    └── sendemail
                             ├── MainAppointment.java
                             └── SendMail.java

All is working and compiled as expected by running via the IDE(IntelliJ). by running javac MainAppointment.java from other then the sendemail package the files are not found while running the javac MainAppointment.java command from the sendemail directory cannot find symbol error is returned

Any idea how to resolve this?

greg-449
  • 109,219
  • 232
  • 102
  • 145
yigal92
  • 1
  • 1
  • You should learn to build your projects with maven. – tgdavies Jul 04 '22 at 06:01
  • Please add more details to your question. For example, show us the exact javac command you're using and the error message it produces. – Olli Jul 04 '22 at 09:25
  • Hi, the javac command I executed is javac com/sendemail/MainAppointment.java and the error is : – yigal92 Jul 05 '22 at 12:14

1 Answers1

0

If you are going to compile by hand, you should not run javac in any directory other than your source directory; i.e. the one that contains the top-level package(s) as direct subdirectories. That means you will need to do something like this:

  $ cd appointment/src/main/java
  $ javac com/sendemail/MainAppointment.java com/sendemail/SendMail.java

(OK it might be possible to do it using the -sourcepath and -cp and -d options but it is messy. But either way, you may develop RSI from all of the typing. Not to mention the time you waste looking for "bugs" that are actually caused by not building correctly; e.g. this one!)

A better idea is to learn to a build tool. It looks like this project has been set up with the standard Maven project structure. (Is there a "pom.xml" file in the "appointment" directory?) So Maven would probably be the tool to use.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks for the answer, unfortunately it doesn't help the returned error is : javac: file not found: com/sendemail/SendMail.java Usage: javac use -help for a list of possible options yes I have pom.xml file by running the mvn clean install command it building the project (jar is created) but it is not executing the commands in the code – yigal92 Jul 04 '22 at 06:28
  • 1) Did you `cd` to the directory above "com"? Can you see the 2 Java files with the those relative paths? 2) *"... but it is not executing the commands in the code"* - that sounds like a different problem; i.e. a bug in your code. – Stephen C Jul 04 '22 at 06:33
  • yes, the directory was appointment/src/main/java, I can see them both under those relative paths – yigal92 Jul 04 '22 at 06:55
  • Well I cannot explain why `javac com/sendemail/MainAppointment.java com/sendemail/SendMail.java` does not work for you. Look at https://riptutorial.com/java/example/15658/the--javac--command---getting-started ... and search for `javac com/example/*.java`. That is analogous to what I said to you. – Stephen C Jul 04 '22 at 07:25
  • (It is also possible that the `cannot find symbol` is caused by something else; e.g. a problem with the classpath, or an error in the code you are trying to compile.) – Stephen C Jul 04 '22 at 15:00