Eclipse – Create and publish a static web project in Eclipse

eclipse

when I tried to create and publish a static web project in eclipse I got: "Error copying file index.html: No such file or directory"

My environment: SuSE 12.2, Eclipse Indigo Release 2, Apache2 2.2.22,

This is what I did to create the project:

1) Create new Server

  • Basic, HTTP Server
  • Publishing Directory: /srv/www/htdocs
  • Enable publishing to this server: true

2) Create Project

  • New -> Static Web Project
  • Project Name: Simplepage
  • Target Runtime: HTTP Server (from 1)
  • Default Configuration
  • Content root: Simplepage
  • Web content folder name: WebContent

3) Create very simple page

  • Create new HTML file
  • Parent folder: Simplepage/WebContent
  • Name: index.html
  • Content:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=${encoding}">
    <title>Insert title here</title>
    </head>
    <body>
    Test
    </body>
    </html>

4) Start Project

  • Right Click on Project Name -> Run as -> Run on Server

Here I got the error message mentioned above.
At this point there is a new folder /srv/www/htdocs/Simplepage created but has no content.

Later I made a test with the following configuration:

  • Change publishing directory to: "/srv/www/htdocs/XY"

Start Project gives error: "Access forbidden! You don't have permission to access the requested directory…"

At this time there is a new directory created: /srv/www/htdocs/XY/Simplepage containing the file index.html.

The window in eclipse is showing the path http://localhost/Simplepage/. When I change this manually to http://localhost/XY/Simplepage/ the newly created page is shown.

I don't understand this behaviour. Can someone explain this?

Best Answer

You have installed Apache2 server on your home computer, with the publishing directory /srv/www

Note that Apache2 runs on its own user (on my Ubuntu it is www-data). Apache's publishing directory /srv/www is normally owned by Apache's user.

You have also directed HTTP Server of Eclipse to the same directory. Note that this server is different from Apache; it is run by Eclipse inside its belly, and usually on different ports from Apache, to avoid port conflict. I think this server is run on the same user Eclipse runs, i.e., your regular user on your home comp.

I think that the error messages you get, are permission mismatch: Eclipse cannot publish in directories owned by Apache's user.

The solution is not to try to use Apache's directories but rather the default directories of Eclipse.

I have explained this in more detail here: Eclipse Web (http) servers: Debugging and publishing http files in Eclipse.

I do use both Eclipse' HTTP Preview server and Apache2:

  • Eclipse' HTTP Preview server for files I work on in Eclipse, and
  • Apache2 to run a localhost copy of my Wordpress site.

When files I work on in Eclipse, are mature, I transfer them manually to Wordpress as posts or pages.