Tampilkan postingan dengan label Eclipse. Tampilkan semua postingan
Tampilkan postingan dengan label Eclipse. Tampilkan semua postingan

Eclipse proxy setting

To enable Eclipse to connect to the internet through proxy:


  • set proxy settings in General -> Network Connections. Set for both HTTP and HTTPS BUT leave SOCKS empty! 
  • Active provider: manual

Websphere hot deployment and dynamic reloading

In the office we use Websphere AS and RAD as IDE. When you make changes to a Java class file, the changes are publised by the IDE to the AS, and the server restarts for the changes to take effect. This is in contrast to the changes done to JSP which do not require server restart to take effect. Actually there is a possibility of hot deployment and dynamic reloading (http://publib.boulder.ibm.com/infocenter/wsdoc400/v6r0/index.jsp?topic=/com.ibm.websphere.iseries.doc/info/ae/ae/trun_app_hotupgrade.html) which basically works like this: you replace the class file in the server with the new class file and the changes should take effect immediately without needing server restart. This is a very useful feature of WAS and it makes me wonder why the WAS plugin for RAD/Eclipse does not have a feature to enable this. I know there are limitations, like when you replace Hibernate entities or deployment descriptor, then you still need to restart the server but generally this feature is very useful during development.

So i decided to write an ant build file which runs when there is an automatic build. The job of this build file is basically to replace the class files in the server with the newly built class files in the workspace.

To do this, I first need to manually deploy the EAR via the WAS console. This is to make the exploded EAR file available in the server. Because when i deploy the ear by right clicking on the project -> run as -> run in the server, the exploded ear file is not there in the server! I dont know where, probably in one of the numerous plugin directories of the RAD/Eclipse installation.

After the ear file is manually deployed, then disable automatic publishing in the WAS plugin.


And then the ant build file:



Pretty obvious I guess. The src.osms is the workspace build directory while the des.osms is the WAS exploded ear directory. The most important part of the build file is the mnodified selector (https://ant.apache.org/manual/Types/selectors.html#modified) which selects only recently modified file (which is the file newly built by Eclipse automatic build) and copies these files to WAS.

Now, this ant build file needs to run everytime you modify a class file or anything, so enable automatic build on your project.

And then right click on your project -> properties -> builders -> new -> ant builders -> OK. You get this dialog
Choose your ant build file. Then click on the target tab and set the target for manual build and auto build. Done.


PS: if you have money, try JRebel.

ADB not recognized on newly installed Ubuntu 12.10

I just installed latest Ubuntu (12.10) on my office computer running Win 7. Problems soon appear.

The first is that from time to time the desktop became totally unresponsive. Paralyzed. I had to wait for a few minutes until my mouse clicks did anything at all.
After looking at top, I found out that the process mount.ntfs occupied 100% of CPU. So I got windows partition mounted and Ubuntu was doing something to it that hogged the resources. I don't know how to solve this... I installed this Ubuntu from Windows initially.

And then I needed to put Eclipse to the Unity launcher. Unity launcher is a vertical container of icons on the left side of the desktop, as in following picture:

How: 
1. Create a file with .desktop extension, containing info like this:

[Desktop Entry]
Version=
Name=Eclipse
Comment=
Exec=/home/switchlab/Documents/bin/eclipse/eclipse
Icon=/home/switchlab/Documents/bin/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=Application;

2. Put it in /usr/share/applications
3. In Dash Home, search for Eclipse and then drag and drop it to launcher.

I installed Android SDK, but then I failed to run adb eventhough I got it on my PATH. The error message said: No such file or directory. This is very weird. I checked that the adb did exist in platform-tools. So why this message? 

It turned out that this is caused by a glitch on my Ubuntu 64 bit installation. I had to do:
sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install ia32-libs

and everything worked fine again. I still haven't got a clue what that command does. Anyway, thanks goes to Scotty Delicious who wrote it here: http://askubuntu.com/questions/219465/cannot-install-ia32-lib-package

Hiero. Bitmap Font Tool

So I needed bitmap font atlas for my game. Bitmap font atlas is something similar to Image Atlas, only for font.

There's an open source code for it. The Slick project http://slick.cokeandcode.com/ The bitmap font tool is part of the project, which is located in the Hiero directory.

To correctly set it up as Eclipse project:

1. Create new Eclipse project. Copy the Hiero directory of the Slick project into the source directory of the new project.
2. Copy the lwgl.jar and lwgl-util.jar and slick.jar into the lib directory.
3. Copy the native (platform dependent) binary into some directory in the project structure.
4. Properties -> Java build path -> libraries then click on lwgl.jar and double click on native library location and in the resulting dialog, navigate to the directory where you saved the native binaries of lwgl for your platform.
5. Run the Hiero.java as Java application.

Or, if you still get errors or those steps are too much hassle, you can buy Glyphdesigner for USD 30. Glyphdesigner is better (not much better, just better) than Hiero, and it's easy to run and understand.

Debug Java applications remotely with Eclipse

I found this gem on IBM website when I looked for ways to debug my running applet. The original link:
http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html
Remote debugging can be useful for application development, such as developing a program for a low-end machine that cannot host the development platform, or debugging programs on dedicated machines like Web servers, whose services cannot be shut down. Other examples include Java applications running with limited memory or CPU power, such as mobile devices, or developers wanting to separate the application and development environments, etc.

Launch-configuration type

A launch configuration keeps a set of attributes that can be used to launch a program. The launch-configuration type is a unique type of program that can be launched in the Eclipse platform.
If you don't have it already, download Eclipse V3.4 (Ganymede). In Ganymede, the socket listening connector has been added to the Remote Java Application launch-configuration type. Eclipse's new socket listening connector allows you to start the Java debugger, which listens for a connection on a specific socket. The program being debugged can then be started with command-line options to connect to the debugger. Prior to the Ganymede release, only a socket-attaching connector was provided, and the program being debugged had to be a debug host that was connected by the debugger. It is impractical for mobile devices to be a host due to insufficient memory and CPU power.
To use remote debugging, Java Virtual Machine (JVM) V5.0 or later must be used, such as IBM® J9 or Sun Microsystems' Java SE Development Kit (JDK). In this article, we focus on remote debugging, rather than detail each of Eclipse's debugging features. See Resources for more information about debugging with Eclipse and where to find the aforementioned software.

Frequently used acronyms

  • JDI — Java Debug Interface
  • JDT — Java Development Tools
  • JDWP — Java Debug Wire Protocol
  • JPDA — Java Platform Debugger Architecture
  • JVM — Java Virtual Machine
  • JVMDI — JVM Debug Interface
  • JVMTI — JVM Tool Interface
  • VM — Virtual Machine
Sun Microsystems' Java Platform Debugger Architecture (JPDA) technology is a multitiered architecture that allows you to debug Java applications in all situations easily. The JPDA consists of two interfaces (the JVM Tool Interface and JDI, respectively), a protocol (Java Debug Wire Protocol), and two software components that tie them together (back-end and front-end). It's designed for use by debuggers in any environment. JPDA is not only for desktop systems but works well with embedded systems, too.
The JVM Tool Interface (JVMTI) defines that a VM must provide for debugging. (Editor's note: Starting with Java V5, JVMTI replaced JVMDI, which was used in Java V1.4.) The Java Debug Wire Protocol (JDWP) describes the format of debugging information and requests transferred between the process being debugged and a debugger front end, which implements the JDI, such as Eclipse, Borland JBuilder, and many others. The program being debugged is often called the debuggee in Sun's JPDA specification. The JDI is a high-level interface to define the information and requests used for remote debugging. The architecture is structured as follows.

Listing 1. The Java Platform Debugger Architecture
Components                      Debugger Interfaces

/ |--------------|
/ | VM |
debuggee -----( |--------------| <---- JVMTI - Java VM Tool Interface
\ | back-end |
\ |--------------|
/ |
comm channel --( | <------------ JDWP - Java Debug Wire Protocol
\ |
/ |--------------|
/ | front-end |
debugger -----( |--------------| <---- JDI - Java Debug Interface
\ | UI |
\ |--------------|

Therefore, any third-party tools and VM based on JPDA should work together without complaint. This client-server architecture allows you to debug a Java program from a local workstation running the platform, or even debug it from a remote computer on your network.
Before talking about the debug-scenario stuff, we need to introduce two terms used in the JPDA specification: connector and transport. A connector is a JDI abstraction used to establish a connection between a debugger application and a target VM. A transport defines how applications access and transmit data between the front end and back end. The connectors "map" to the available transport types and the modes of connection. In Sun's reference implementation of JPDA, two transport mechanisms are provided on Microsoft® Windows®: socket transport and shared memory transport. Available connectors:
  • Socket-attaching connector
  • Shared-memory attaching connector
  • Socket-listening connector
  • Shared-memory listening connector
  • Command-line launching connector
In establishing a connection between a debugger application and target VM, one side acts as a server and listens for a connection. At some later time, the other side attaches to the listener and establishes a connection. The connections allow the debugger application or the target VM to act as a server. The communications among processes can be running on one machine or different machines.
The problem with debugging a Java program remotely is not in the debugger front end but the remote Java back end. Unfortunately, there is not much information about this in the Eclipse help system. In fact, JDI and JVMTI are implemented by Eclipse and the Java runtime environment, respectively. The only thing we are concerned with is the JDWP, which contains the information to communicate with the JVMTI and JDI. The JDWP contains many arguments that have been added to invoke the application for the remote Java application. Following are some of the arguments used in this article.
-Xdebug
Enables debugging features.
-Xrunjdwp:
Loads the implementation of JDWP in the target VM. It uses a transport and the JDWP protocol to communicate with a separate debugger application. Specific suboptions are described below.
Starting from Java V5, you can use the -agentlib:jdwp option, instead of -Xdebug and -Xrunjdwp. But if you have to connect to the VM prior to V5, -Xdebug and -Xrunjdwp will be the only choice. Following are brief descriptions of the -Xrunjdwp suboptions.
transport
Generally, socket transport is used. But shared-memory transport can also be used on the Windows platform, if available.
server
If the value is y, the target application listens for a debugger application to attach. Otherwise, it attaches to a debugger application at the specified address.
address
This is the transport address for the connection. If the server is n, attempt to attach to a debugger application at this address. Otherwise, listen for a connection at this port.
suspend
If the value is y, the target VM will be suspended until the debugger application connects.
For detailed explanations for each debug setting, refer to the JPDA documentation (see Resources).
Listing 2 shows an example of how to launch a VM in debug mode and listen for a socket connection at port 8765.

Listing 2. Target VM acts as a debug server
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8765

Listing 3 shows how to attach to a running debugger application using a socket on host 127.0.0.1 at port 8000.

Listing 3. Target VM acts as a debug client
-Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000

Eclipse is a graphical Java debugger front end. The JDI is implemented in org.eclipse.jdt.debug bundle. In this article, we don't discuss the details of JDI implementation. See Resources for information about Eclipse JDT and Java JDI technology.
The first thing we want to know is which Eclipse connector to use. To learn the remote connection types provided by Eclipse, you can add a launch configuration in Remote Java Application by going to the Eclipse menu and selecting Run > Debug Configurations..., then selecting the connector from the dropdown list. Two connectors are provided in Ganymede:
  • Socket Attach
  • Socket Listen
For the socket-listening connector, the Eclipse VM will be the host to be connected by the remote Java application. For the socket-attaching connector, the target VM will be the host. There is no difference for application debugging between the two connectors — the user may choose. A good rule of thumb is to use the faster, more powerful computer as the VM debug host because of the computational resources required.
Before debugging your Java application, you may need to make sure the debug options are all enabled for your remote application. If that information is not available, you will get an error message, such as "Debug information is not available" or "Unable to install breakpoint due to missing line number." You can modify the settings from the Eclipse menu by changing what's set in Window > Preferences > Java > Compiler.

Figure 1. Debug options in Eclipse





We are ready to start debugging an application remotely. Let's do it step by step:
1. Create a Java project with a simple class
We create a simple class for debugging purpose. Listing 4 shows the sample code.

Listing 4. Sample code for debugging
package com.ibm.developerWorks.debugtest;

public class test {

public static void main(String[] args) {
System.out.println("This is a test.");
}
}

2. Set a breakpoint
Set a breakpoint in the code. In this example, we set the breakpoint in the line System.out.println("This is a test.");.

Figure 2. Set breakpoints in Eclipse
3. Debug the application locally
Before debugging your application, ensure that the debug options described in Figure 1 are enabled for the project. It's unnecessary to debug an application locally, but we can make sure all the debug information is available. Right-click on the Java project, select Debug As and select Java Application (see Figure 3). If the application execution is stopped at the breakpoint, the debugging information is presented correctly. You can continue to use the debugging features, such as displaying the debug stack, variables, or breakpoint management, etc.
Figure 3. Debug the application locally






4. Export the Java project




We will use this application as the debug target. Right-click on the Java project, select Export, select Java, then chooseJAR file or Runnable JAR file to export the project. The JAR file will be generated at the desired location. Be aware that if the Java source does not match the target application, the debug function will not work correctly.

5. Run the Java application manually
Open a console to launch the application manually to make sure the Java runtime environment is configured properly.
Listing 5. Sample to invoke Java application
java -jar test.jar
6. Debug the application remotely
Copy the JAR file to the appropriate location on the remote computer, or even the same machine, invoke the debug server, and then attach a client to it. The simple Java application can act as a debug server or client. Depending on the configuration, you can choose either Socket Attach or Socket Listen connection type in Eclipse. Learn how to run the application as a server or client in the following two sections.
The following example invokes the Java application on the remote side, acts as a debug server, and listens for a socket connection on port 8000. The target VM will be suspended until the debugger connects.

Listing 6. VM invocation sample for socket attaching mode in Eclipse
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address="8000" -jar 
test.jar

Start Eclipse using the remote launch configuration and specify the target VM address of the remote application. To do this, clickRun > Debug Configurations, and double-click the Remote Java Application in the Eclipse menu. From the newly created launch configuration, specify the IP and port for target application. To run the remote application in the same machine, simply specify the host IP as localhost or 127.0.0.1.

Figure 4. Configuration of socket-attaching connection






























Select Allow termination of remote VM option to terminate the VM to which you are connecting during application debugging.
Figure 5. Terminate button in Eclipse
The second example is to use a simple Java application that acts as a debug client, and the debugger front end acts as a debug server. Eclipse uses the socket listen-mode connection type for listening. The debug front end must be started in advance to listen on a specific port. Figure 6 shows a sample configuration to set up listening.

Figure 6. Configuration of socket-listening connection




























Click the Eclipse Debug button, and the status bar will show the message "waiting for vm to connect at port 8000..." When you see that, start the remote application. Listing 7 shows how to invoke the Java application as a debug client and attach it to a running debugger application using a socket on host 127.0.0.1 at port 8000.

Listing 7. VM invocation sample for socket-listening connection in Eclipse
java -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8000,suspend=y 
-jar test.jar

If everything goes well, the debug perspective will be displayed to support the application debugging, and the execution of the remote Java application will be stopped normally. This is similar to Step 3 that we did in local debugging (see Figure 3). At this point, you can use standard debugging functions, such as setting breakpoints and values, step execution, etc.
This article illustrated how to use the Eclipse built-in remote Java application configuration type to perform application debugging remotely. It introduced how to set up a Java application to invoke remote debugging and helped you understand the connectors Eclipse provides. Finally, you learned how to apply this technology to your projects.

Java resource consumption

So yesterday I fired up Eclipse, I did SVN update on my project and I ran the ant. And it took unusually long time to finish. 10 minutes! At some points, Eclipse occupied so much computing resource that it brought my computer to an unresponsive state. Mouse clicks would not respond. Neither would keyboard presses. I took print screen of the resource usage and it surprised me to see that java (Eclipse) occupied 228% of CPU. How could that be? 228%? Well I have quadcore processor, so does it mean that the maximum CPU percentage would be 400%? I also noticed that the signjar target of the ant was the most resource consuming. Following are the screenshots:


"Run as -> Ant build" disappear from pop up menu!

So.... this is weird. And inconvenient too. I was working on my Eclipse Helios and as I right click on my build.xml file, the "Run as -> Ant build" disappear from pop up menu! The cure is simple: Restart eclipse! But it caused some nerve at first because I had thought something went wrong and I had to do a lot of work to get it back to normal function.

New Eclipse. New Problems.

I got bored of my Eclipse Galileo for PHP. I no longer developed PHP and I used it to develop Java app, so I installed Java EE dev plugin and I thought it made the Galileo got rather bloated. I decided to download afresh Eclipse Helios for Java EE. I unzipped it and clicked the eclipse executable binary. Problems soon followed as I opened the projects I had previously worked on with my Eclipse Galileo.

  1. I no longer can connect to the SVN.
  2. I lost all of my run and debug configurations.
  3. Word completion does not work.
  4. I usually only needed to right click on a Java applet source code or Java code containing main class and choose run, and they ran, now I longer could do that.
I'll talk about all 4 points one by one. 

It turns out that Eclipse out of the box does not have Subversion (which is Eclipse plugin for SVN) installed. This is because installing Subversion is a 2 steps process: First you need to install Subversion plugin, which is provided by Eclipse, and then you have to install a separate connector which is provided by Polarion and not included in Eclipse due to licensing issue.

When I first tried to install Subversion, I did a stupid thing. I added subversion.tigris.org into the update address and then I installed the plugin provided by that address. After being installed, the plugin could not connect to SVN. The correct thing to install Subversion is as follows:
  1. Check for Helios update. Locate the "Collaboration" option. Install "SVN Team provider".
  2. After it is installed, try to connect to SVN repository or do something else SVN related. You will then be prompted to install Subversion connector from Polarion. Choose the latest SVNKit instead of the JavaHL option.
  3. Done!
Now you have "Team" menu when you right click on any Java file. 

But then on the 'Team" menu, I could not find "Update", "Synchronize" or "Commit" option as usual. It seemed that my newly installed Eclipse Helios did not recognize the SVN directories that were created by my previous Eclipse installation. I again did a stupid thing: I deleted all project on my disk and checked out all projects anew. 

I could have saved a lot of time by clicking "Team" and then "Share" instead. That would make my new Eclipse recognize the old SVN directories.

After I checked out all projects, I ran into new problems. I could not manipulate the source files like usual. The word completion did not work. It turns out that newly checked out projects are not recognized by Eclipse as Java project, that is why word completions do not work. So I had to delete the projects from workspace (but not from disk!) and then reopened them as Java projects.

One more tidbit, my projects came with Ant build files. I ran the ant. Failed. I fixed my project setting. I ran the ant. Successful. I tried to right click on my source file containing main class and chose run as Java application. Failed. It turns out I had to compile the project using Eclipse built in compiler in order to enable me to do that. So I cleaned the project (Project -> Clean) and then I could right click and run it. By the way, the option "Build automatically" in the Project menu means that the build will be executed automatically right after you clean the project.

Auto complete, Code Assist does not work in Eclipse

I checked out project from SVN into Eclipse. I tried to work on it, but when I hit Ctrl+Space, the expected Code Assist did not show up. What went wrong?
It turned out that Eclipse did not recognize the newly checked out project as Java Project. I right clicked and chose Properties, and I could not find the option to set the Java build path and lib.
To solve it, I had to delete the project from workspace. Only from workspace, not from disk. Then I reopened the project with: New project with existing source. And I tweaked the lib and build path. And there, Code Assist showed up again :)

Team -> Update is disabled/grayed out in Eclipse PDT

I recently installed Eclipse PDT (Eclipse package for PHP developer). Everything went well. It recognizes my existing Java project. Until today. I opened Eclipse, and when I right-click on a project to update it from SVN, the update menu is grayed out. Disabled. I didn't know what went wrong but I accidentally stumbled upon a simple fix. I deleted the project from the workbench (not from disk) and then re-opened it again. After being re-opened, the update menu is available again! My problem got solved but one question remained. What went wrong?

Enabling Ant, Searching for file containing certain text in Linux, Eclipse fails to run after crashing

I was importing project into Eclipse when I saw that there was no ant icon on .xml file. When I right click the build.xml, there was no option to run it as ant build. The solution is simple: just install Java EE Developer Tools Component.

I often need to search for files containing certain text in Linux. The following command does the magic:
grep -lir 'the text to be found' ./
I installed Eclipse PDT (Eclipse for PHP projects) and I tried to open a file with embedded applet. Eclipse crashed right away. After the crash, there was no way for me to start Eclipse again. After some searches, I stumbled upon this blog. I deleted the content of the .settings directory as explained in the blog, but Eclipse still failed to start. Then  Jason told me to remove user properties files. They could be found on the directory .metadata. This directory itself was located in the workspace directory. After I did that, Eclipse started, but I lost all of my workbench configurations and I had to redo all of the config. But it was better than not having Eclipse start at all. At least I learnt something new.