Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Monday, March 18, 2013

Eclipse shortcuts

   
Ctrl+Shift+O organize imports
Ctrl+Shift+M Add imports
Ctrl+Alt+H Show call hierarchy
Ctrl+T Show type hierarchy
Ctrl+1 quick fix
Alt+Shift+J Add comments
Ctrl+I correct indentation
Ctrl+Shift+Space show parameter hints
   
Ctrl+D delete a line
Ctrl+Shift+Delete Delete to the end of line
Alt+Up/Down move current line
Ctrl+Q jump to last-edit place
Alt+/ auto-completion
Ctrl+Alt+J Join lines
Shift+Alt+Up Select Enclosing Element
Shift+Alt+Left Select Previous Element
Shift+Alt+Right Select Next Element
   
Ctrl+O open outline dialog
Ctrl+Shift+R open resource dialog
Ctrl+E show opened files
Ctrl+Shift+E open a dialog showing opened files
   
Ctrl+Shift+P jump to matching parenthesis
   

Sunday, November 14, 2010

How to build Hadoop in Eclipse

Subclipse

  1. Install SVN
    I installed "Slik-SVN" because it provides JavaHL lib for 64bit Windows.
  2. Install Subclipse plugin to Eclipse.
  3. Change eclipse.ini to add following parameters after -vmargs:
    -Djava.library.path=/usr/share/jni/lib (For linux)
    -Djava.library.path=<svn_install_dir>/bin (For Windows)
  4. Start eclipse
  5. Goto WIndow --> Preference --> Team --> SVN
    In section "SVN Interface", it should say something like "JavaHL (JNI) … SlikSvn". If it says "JavaHL(JNI) not available", it means subclipse cannot find JavaHL library. Check step 3).

Code checkout

Example: svn co http://svn.apache.org/repos/asf/hadoop/common/tags/release-0.21.0/
You can also check out code within Eclipse using Subclipse plugin.

Install Ant and Ivy

Read http://ant.apache.org/ for how to install Ant.

Download ivy jar and put it into directory ANT_HOME/lib/. If ANT_HOME is not specified explicitly, it is the installation directory.

IvyDE

Hadoop is managed by ivy. You need IvyIDE Eclipse plugin. Read http://ant.apache.org/ivy/ivyde/ for more info. IvyDE includes ivy jar file itself. So it does not use the ivy jar you installed in last step. Also it seems that ANT_HOME variable is set to <eclipse_dir>\plugins\org.apache.ant_1.7.1.v20090120-1145 (version number may vary for you).

Shell and Unix commands on Windows

Hadoop build file invokes sh and some other linux commands such as tr, sed to build the project. Of course those commands don't exist on Windows.

Following two projects port linux tools to Windows:

  1. http://sourceforge.net/projects/win-bash/files/win-bash/
  2. http://unxutils.sourceforge.net/

I use the first one. You just download the tarball and decompress it to a directory. This directory must be passed to Ant. The usual way is you put it into environment variable "PATH". Ant will pick it up automatically. It's true for command line use of Ant. It does not work well for Ant within Eclipse. Following sections include instructions about how to pass PATH to Ant in Eclipse.
For command line use, try command "ant compile".

Create Eclipse Project for Hadoop

  1. New --> Java Project
    Select "Create project from existing source". Then select the directory where code is located.
    Click "Next"
  2. CHANGE OUTPUT DIRECTORY TO <workspace_name>/build.
    The default directory bin is used by Hadoop for different purposes.
    Click "Finish"
  3. Add JDK's tools.jar to build path.  It is not included in JRE.
  4. Change source directories to tell Eclipse which directories include Java source code.
    Right click project name --> Build Path --> Configure Build Path… --> Source
  5. Make IvyDE to manage ivy dependencies.
    Right click project name --> Build Path --> Configure Build Path… --> Libraries --> Add Library --> IvyDE Managed Dependencies --> Next --> (couple of  IvyDE setting steps) --> OK.
    It may take some time for IvyDE to resolve dependencies.

Create Run Configuration

  1. Right click "build.xml" --> Run As --> Ant Build … (not "Ant Build")
  2. A dialog should pop up
    1. Switch to "Targets" tab: select corresponding target (e.g. compile) you want to execute.
    2. Switch to "JRE" tab: select "separate JRE"
    3. This step is for Windows users.
      Switch to Environment Tab: set PATH. (to include where those linux tools are included on Window)
      You can click "Select" and choose variable "Path". But in my case, its value does NOT include all of the content of the variable (use "path" command in command line). probably, Eclipse has some restriction about length of value of environment variable. If it's too long, it will be truncated.
    4. Click "Run"
  3. See Console for messages.

Customize project builder

It's more convenient to use "Builder" than right click "build.xml" --> Run As --> Ant Build … --> Run. Following steps tell you how to use ant as default builder. Then you can use "Project-->Build Project" to build your project (same as any regular native Eclipse Java project).

  1. Right click project name --> Properties --> Builder --> New --> Ant Builder
    1. Select the build file (usually "build.xml").
    2. Switch to "Targets" tab.  Specify which targets are executed when the project is built or cleaned.
    3. This step is for Windows users.
      Switch to "Environment" tab. Add PATH environment variable if needed. (to include where those linux tools are included on Window)
  2. Deselect default java builder.

Monday, June 30, 2008

Change font in PDT

The way to change font in PDT is not intuitive.  PDT does not support configuration of font itself. Instead, it inherits global configuration. By click "windows->preference->Apperance->Colors and Fonts", you will get:
image 

Although there are two entries related to PHP, they are useless in fact. You can not configure them. Instead, you may think configuration of entry "Basic" should work. But, you are wrong. You should configure entry "Structured Text Editors" to configure fonts which will be used by PDT PHP editor. I don't why PDT chooses to inherit font setting from "Structured Text Editors".

PHP development environment

[PHP IDE]
PHPEclipse: A plug-in of Eclipse.
PDT: a new PHP IDE which is also a plug-in of Eclipse. It is supported by Zend.
Aptana with PHP plug-in: Aptana is excellent tool to develop web2.0 applications. It excels at CSS + JS... I don't know whether its support for PHP is good as well.

[PHP Debug]
XDebug: This is a PHP extension which provides a lot of valuable debug information. Its installation is fairly simple. Users just need to download the extension, put it into PHP ext directory and modify php.ini file.
DBG PHP Debugger:
Zend Debugger: I googled and found this debugger. But I could not find related documents. So actually I don't know how to use it.

[PHP Test]
SimpleTest: A unit testing tool for PHP.

Finally, I selected PDT+Eclipse as my IDE. I found this article which describes how to debug in PDT. PHP programs can be debugged locally or on a remote server. PDT supports Zend Debugger and XDebug. PDT all-in-one package is suitable for those who want a new Eclipse+PDT+Prerequisites. If you have already installed Eclipse, you can just install PDT as plug-in. The latter is what I chose. After installing PDT, you need some configurations.
Instructions about how to configure and use all-in-one PDT package are listed here.

[Configuration of PDT]
Procedure to build PHP PDT environment not using all-in-one package:
(1) Install PHP and Debugger
To use PDT, first install PHP(I am using PHP 5.2.6). Then install corresponding PHP debugger module you choose(xdebug or zend debugger). My PHP version is 5.2.6 and I downloaded XDebug module from here. Then you need to configure PHP (modify php.ini) to use the debugger. Installation instructions about XDebug is here. After configuration, restart your web server to see whether XDebug is configured correctly. Function phpinfo() can be used. Or you can use command "php.exe -m" to list the loaded modules and XDebug should be in the Zend Module list.
(2) Configure PDT in Eclipse
If you don't use PDT all-in-one package, you need lots of configuration work.
There are two modes in which PHP can be run: script mode and web mode.
In web mode, you need a web server(e.g. Apache httpd) to host PHP applications and you can test your apps by accessing those PHP pages through browser. Generally, this is the way we publish our PHP programs when we finish.
In script mode, your PHP programs can be run by an independent executable file. PHP package provides an executable file called php.exe which can be used to execute your PHP program.
image
The most important configuration options are "Debug", "PHP Executables", "PHP Servers". 

[Run/Debug]
You can debug and run your PHP program in both modes in Eclipse. When you open Run/Debug dialog in Eclipse, following dialog should be displayed:
image
Note the two entries within red box. If you want to debug/run program as script, you should configure "PHP Executable" correctly. If you want to debug/run program on a web server, you should configure "PHP Server" correctly. Meanwhile, you should select the debugger you would like to use. This must match the debugger module you actually installed. If you install a Zend debugger for PHP while you set XDebug as your debugger in Eclipse, something unpredictable may occur.
You also can set the debug scope by clicking tab "Advanced":
image
Usage of these options is(The explanation is from help document of PDT):

  • Debug All Pages - The specified page and all the pages linked to it are debugged. The browser waits for the debug of each page before displaying it.
  • Debug First Page Only - Only the first page is debugged.
  • Start Debug from - Select the URL from which you would like the Debugging process to start.
  • Continue Debug from this Page - Selecting this option will result in all the pages linked to the URL being debugged.

When you debug PHP program in web mode(In script mode, you don't have this concern.), you must explicitly terminate the debugging process. When you click button "resume" to make the program execute until completion, the program actually does not terminate. One bug? or annoying thing is that the "Terminate" button in debug toolbar is disabled which gives users illusion that the debugged program is terminated. This illusion is natural because users don't have way to terminate the debugged program. However, the debugged app is still alive and waiting for new incoming requests. One way to terminate the debugged app is that: once more you access the debugged web page, and when the debugger stops at a breakpoint, click button "Terminate"(not button "Resume") to truly kill the debug process. Another way is that when you click an arbitrary statement in window "Debug", button "Terminate" is activated and enabled.

[Deploy]
To test programs in web mode, a web server is necessary. In my case, web server is located in my local machine as well. One way to deploy the program during development is configure Apache httpd to change its document root to point to your development root directory. However, this is not good because other applications which don't reside in your current development root will not work. My solution is to use HTTP Server configuration in Eclipse. First, I add a new HTTP server to Eclipse.
image 
Then I add the PHP application to that HTTP server:
image
When I change a source file, Eclipse will automatically publish newest version of the file to the directory specified in HTTP Server configuration. I let it point to my original Apache Httpd document root.

[Issues]
One issue I have not figured out is how to use the "Path Mapping" when PHP Server is set:
image
I don't know what that means. Hopefully, I will figure it out tomorrow.

Now, I know how to use Path Mapping.
When you run/debug your PHP page on web server, PDT needs a mapping relationship between remote document directory and current working directory. As you all know, client can not retrieve PHP source file by accessing it in browser. What is returned is output produced by PHP interpreter and web server. In other words, PDT has no way to get the PHP file you want to run/debug from remote web server. Instead, you must maintain a copy in local directory.
In my case, remote PHP URL is at http://localhost/php (I run web server on my local machine). And my Eclipse PHP working directory is different. Then I create a path mapping: "E:\Program Files\Apache Software Foundation\Apache2.2\htdocs\php\TestPHP" => "/TestPHP"(Path in Eclipse workspace, you also can use absolute path in file system). When I access http://localhost/php/TestPHP/test.php, the file /TestPHP/test.php is displayed and traced in Eclipse debug window. The php file on remote server is debugged and local PDT communicates with remote server/debugger by specific debugging protocol. Apache http server will check the existence of requested php file before it transfers processing control to PHP interpreter. If no corresponding php file is found by web server, error message is returned. If content of file on remote server and content of local file is different, weird behaviors may occur. Generally, they should be identical.  To sum up, debugging occurs on remote server and PDT uses local php source file to display debug information and let user control (step in, step over...) the progress of debugging.