email:
website: http://www.siongboon.com
| Eclipse
classpath setup
Most of the time when my code couldn't compile, the problem is
most probably on the class path. Attached is a sample the classpath
file from one of my typical java project. This classpath is named as
.classpath and is found under the root of the Eclipse project folder.
This file is specially for Eclipse IDE to allow the runtime to locate
the files and resources required by the project. |
Eclipse java classpath example
(.classpath, another classpath example)
<?xml version="1.0" encoding="UTF-8"?>
|
If you are not using Eclipse to run your java project, and is using the command line prompt, the classpath will have to be indicated in your javac command. The following example is a window batch (*.bat) file that indicate the classpath and compile the java code through the command prompt. The shell script (*.sh) file is similar to the batch file, which is used in the Linux OS. The period "." is refering with reference to the executing or current directory."./bin" indicates that the subdirectory to be included in the classpath. The last parameters "MyMain" indicates the initial class object to invoke. The Java will attempt to execute the main(String[] args) method that is found in this class. MyMain is the class name for the program entry point. |
Command prompt java classpath
(run.bat for Windows OS, run.sh for Linux OS) run2.bat batch file with Ant example.
Command prompt java classpath (run.sh for Linux OS)
|
Shortcut file for Microsoft Windows user to open command prompt which starts at the local directory. Usually when you open a command prompt program, open up under the default directory, example "c"\users\abc\". You can delete away the "Start in" directory found under the cmd prompt shortcut *.lnk 's properties. If this *.lnk file is place under d:\mydir\myhome\. When you click on this lnk, it will open up a command prompt with the current directory which it is in, which is "d:\mydir\myhome\".
|
cmd prompt open current dir.lnk |
| Eclipse Java
compiler setup
Another common problem I have is to set my eclipse to the latest compiler version after installing the eclipse IDE (integrated development environment). Although I think that the installation process is quite simple, but I couldn't managed to get it configured without help from my senior teacher. Perhaps I am still unclear about the java environment. I wanted to get it cleared once and for all. Therefore I put
in this effort to write down the steps here for the future. I know that
I will probably forget once more. |
To change the Java compiler
version 6 for the project in eclipse
|
| Import existing Java project into
Eclipse - File>Import...>General>Existing Projects into Workspace - Select the project folder, then click Finish - click the file where your main() is, then click on run (Ctrl+F11) The project can be previously compiled without any error and might still encounter error after importing the project to the new PC. You might encounter the error for example: "Implicit super constructor Object() is undefined". Most issue is basically classpath set incorrectly. - On the left project navigation panel, right click on the project's Properties (Alt+Enter) - Select the option Java Build Path (left panel), and Libraries (right panel) You should see a list of classpath as from your previous project. There should be some icon with the red cross. Click on them and click Edit. Resolving the error will solve the issue. Very often the JRE version install on the new PC is different from the old. Sometimes the path of the libraries are wrong after the import (due to absolute path in the classpath). |
|
|
Importing *.jar and *.dll files to Eclipse Java project
1) copy the *.jar, *.dll to the folder "/project/lib" 2) right click the java project folder, and click on the properties 3) go to "Java Build Path>Libraries" 4) add the *.jar to the libraries 5) click on the *.jar package and link the required *.dll for the jar packages. 6) under Native Library location, select the directory path for the dll.
reference: http://www.eclipse-blog.org/eclipse-ide/exportingimporting-jar-files.html |
|
| Installing plugin for Eclipse 1) Run Eclipse program. 2) Go to Help>Install New Software...> Work with: --All Available Sites-- Key in the name of the plugin in the filter text field. 3) Select and install the plug-in. |
Installing plugin for Eclipse 1) Copy the plugin to eclipse/plugins 2) Run Eclipse program with an option -clean, "D:\eclipse\eclipse.exe -clean" 3) The plugin feature should be installed when the Eclipse is running. 4) To check if plugin is installed, go to Help>About Eclipse>Installation Details>Plug-ins Managing plugins using links 1) Create a folder "eclipse/links" in the eclipse installed directory. 2) Create a file *.link 3) File will contains the path to the plugin outside the eclipse installation directory. path=D:/thirdparty/wtp 4) The path should point to a directory which has a “eclipse” folder which in turn has “features” and “plugins” as sub-folders references: http://www.venukb.com/2006/08/20/install-eclipse-plugins-the-easy-way/ |
Setup environment path for
WindowXP, Vista
|
Reference
for Windows operating
system environment variables. eg. %APPDATA%, %PROGRAMFILES%,
%SYSTEMDRIVE%, %SYSTEMROOT%, %TEMP%, %USERPROFILE% -Environment Variables in WinXP.pdf |
| Formatter for your Java codes Eclipse comes with it's standard coding style. I am not used to the way the brackets appears on the code. Eclipse allow customization for the coding style. And I have attached it for my reference. - 2009-07-07 LSB style eclipse.xml To customised coding format
|
//I
don't like the following formatpublic void myFunction{ //My preferred formatpublic void myFunction |
| Useful Shortcuts for Eclipse | Ctrl+F11 -Run console
more amazing shortcut key, |
Editor Templates 2011-01-18 Eclipse template. What I have just learned today. They are the shortcut keyword to auto generate codes in Eclipse. After programming Java in Eclipse for so long, I started to become lazier and lazier, looking for shortcut. As short as possible. You may get boring typing the same while loop, delay function, data iterator. In fact, most of the time, I copy the codes from my old programs and do a bit of modification to fit the new program. If you are starting to get bore with typing all those codes again and again, I am sure you are going to like what I have learned today; Eclipse template. Let's say you need to code your main method that we always have as our program entry. Type in the word "main" and then press Ctrl+Space. You will see a menu pop up indicating a text icon with the text "main - main method". Double click on this option and pop, your main method is completely generate in an instant.
type "main" & press Ctrl+Space
The main method is generated immediately . That's cool. There are many code generating keyword which are already built in as default. Keyword for example, while, if, etc... The loops variables are auto generated. The best part is being able to customise your own code generation. I enjoy using those code generation using my way of writing the Java codes. To do the customisation, you have to change the preference.
Click on the button New, to start adding your own shortcut code generation. For example, to generate the logger statement when I type "log" Name: log
Other example: Name: getLog Name: while
There are many example in the default template for your reference. The settings can be export/import. I have saved my template here for use.
Code Templates The code template is a bit similar to the editor templates. When eclipse help us to auto generate the setter or getter methods, it is actually using the code templates to do the job. To do the customisation, you have go to. My code templates is as follows, |
|