• Post Reply Bookmark Topic Watch Topic
  • New Topic

Javac question  RSS feed

 
nick woodward
Ranch Hand
Posts: 382
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just trying to learn how to cut the IDE out of my programming, in an effort to understand how things work more completely.

I've added C:\Program Files\Java\jdk1.7.0_55\bin to the environment variables (path), am navigating to the src folder where my java class exists in cmd prompt, and then typing "javac CaesarCipher.java", but its complaining that it can't find the file.

Is the problem something to do with the relative address of the compiler to the file it needs to run? Just a stab in the dark on my part. Or do I have to add the JRE path as well as the compiler?

Thanks a lot guys, this place has been invaluable, am steadily starting to understand!! (although swing and listeners are a bit of a pain in the arse atm!)

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is exactly the error message that you get (copy & paste it here)? Does the error message say that it cannot find javac.exe (something like "Command not found") or does it say that it cannot find your source file "CaesarCipher.java"?

Does the current directory contain the file "CaesarCipher.java"? (Check with the "dir" command). Did you save it with Windows Notepad? Then it might actually be named "CaesarCipher.java.txt" (because Notepad automatically adds the ".txt" extension). Windows Notepad is not good for programming; if you want to use a text editor, use a better one such as Notepad++, TextPad or Sublime.

Is your class in a package? If yes, then first of all your directory structure needs to match the package structure, and then you should compile it from the base directory of the package; for example if it's in a package named "com.myproject", then "CaesarCipher.java" should be in a directory "com\myproject" and you should compile it from the base directory of the package:

C:\MyProject> ; the base directory that contains com\myproject\CaesarCipher.java
C:\MyProject> javac com\myproject\CaesarCipher.java
C:\MyProject> java com.myproject.CaesarCipher
 
nick woodward
Ranch Hand
Posts: 382
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:What is exactly the error message that you get (copy & paste it here)? Does the error message say that it cannot find javac.exe (something like "Command not found") or does it say that it cannot find your source file "CaesarCipher.java"?

Does the current directory contain the file "CaesarCipher.java"? (Check with the "dir" command). Did you save it with Windows Notepad? Then it might actually be named "CaesarCipher.java.txt" (because Notepad automatically adds the ".txt" extension). Windows Notepad is not good for programming; if you want to use a text editor, use a better one such as Notepad++, TextPad or Sublime.

Is your class in a package? If yes, then first of all your directory structure needs to match the package structure, and then you should compile it from the base directory of the package; for example if it's in a package named "com.myproject", then "CaesarCipher.java" should be in a directory "com\myproject" and you should compile it from the base directory of the package:

C:\MyProject> ; the base directory that contains com\myproject\CaesarCipher.java
C:\MyProject> javac com\myproject\CaesarCipher.java
C:\MyProject> java com.myproject.CaesarCipher


"javac: file not found: CaesarCipher.java"

so i'm pretty sure the javac is being found, but not the class itself.

edit: haha. sorted by checking the directories - sorry, must have messed up somewhere along the way! I wasn't in the src folder.


on a slightly related note - in order to use an external library in cmd prompt do i have to add the library to the environment variables? the program works in the IDE because I imported the .jar, but I have no idea what the command line equivalent is.

thanks again though! very quick and informative!!

 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want the -cp option.
See here.
 
nick woodward
Ranch Hand
Posts: 382
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:You want the -cp option.
See here.


perfect. thanks a lot!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!