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)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_18">
        <attributes>
            <attribute name="owner.project.facets" value="jst.java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry combineaccessrules="false" kind="src" path="/Wake&amp;Sleep"/>
    <classpathentry kind="lib" path="E:/java projects/wakeShutWebservice/lib/axiom-api-1.2.8.jar"/>
    <classpathentry kind="lib" path="E:/java projects/wakeShutWebservice/lib/axiom-dom-1.2.8.jar"/>
    <classpathentry kind="lib" path="E:/java projects/wakeShutWebservice/lib/axiom-impl-1.2.8.jar"/>
    <classpathentry kind="lib" path="E:/java projects/wakeShutWebservice/lib/commons-logging-1.1.jar"/>
    <classpathentry kind="lib" path="E:/java projects/wakeShutWebservice/lib/log4j-1.2.14.jar"/>
    <classpathentry kind="output" path="build/classes"/>
</classpath>


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. MyMain is the class name for the program entry point.

Command prompt java classpath (run.bat)
java -classpath .;bin;lib/log4j-1.2.14.jar;lib/commons-logging-1.1.jar;lib/PingICMP.jar;
lib/axiom-api-1.2.8.jar;lib/axiom-dom-1.2.8.jar;lib/axiom-impl-1.2.8.jar;
resource MyMain
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
  1. Click on the project package.
  2. Go to menu Project>Properties
  3. Select "Java Build Path", click on the tab "Libraries".
  4. Select the JRE (Java runtime environment), and click edit.
  5. Choose Alternate JRE: jdk1.6.0_14
  1. if jdk1.6.0_14 option is not available, download and install the new JRE.
  2. Click on the button "Installed JREs..."
  3. Click "Add..."
  4. Go to JRE home directory:, click Browse...
  5. Go to the Java directory to find the installed JRE.
  6. Click ok all the way.
  1. Go to menu Project>Properties
  2. Select "Java Compiler", tick on "Enable project specific settings"
  3. Change the "Compiler compliance level" to 6.0.
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
1) Start>Settings>Control Panel>System>System Properties>Advanced>Click "Environment Variables"
2) Under "System Variables", select variable "Path"
3) Edit the path to include your desire path of your program.

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
Go to Project>>Properties>>Java Code Style>>Formatter>>Enable project specific settings>>New

//I don't like the following format
public void myFunction{
}

//My preferred format
public void myFunction
{
}


Useful Shortcuts for Eclipse. Ctrl+F11 -Run console
Ctrl+F2 -Stop console
Crtl+1 -assist
Crtl+Space -auto complete
Crtl+Shift+Space -assist
Ctrl+M -max coding space
Alt+(left/right) -scroll through history file
Alt+(up/down) -shift code selection up/down
Ctrl+click -go to declaration
Ctrl+Shift+F -format code style
Ctrl+Shift+G -find name