Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 293398

Summary: HTTP Preview Server does not start - "Could not find JRE executable"
Product: [WebTools] WTP ServerTools Reporter: Robert Elliot <rob>
Component: wst.serverAssignee: Elson Yuen <eyuen7>
Status: RESOLVED FIXED QA Contact: Elson Yuen <eyuen7>
Severity: normal    
Priority: P3 CC: amirco, arman.arbab, arvera, buckett, chris.mcclune, ckrintz, eclipse-dev, eclipsebugs, ftip, j.edward.rayl, jan.wloka, kimbaudi, l.wayne.james, lee_j_keith, of, ola.redell, softandbyte, stralf, super.zen, taa.eclipse_ide, thatnitind, VolkerMu
Version: 3.1Keywords: helpwanted
Target Milestone: 3.4.2   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
See Also: https://git.eclipse.org/r/109136
Whiteboard:
Attachments:
Description Flags
binary of the fix suggested
none
Prob exists in Indigo also
none
HTTP Preview Server bug fix for Eclipse 4.2 Juno eyuen7: iplog+, eyuen7: review+

Description Robert Elliot CLA 2009-10-27 04:15:51 EDT
I cannot start the HTTP Preview server - I get the following in the log:

org.eclipse.core.runtime.CoreException: Could not find JRE executable
	at org.eclipse.wst.server.preview.adapter.internal.core.PreviewLaunchConfigurationDelegate.launch(PreviewLaunchConfigurationDelegate.java:91)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:696)
	at org.eclipse.wst.server.core.internal.Server.startImpl2(Server.java:3010)
	at org.eclipse.wst.server.core.internal.Server.startImpl(Server.java:2960)
	at org.eclipse.wst.server.core.internal.Server$StartJob.run(Server.java:294)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


eclipse.buildId=M20090917-0800
java.version=1.5.0_20
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_GB
Framework arguments:  -product org.eclipse.epp.package.jee.product -keyring /Users/Robert/.eclipse_keyring -showlocation
Command-line arguments:  -os macosx -ws cocoa -arch x86 -product org.eclipse.epp.package.jee.product -keyring /Users/Robert/.eclipse_keyring -showlocation
Comment 1 Angel Vera CLA 2009-11-23 13:34:41 EST
Try setting the java.home to /Library/Java/Home and see if that works.
Comment 2 Robert Elliot CLA 2009-11-26 16:32:51 EST
Thanks for the suggestion; could you elaborate?  In Info.plist I have the following:

<string>-vm</string><string>/Library/Java/Home</string>

and typing "echo $JAVA_HOME" at the command line produces /Library/Java/Home.  However, I get the same error when I try and launch the HTTP Preview Server.

Looking in "Eclipse Installation Details / Configuration" I see this:
java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
That is what /Library/Java/Home ultimately resolves to, via several extremely convoluted symlinks:

/Library/Java/Home -> /System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Home -> Versions/CurrentJDK/Home
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK -> /System/Library/Frameworks/JavaVM.framework/Versions/1.6
/System/Library/Frameworks/JavaVM.framework/Versions/1.6 -> /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0

Is there something else I should be setting?  Is it that it doesn't work with a JDK and needs a JRE?  If so, is there any way to specify a JRE specifically for the Preview Server, as I need to run Eclipse via a JDK for some other plugins?
Comment 3 volker CLA 2010-03-02 17:03:39 EST
Hi,

I've the same problem.
But is there any solution?
Comment 4 Angel Vera CLA 2010-03-02 17:25:02 EST
I think the problem is related to the MAC OS system and the compatibility with JAVA. I am not sure of what the fix would be, but I have found some hits regarding java.home in MAC OS. 

I still need to look deeper into the preview server but I don't have a MAC OS around to play with so this has been hard to debug. It would be nice if the community can help us on finding out a fix for this problem. I can guide the community on how to debug the problem.
Comment 5 super.zen CLA 2010-08-15 04:26:22 EDT
I can help to debug this problem if you guide me.

I've got a Mac too.

I found on 
org.eclipse.wst.server.preview.adapter.internal.core.PreviewLaunchConfigurationDelegate

The following fragment of source code which returns always null if the platform is a mac:

  protected static File getJavaExecutable() {
     // do not detect on the Mac OS
     if (Platform.getOS().equals(Constants.OS_MACOSX))
     return null;


And on the same class there's the call to the method causing the error

// jre
File java = getJavaExecutable();
 if (java == null)
 throw new CoreException(new Status(IStatus.ERROR, PreviewPlugin.PLUGIN_ID, "Could not find JRE  executable"));


Tell me how I can help.
Thx
Comment 6 Angel Vera CLA 2010-08-16 11:41:53 EDT
(In reply to comment #5)
Thanks for your help. I would first try to remove that piece of code and setting java.home to something, but some article that I found online seemed to imply some problems around finding or setting java.home for the entire system.
Comment 7 Frank Tip CLA 2010-09-13 11:54:54 EDT
I just ran into the same problem? Is there any news on the status of this bug? It is a serious one, because it reduces Eclipse WTP on the Mac to not much more than an editor with keyword highlighting.

  -Frank
Comment 8 Angel Vera CLA 2010-09-14 15:01:49 EDT
Frank, 

The bug is marked as 'helpwanted' because we haven't had time to work on it in part due to not having the resources (a mac available). It would help if you can help debugging and find a solution for the problem.
Comment 9 Sven B CLA 2010-12-11 19:10:09 EST
I have the same problem 
How can i help you guys to fix this ?
I installed some extra web tools last time.
Comment 10 Angel Vera CLA 2010-12-14 18:31:55 EST
(In reply to comment #9)
We need someone to look at the code, change it and do test to ensure the problem is fixed.

You can use this tutorial to guide yourself on how to download the code:
http://www.eclipse.org/webtools/community/tutorials/DevelopingWTP/DevelopingWTP.html

The plugin you need to download is org.eclipse.wst.server.preview.adapter. After that refer to Comment #5 to find the class that needs to be modified. There is possibly more classes that need to be changed but you can start with the changes suggested in comment #5
Comment 11 Sven B CLA 2010-12-15 05:03:56 EST
i changed following

/org.eclipse.wst.server.preview.adapter/src/org/eclipse/wst/server/preview/adapter/internal/core/PreviewLaunchConfigurationDelegate.java

i placed following lines in comment
		//if (Platform.getOS().equals(Constants.OS_MACOSX))
	       //return null;


import org.eclipse.osgi.service.environment.Constants;
was in my test a unused import that i placed in comment.

when run that project my http preview worked perfect.

I dont know how i can build or resubmit that code can someone do it for me ? 
1. test also on windows.
2. test it again on MaxOSX after build.

just should when i need to test it on MacOSX

ps. i have no idea what can go wrong whit this change. ( i am a newbie programmer ;-) )
Comment 12 Angel Vera CLA 2011-02-08 11:09:43 EST
Created attachment 188530 [details]
binary of the fix suggested

Here is a binary version of the changes, I would like to hear more testing to ensure that the problem is fully fix. But the changes look safe enough that can be included in a build in the future. 

I just would like to here more testing and the levels of MAC OS where the fix was tested.
Comment 13 Ola Redell CLA 2011-04-25 18:14:39 EDT
(In reply to comment #12)
I have the same problem on Eclipse Helios and I tried the suggested fix without luck. I might not have done it correctly though. I replaced the file org.eclipse.wst.server.preview.adapter_1.1.0.v20090311b.jar under eclipse/plugins (renamed it to *.jar.old) with the attached one (org.eclipse.wst.server.preview.adapter_1.1.0.v201102081105.jar). 

I got another error message though: "The selection cannot be run on any server", and I got it even before I got a chance to select the preview server. It is the same error message that I get if I do not have any valid ...preview.adapter...jar file on the path.
Comment 14 Ola Redell CLA 2011-04-26 16:29:46 EDT
(In reply to comment #13)
Now I continued further and did the fix myself as suggested in 11. WIth my own fix the preview server appears to work fine when executed in the IDE environment, but when I export the .jar file and use it in my original installation I get the same problem as reported in 13 for the fix attached in 12.

Suggestions?
Comment 15 Angel Vera CLA 2011-04-26 16:34:41 EDT
(In reply to comment #14)
> (In reply to comment #13)
> Now I continued further and did the fix myself as suggested in 11. WIth my own
> fix the preview server appears to work fine when executed in the IDE
> environment, but when I export the .jar file and use it in my original
> installation I get the same problem as reported in 13 for the fix attached in
> 12.
> 
> Suggestions?

No need to remove the old jar the platform will pick the latest version. Try leaving the old jar there and just dropping the new one. Also if you have a /eclipse/dropins directory it might be best to place the binary jar there.
Comment 16 Ola Redell CLA 2011-04-26 17:02:26 EDT
(In reply to comment #15)
> No need to remove the old jar the platform will pick the latest version. Try
> leaving the old jar there and just dropping the new one. Also if you have a
> /eclipse/dropins directory it might be best to place the binary jar there.

OK, did that, tried both the plugin and dropin folder with original file still in plugin folder. In both cases I got the original problem back "Could not find JRE executable". Strange. Makes no sense.
Comment 17 Hendrik Hoefer CLA 2011-08-18 04:41:02 EDT
Created attachment 201700 [details]
Prob exists in Indigo also

Same problem in Indigo. The reason why the poposed patch (removing the test for OS-X) does not work for all is probably, that you'll need a java.home environment variable. 
Under Lion (OS-X 10.7) the JRE is accessible from /Library/Java/Home (can also be added as a standard JRE). I did a quick hack to the bundle:

protected static File getJavaExecutable() {
		File javaHome;
		// do not detect on the Mac OS
		if (Platform.getOS().equals(Constants.OS_MACOSX)) {
			try {
				javaHome = new File("/Library/Java/Home").getCanonicalFile();
			} catch (IOException e) {
				return null;
			}
		} else {
		
			// retrieve the 'java.home' system property. If that directory doesn't exist, return null
				
			try {
				javaHome = new File(System.getProperty("java.home")).getCanonicalFile();
			} catch (IOException e) {
				return null;
			}
		}
		if (!javaHome.exists())
			return null;
		
		// find the 'java' executable file under the java home directory. If it can't be
		// found, return null
		return findJavaExecutable(javaHome);
	}


and added the binary to this comment.

- Hendrik
Comment 18 Angel Vera CLA 2011-08-18 10:48:55 EDT
Transfering ownership to Elson, as I can't currently look into it.
Comment 19 Arjan van Bentem CLA 2011-12-05 10:00:23 EST
(In reply to comment #17)
Just to confirm that Hendrik's August 18th patch works fine for me. Mac OS X 10.7.2, Eclipse Indigo SR1.

(I guess the "do not detect on the Mac OS" comment still needs to be removed before merging this patch.)
Comment 20 Matthew Buckett CLA 2012-06-13 08:43:21 EDT
It would be nice to see this fixed, is there anything I can do to help this along?
Comment 21 Chandra Krintz CLA 2012-07-05 13:53:09 EDT
I have this same problem with Juno JEE and neither patch works for me.  Can I get one that replaces this jar please?  

org.eclipse.wst.server.preview.adapter_1.1.100.v20120517_1638.jar

thanks
Chandra
Comment 22 Paul Kim CLA 2012-07-15 16:15:16 EDT
I have Mac OS X 10.7 Lion and I installed Java, Eclipse Juno 4.2 Classic, and WTP to create Static Web Projects.

When I tried to run my static web project on the HTTP Preview Server, I also got the following error:
'Starting HTTP Preview at localhost' has encountered a problem. Could not find JRE executable.

I verified that java.home is set correctly.
System.getProperty("java.home") returns /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home.

I also set $JAVA_HOME environment variable under ~/.bash_profile: export JAVA_HOME `/usr/libexec/java_home`.
$JAVA_HOME also returns /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home.

I also downloaded the two fixes and put it in my eclipse/dropins folder.

I have spent the last day Googling and trying to fix this problem to no avail. I hope this bug will get fixed.
Comment 23 Paul Kim CLA 2012-07-16 02:58:17 EDT
Created attachment 218743 [details]
HTTP Preview Server bug fix for Eclipse 4.2 Juno

Attached is a proposed bug fix for the HTTP Preview Server in Eclipse 4.2 Juno. Basically the proposed bug fix will set the java.home environment variable to "/Library/Java/Home" for Mac OS X where the JRE is located.
Comment 24 Paul Kim CLA 2012-07-16 04:08:14 EDT
First of all, I also want to confirm that Hendrik's patch works for Eclipse Indigo SR2 on Mac OS X 10.7.4 Lion.

Second, I agree with previous comments that getJavaExecutable() method does not detect the JRE on Mac OS and it should look for the JRE under /Library/Java/Home.

To fix this bug for Eclipse 4.2 Juno, the getJavaExecutable() method in org.eclipse.wst.server.preview.adapter.internal.core.PreviewLaunchConfigurationDelegate.java should be modified so that it sets java.home to /Library/Java/Home.

	protected static File getJavaExecutable() {
		// set the 'java.home' system property on the Mac OS
		if (Platform.getOS().equals(Constants.OS_MACOSX))
			System.setProperty("java.home", "/Library/Java/Home");
		
		// retrieve the 'java.home' system property. If that directory doesn't exist, return null
		File javaHome;
		try {
			javaHome = new File(System.getProperty("java.home")).getCanonicalFile();
		} catch (IOException e) {
			return null;
		}
		if (!javaHome.exists())
			return null;
		
		// find the 'java' executable file under the java home directory. If it can't be
		// found, return null
		return findJavaExecutable(javaHome);
	}

I have created a patch and attached it as a proposed patch (in the form of a .patch file). I don't know how to create a binary of the proposed patch. Also, I don't think I have the authority/permission to create a binary of the proposed patch. Can somebody create a binary of the proposed patch? Or give me instructions on how to do it? This bug is so close to being fixed for Eclipse 4.2 Juno.
Comment 25 Keith Lee CLA 2012-08-16 10:57:28 EDT
I second that this really needs to be fixed for the Mac. Now that Juno is out, there is not an available package binary to replace the existing as there was in Indigo.
Comment 26 Olaf Flebbe CLA 2012-10-28 07:15:08 EDT
I can confirm that the patch fixes this issue.

I followed the instruction and rebuild this plugin and double-checked that HTTP Preview now worked.

Please apply upstream.

Cheers
  Olaf
Comment 27 Elson Yuen CLA 2012-10-29 08:46:24 EDT
Thanks for submitting the patch. Changes relased to 3.4.2 and 3.5.
Comment 28 Keith Lee CLA 2013-02-20 16:58:06 EST
The last comment in this thread indicates that a patch was released into 3.5, but the latest version of eclipse still has this issue. What gives?
Comment 29 Nitin Dahyabhai CLA 2013-02-20 17:46:33 EST
(In reply to comment #28)
> The last comment in this thread indicates that a patch was released into
> 3.5, but the latest version of eclipse still has this issue. What gives?

3.4.2 and 3.5 refer to WTP version numbers, not Eclipse project versions.  See http://projects.eclipse.org/projects/webtools for their dates.
Comment 30 Keith Lee CLA 2013-02-20 21:29:13 EST
(In reply to comment #29)
> (In reply to comment #28)
> > The last comment in this thread indicates that a patch was released into
> > 3.5, but the latest version of eclipse still has this issue. What gives?
> 
> 3.4.2 and 3.5 refer to WTP version numbers, not Eclipse project versions. 
> See http://projects.eclipse.org/projects/webtools for their dates.

Ah yes, ok. So I downloaded the 4.3 Kepler release for Mac which looks to include 3.5 of WTP, and the preview server fails to start, complaining about a class not found. Has anyone else seen this? Should a new bug be submitted?

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/webapp/WebAppContext
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.webapp.WebAppContext
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Comment 31 Nitin Dahyabhai CLA 2013-02-21 10:48:40 EST
Kepler is still in active development and won't be released until June.  What did you download, specifically what file name(s), and how did you install them?
Comment 32 Keith Lee CLA 2013-02-21 14:42:05 EST
(In reply to comment #31)
> Kepler is still in active development and won't be released until June. 
> What did you download, specifically what file name(s), and how did you
> install them?

I downloaded the 4.3 M5 pkgs from here: http://www.eclipse.org/downloads/index-developer.php

I was planning to test this fix, but ran into another preview server error.
Comment 33 Mirco Attocchi CLA 2013-03-04 13:13:08 EST
the same problem seems to occur with Juno SR2

Tested with Sun JDK 1.6.0_37-b06 and a fresh new workspace



(In reply to comment #30)
> (In reply to comment #29)
> > (In reply to comment #28)
> > > The last comment in this thread indicates that a patch was released into
> > > 3.5, but the latest version of eclipse still has this issue. What gives?
> > 
> > 3.4.2 and 3.5 refer to WTP version numbers, not Eclipse project versions. 
> > See http://projects.eclipse.org/projects/webtools for their dates.
> 
> Ah yes, ok. So I downloaded the 4.3 Kepler release for Mac which looks to
> include 3.5 of WTP, and the preview server fails to start, complaining about
> a class not found. Has anyone else seen this? Should a new bug be submitted?
> 
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/eclipse/jetty/webapp/WebAppContext
> Caused by: java.lang.ClassNotFoundException:
> org.eclipse.jetty.webapp.WebAppContext
> 	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
> 	at java.security.AccessController.doPrivileged(Native Method)
> 	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
> 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
> 	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Comment 34 Ralf Steinhaeusser CLA 2015-05-15 05:26:45 EDT
Hi there!

As I read in comment #27, this has been fixed in WTP 3.4.2 and 3.5.
I just installed Eclipse Helios (need that version for JavaScript) and as far as I see, Helios comes only with Web Developer tools V 3.2.3 where the bug still arises.

Can I install the newer WTP into Helios?
Or is there another way to fix this issue with the preview server?

Sorry if this is a dumb question. 
I am a complete newbie in Eclipse AND on the Mac.
Eclipse works fine on Win7 (where I am firm), but on my Mac this problem occurs. However, the MacBook is far more comfy to use, so i'd like to get it running there...

Thanks,
R.
Comment 35 Chris McClune CLA 2015-06-25 15:36:08 EDT
Hi

I am new to programming and I have encountered the 'could not find JRE executable' problem using my mac. I was trying to run some html code in a HTTP Preview server.

I need to use eclipse to create a project that includes HTML, php, javascript and also java. Is there a version that would allow me to do this that has the bug already fixed in the download? Or is it something I will have to try and fix using some of the previous comments?

Any help on this would be fantastic.

Chris
Comment 36 Ralf Steinhaeusser CLA 2016-02-15 16:29:47 EST
Ok, I just returned to my Mac after a 6months break. Installed the newest release of Eclipse Mars1 4.5.1 JEE, uninstalled the old Java and installed the newest JDK 8u73.
But still, when I try to start the preview server I get the message 

"Starting HTTP preview at localhost" has encountered a problem.
Could not find JRE executable

Looking into Eclipse/Settings/Java/Installed JREs
there is only one entry, "Java SE 8 1.8.0_73 (default)", it's highlighted and the path is correct.

Any tips for me?
Comment 37 Arman Arbab CLA 2017-06-06 17:21:07 EDT
I just downloaded a fresh installation of java 8 and eclipse neon on a new mac. I also get an error when running the HTTP preview server: "Starting HTTP preview at localhost" has encountered a problem. Could not find JRE executable", and I also get a null pointer exception when trying to set up a localhost HTTP server through eclipse. These error messages occur both on the Java EE version and on the Javascript/Web Development Version.
Comment 38 Eclipse Genie CLA 2017-10-11 16:39:06 EDT
New Gerrit change created: https://git.eclipse.org/r/109136