Link to home
Start Free TrialLog in
Avatar of wjh7554
wjh7554

asked on

Unable to find a javac compiler

I have this error when i am trying to start the Tomcat browser in the IE. I have successfully configure the Tomcat with Eclipse.

Exception:
Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

And when i type this in the commanda of this
D:\PROFILES\CKF034>echo %JAVA_HOME%
C:\j2sdk1.4.2_04\bin

D:\PROFILES\CKF034>echo %CLASSPATH%
C:\j2sdk1.4.2_04\bin;%CLASSPATH%


What else should i set?

Avatar of Mick Barry
Mick Barry
Flag of Australia image

try also setting CATALINA_HOMW to point to your tomcat installation
Avatar of slyong
slyong

CATALINA_HOME it should spell..
thanks :)
Make sure you have the *JDK* installed and not the JRE. The latter doesn't contain a compiler
Well, it *appears* that you do, although having JAVA_HOME set accordingly, any software needing the compiler should know where to look. Help it along by adding

%JAVA_HOME%\lib\tools.jar

to your classpath. %JAVA_HOME%\bin, btw, does not need to be in the classpath

If you have any classpath at all set like that, you should add

.


(the current directory) to the classpath too
> D:\PROFILES\CKF034>echo %CLASSPATH%
> C:\j2sdk1.4.2_04\bin;%CLASSPATH%

Those two lines actually looks strange.. echo %CLASSPATH% shouldn't give you %CLASSPATH% back?
>>echo %CLASSPATH% shouldn't give you %CLASSPATH% back?

That's normal

C:\Documents and Settings\Charles>set classpath=.;%CLASSPATH%

C:\Documents and Settings\Charles>echo %CLASSPATH%
.;%CLASSPATH%
I see.. that's how it gets in there.. my .bat always test for empty string ;)

IF x"%CLASSPATH"==x (
  SET CLASSPATH=.
) ELSE (
  SET CLASSPATH=.;%CLASSPATH%
)

If setting CATALINA_HOME doesn't fix it then try copy tools.jar to

%CATALINA_HOME%\common\lib
Check few of these things.

1. cd %JAVA_HOME% and check the cd works. Some times we set a directory to JAVA_HOME but the directory don't even exist. then
2. cd %JAVA_HOME%\BIN and <DIR javac and make sure the javac is listed.
3. Add %JAVA_HOME%\BIN to your PATH. If you are using W2k or WinXP then goto control pannel->system->advanced tab->Enivironment variable button->System variable->look for PATH variable and add the above to the path in the beggining. I hope this is the setting you might forgot to add to path which produces the error message 'javac not found'.
4. It seems that the CLASSPATH is not set to a correct value as mentioned by slyong. If there is a CLASSPATH it should point to a a list of path or archive files (jar,zip..etc) including full path, where the classes needed by your running java programs can be found. Normally CLASSPATH is not required to set nowdays globally. The java programs/batch file invoked at the command prompt, set the required CLASSPATH inside the program/batch file itself or the CLASSPATH can be passed as a parameter when you run the java program using java -classpath x:y:z program.java where x,y,z are the path or archive names with fullpath.
Make sure before adding the %JAVA_HOME%\BIN to your PATH variable, you defined the JAVA_HOME to point to java direcotry in the same way as I described for PATH variable in point 3 in my previous command.
Avatar of wjh7554

ASKER

ok. here is the funny setting

1.
i have changed the JAVA_HOME to point to JDK1.5.
D:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.5.0_02\bin

And also changing the CLASSPATH TO point to /lib/tool.jar
But when i still see this :
D:\>echo %CLASSPATH%
C:\j2sdk1.4.2_04\bin;%CLASSPATH%; C:\j2sdk1.4.2_04\jre\lib

**But in the Environment Setting, i enter this "C:\Program Files\Java\jdk1.5.0_02\bin;%CLASSPATH%; C:\Program Files\Java\jdk1.5.0_02\lib\tools.jar" **

What is wrong?

*************
2.
Then i ignore the above problems. I proceed with this suggestion :

If setting CATALINA_HOME doesn't fix it then try copy tools.jar to

%CATALINA_HOME%\common\lib

And when i start the tomcat, i got this error.

2005-12-12 17:25:56 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
javax.servlet.ServletException: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:195)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
      a
..
..
java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)
      at java.lang.ClassLoader.defineClass0(Native Method)

Avatar of wjh7554

ASKER

judej,

******
C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.5.0_02\bin

C:\>cd %JAVA_HOME%
Invalid directory

C:\>dir /w
 Volume in drive C is SYSTEM
 Volume Serial Number is 9CF8-59B3

 Directory of C:\

[Dell]               [Dev-Cpp]            [DRIVER]
[eclipse]            [gstools]            [j2sdk1.4.2_04]
[mvfslogs]           [Ntutils]            [PowerLink]
[Profiles]           [Program Files]      [Sun]
[systemwork]         [Temp]               [Valve]
[WINDOWS]            AUTOEXEC.BAT         BcBtRmv.log
comply.ini           CONFIG.SYS           DBS.TXT
drwtsn32.log         INFCACHE.1           Settings.ini
statusclient.log     SurgientDebug.log    Voice_File_Log.txt
              11 File(s)         16,972 bytes
              16 Dir(s)     461,006,336 bytes free

C:\>cd Programs Files
Too many parameters - Files
************
There is a folder of C:\Program Files\Java\jdk1.5.0_02\bin as i see it in Window Explorer. But why can't i cd into it?
Make sure you have set the classpath in the *system* vars - not user ones.

This is better btw

%JAVA_HOME%\lib\tools.jar
>>But why can't i cd into it?

cd "C:\Program Files\Java\jdk1.5.0_02\bin"
you've got two jdk's installed. make sure you use the only one with tomcat.

> What is wrong?

You need to open a new window after changing to see the changes
> But why can't i cd into it?

you need to wrap the name in quotes

cd "Program Files"
(The path contains the spaces from the ghastly 'Program Files')
you need to use tools.jar from your 1.5 jdk
>> Make sure you have set the classpath in the *system* vars - not user ones.

That goes for JAVA_HOME too
Avatar of wjh7554

ASKER

C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.5.0_02\bin

C:\>echo %CLASSPATH%
C:\Program Files\Java\jdk1.5.0_02\bin;%CLASSPATH%; C:\Program Files\Java\jdk1.5.
0_02\lib\tools.jar

C:\>echo %CATALINA_HOME%
C:\Program Files\Apache Group\Tomcat 4.1

C:\>cd "Program Files"
Parameter format not correct -  "Program
Avatar of wjh7554

ASKER

object, i am using the tools.jar for my 1.5 and paste it into the CATALINA_HOME\common\lib
Avatar of wjh7554

ASKER

confirmed. i am using 1.5jdk for it..
Avatar of wjh7554

ASKER

javax.servlet.ServletException: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:195)



java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)
      at java.lang.ClassLoader.defineClass0(Native Method)
Avatar of wjh7554

ASKER

">> Make sure you have set the classpath in the *system* vars - not user ones.

That goes for JAVA_HOME too"

Dont understand this.
>>i am using the tools.jar for my 1.5 and paste it into the CATALINA_HOME\common\lib

That's not really a good idea. When your JDK is updated you may find it breaks Tomcat and you'll forget why

>>
C:\>cd "Program Files"
Parameter format not correct -  "Program
>>

That's strange. You definitely copy and pasted that?
>>
java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main (Unsupported major.minor version 49.0)
     at java.lang.ClassLoader.defineClass0(Native Method)
>>

Too high. You'll have to find a Tomcat that supports 1.5 or lower the version to 1.4
Avatar of wjh7554

ASKER

CEHJ, YEs.. i copy and paste. no space in between
>>
That goes for JAVA_HOME too"

Dont understand this.
>>

*All* these vars under discussion should be system vars and not user ones
Set the JAVA_HOME to the home directory and not to bin directory. That is,
JAVA_HOME="C:\Program Files\Java\jdk1.5.0_02"

The bin directory not required in the CLASSPATH but must be added to PATH variable.
If you want to use a 1.5 version of tools.jar with Tomcat, then Tomcat will have to be built in >= 1.5. I don't know if that's possible. Anyone?
>> Set the JAVA_HOME to the home directory and not to bin directory.

Well spotted ;-)
Avatar of wjh7554

ASKER

cool.. i am trying out the jdk 1.4

*********
C:\>echo %JAVA_HOME%
C:\j2sdk1.4.2_04\bin

C:\>echo %CLASSPATH%
C:\j2sdk1.4.2_04\bin;%CLASSPATH%; C:\j2sdk1.4.2_04\lib\tools.jar

C:\>echo %CATALINA_HOME%
C:\Program Files\Apache Group\Tomcat 4.1

*************


BINGOOOOOOOOOOOOO it's working now.
http://127.0.0.1:8080/admin/index.jsp
the page come out...

ha....
Avatar of wjh7554

ASKER

**
All* these vars under discussion should be system vars and not user ones

***

ok. CEHJ, can you give example what is this mean? System vars??


What version of Tomcat are you using?

If it 4 then try 1.4, and if its 5 then use 1.5

and delete the contents of tomcats work directory

Avatar of wjh7554

ASKER

C:\>dir /w
 Volume in drive C is SYSTEM
 Volume Serial Number is 9CF8-59B3

 Directory of C:\

[Dell]               [Dev-Cpp]            [DRIVER]
[eclipse]            [gstools]            [j2sdk1.4.2_04]
[mvfslogs]           [Ntutils]            [PowerLink]
[Profiles]           [Program Files]      [Sun]
[systemwork]         [Temp]               [Valve]
[WINDOWS]            AUTOEXEC.BAT         BcBtRmv.log
comply.ini           CONFIG.SYS           DBS.TXT
drwtsn32.log         INFCACHE.1           Settings.ini
statusclient.log     SurgientDebug.log    Voice_File_Log.txt
              11 File(s)         16,972 bytes
              16 Dir(s)     460,226,048 bytes free

C:\>cd "Program Files"
Parameter format not correct -  "Program

Very funny Dos Command
>>ok. CEHJ, can you give example what is this mean? System vars??


"Setting environment variablesEnvironment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.

Any user can add, modify, or remove a user environment variable. However, only an administrator can add, modify, or remove a system environment variable.

Using System in Control Panel, you can customize the following variables:

User environment variables for logged_on_user_name
The user environment variables are different for each user of a particular computer. The variables include any that are set by the user, as well as any variables defined by programs, such as the path to the location of the program files.

System environment variables
Administrators can change or add environment variables that apply to the system, and thus to all system users. During installation, Windows Setup configures the default system variables, such as the path to the Windows files."

This assumes a reasonably recent version of Windows

Avatar of wjh7554

ASKER

CEHJ, thank you.

Is that means by setting the CLASSPATH TO this "%JAVA_HOME%/lib" for example will be pointing to system vars and not user vars "C:\j2sdk1.4.2_04\bin"

or by logging into the system using system admin id will be setting the value of the CLASSPATH will be store as system vars?
there are two sets of system vars, one for the system and the other for each user.

you don't actually need to worry about your classpath for running tomcat
User vars will override system ones, but of course are not global. You need global ones
Avatar of wjh7554

ASKER

allright folks.. i think my problems sovled.

Final Q for object and CEHJ, is both of you American or Australian? Cause based on this "slang", You need global ones, CEHJ is a Asian right?

I am from Malaysia...Chinese. :-)
I'm Australian :)
And i'm a pommie. (English ;-))
Avatar of wjh7554

ASKER

thanks..
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just like PATH is C++'s achilles heel for DLL's, the CLASSPATH is Java's achilles heel for classes... Having spaces in your classpath is problematic for any attempt to run javac or java from the command line as the parser will stop at the space and interpret the words following the space as the next command parameter.  Someone had mentioned setting JAVA_HOME to c:\program files\jdk1.5\bin but you can see the space between program and files will cause confusion.  At the command line, something like:

c:\> java -cp .;%JAVA_HOME% MyClass will likely generate a complain about class not found because the "files\jdk1.5\bin" from "c:\program files\jdk1.5\bin" will be considered the class name and MyClass would be thought to be the first parameter to be passed into "files\jdk1.5\bin"

 

I find it much better to use the shortened names for any directories or filenames that contain a space.  You can figure these out by using a Comand Prompt and using the /x parameter when issuing the dir command.  For example, from the c:\ root directory, if I issue dir /x I see an entry like:

 

01/06/2006  06:55 PM    <DIR>          PROGRA~1     Program Files

 

So, progra~1 is the short name for program files.  Basically, the first six characters plus a tilde (shift of the single quote) and a sequence number starting at 1.  In cases where the name has a space in the first six characters, the space is dropped as in AOLINS~1 for "AOL Instant Messenger".

 

When creating my PATH and CLASSPATH environment variables I always substitute the short names.  A simple way to check your path or classpath is to redirect their content to a file then use a text editor to find the next space.

 

For example, type the following at the Command Prompt:

c:\> echo %path% >path.txt

c:\> notepad path.txt

Then, in notepad, search for a space using Ctrl+F and press the spacebar once before searching.

Do the same for %classpath% to classpath.txt

 

If it doesn't stop at the end of all of the text, you've found a directory name that you should replace with its corresponding short name.  Be careful because notepad will wrap text if it finds a space, so you should use the search facilities rather than trying to eyeball it...

 

Using shortnames has the added benefit of taking less characters on the command line.  InstallAnywhere from Zero G Software has a problem when the classpath gets too long and reports an error:  LaunchAnywhere Error  Can't launch executable. Could not create Java VM.  OK

 

If you want to install your software, this isn't OK, and LaunchAnywhere should have a footnote reading "anywhere the classpath isn't too long or doesn't include spaces..."

 

To solve this problem should you encounter it, you can set your classpath to something very short in the Command Prompt window where you intend to launch the installer by issuing:

c:\> set classpath=.

c:\> setup.exe (or whatever the install program is named).

 

Because you are only setting the classpath within that command prompt window, you can exit and it will no longer have any affect on future commands (e.g., opening a new command prompt will have the environment variables set from the system environment variables).

 

To see your environment variables, simply type:

c:\> set

or, to review them, type:

c:\>set >set.txt

c:\>notepad set.txt

 

Best Regards, Nat

 

PS: I don't know your position on product recommendations, but I've found UltraEdit to be a wonderful, fast, powerful text and hex editor and is a much better alternative to notepad...  http://www.ultraedit.com