Pergunta

When opening Eclipse I can write and run programs in Java, but when I enter javac programname.java, it says the file can not be found.

In short: eclipse is finding the jre7 but cmd (even after making sure file was in the path cmd was looking in), cmd wont execute the programs.

How can I fix this?

Foi útil?

Solução

Eclipse does not require "javac" to compile Java source files since its JDT project supplies a compiler of its own. It's entirely possible that you do not have javac--it requires installing the JDK, not just the JRE that Eclipse itself requires--and that it would not be on your path as a result.

Outras dicas

I believe your environment variable is not set properly.

If you are using windows then create a System Variable JAVA_HOME with the path of the jdk

JAVA_HOME = C:\Program Files\Java\jdk1.7.0_45

Then add this in the Path variable %JAVA_HOME%\bin

If you are using Linux then do the following :

  1. Open the bash profile

$vim /etc/profile

And at the end of the file include the following lines. Wherever you have unzipped the java directory add that path only.

  1. export JAVA_HOME=/usr/java/jdk1.7.0_45

  2. export PATH=$PATH:/usr/java/jdk1.7.0_45/bin

For other shell's in Unix , Have a look at the JDK Doc.

Seems to be your java installation is corrupted. I think you should reinstall java. also You should ensure that you're installing the right jre for your architecture.

If you go in to this link since you are getting cfg error, you will get the exact answer Go to this

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top