Posts

Showing posts with the label Eclipse

Restlet HelloWorld Example in Java and Eclipse

The Restlet is one of the first open source frameworks to create and deploy RESTful web service in Java. After the release of JAX-RS (Java API for RESTful Web Services) JSR - 317, Restlet also supports JAX-RS annotation and provides a consistent way to create both RESTful Server and Client. HelloWorld program is the traditional way to start with a new technology and continuing to the tradition, we'll write our first Restlet program as HelloWorld. Since Restlet can be used to create on both client and server side, we'll first expose a resource as RESTful web service using Restlet server and then consumer the same RESTful web service by creating a RESTful client. I'll use Maven and Eclipse to create this RESTlet HelloWorld example , if you are not familiar with Maven, it's a build automation tool like ANT for Java projects but also provides dependency management i.e. you don't need to download Restlet JAR manually, Maven will do it for you. To learn more about Maven...

How to increase heap size of Eclipse - Solving OutOfMemoryError

If you are running lots of Java projects in Eclipse and it's throwing OutOfMemoryError every now and then it's time to increase the heap memory of Eclipse. Since Eclipse is a Java program, you can increase heap size of Eclipse by using JVM memory options -Xms and -Xmx. There are two ways to provide JVM options to eclipse either updating Eclipse shortcut or adding -vmargs on eclipse.ini file. I prefer the second option because it's clean. I'll tell you the exact steps to increase the java heap space in Eclipse but before that some background why I had to increase heap memory of Eclipse. I was getting "an internal error occurred during repository search . java heap space" while using Maven in Eclipse. Eclipse keep throwing java.lang.OutOfMemory:Java Heap Space while updating the index or searching for maven artifacts. Read more �

3 Maven Eclipse Tips for Java Developers

If you are using Maven inside Eclipse IDE via M2Eclipse plugin then following tips can help you a lot. 1) Setup Dependency as Java Project in Eclipse If your POM dependencies is another project in Eclipse then your project will automatically get updated whenever you build the dependent project. For example, let's say you have a project, ABC, which is dependent on two core modules e.g. framework.jar and persistence.jar , if you have checked out these project and has set up them as Maven Eclipse project, M2Eclipse can directly add them as dependency, instead of loading their JAR files from repository, be it local or remote. Read more �

Eclipse - How to add/remove external JAR into Java Project's Classpath

There are multiple ways you can add an external JAR into the classpath of a Java project in Eclipse, but all goes via adding them into build path. Many beginner's struggles to add JARs into classpath and we will try to address that problem in this tutorial. You will learn step by step tutorial to add an internal or third party JAR in your application's CLASSPATH in Eclipse Indigo. Since this feature has hardly changed in any Eclipse version, you can follow same steps in Eclipse Kepler, Indigo, and Juno version to add JARs into classpath. Since Eclipse is the most popular Java IDE and used by many companies, it's important for a Java developer to know Eclipse in and out. It will not only help to work better but also to create the better impression among your teammates. Read more �

How to make Eclipse use spaces instead of tabs in Java editor

I use Eclipse IDE extensively to write Java programs for testing and example purpose, but when I copy those program in any text editors e.g. VIM, Notepad, TextPad or Edit plus, the indentation goes weird. I see a lot of white spaces which makes the program wider than expected. This happens because when you copy Java program from Eclipse to a text editor, tabs are converted to spaces and different editor has the different settings of tabs. UNIX text editors prefer tab is 8 spaces, Windows text editors, and IDEs e.g. Eclipse treat tabs as 4 spaces. If you are like many Java programmer who is more comfortable with space than tabs because they give a true sense of spacing, you can always change the Java editor settings to use space instead of tabs in Eclipse . In this article, I am going to share how to make Eclipse uses spaces instead of tabs for Java editor , which you use while writing Java programs. Read more �

How to Increase Console Buffer Size in Eclipse IDE - Output and Debug Console

By default Eclipse IDE has limit on console output, also known as console buffer size. Which means, your Eclipse console will overfill quickly, if you are running a Java server program, which usually do lot of logging . Once this happen, you start losing logs. whenever new logs appear, equal number of oldest logs are truncated. Thankfully there is a way to increase output capacity in Eclipse IDE. I discovered this tip, on my search of Eclipse productivity tips e.g. Eclipse shortcuts and settings to organize import . You can increase console buffer size, which is specified in characters by using Eclipse preferences. Eclipse Indigo has default console buffer size as 250000 characters. Eclipse also provides a check box Limit Console Output to put enforce limit on console output , In order to increase console output either you can unchecked this box or you can increase console buffer size. I usually unchecked, Limit Console Output to avoid guessing a good number for console buffer size. ...

How to Fix Must Override a Superclass Method Error Eclipse IDE Java | @Override annotation With interface methods

One of annoying error while overriding Java method in Eclipse IDE is must override a superclass method error , This error is quite frequent when importing Java projects and still I haven't seen any permanent solution of it. Must override a super class method error comes in Eclipse, if you h ave Java Class that implements interface and overrides method from interface and uses @Override annotation . Unfortunately Eclipse defaults to Java 1.5, which only recognize @Override annotation for overriding method from super class and not from interface. This creates lots of confusion between Java programmers as not every one is aware of this subtle difference of using @Override annotation with class and interface methods and they start looking classpath and path suspiciously. @Override annotation for interface methods are only available from Java 1.6 and if you use @Override while overriding interface method tha n you will get must override a superclass method error. In this Java ...

How to fix Failed to load Main-Class manifest attribute from jar - Java Eclipse Netbeans Tutorial

If you have tried creating JAR file and running Java program form command line you may have encountered " Failed to load Main-Class manifest attribute from jar" , This error which haunts many Java programmer when they enter into command line arena and tries to create JAR file in command line or IDE like Netbeans and Eclipse . Major problem with "Failed to load Main-Class manifest attribute from jar" error is that, it�s unnecessary creates panic which it doesn't deserve, may be because process involves of creating and running JAR is not that common like running Java program using "java" command. Anyway in this Java tutorial we will see Why " Failed to load Main-Class manifest attribute from jar" comes and How to fix Failed to load Main-Class manifest attribute from jar error. Read more �

How to decompile class file in Java and Eclipse - Javap command example

Ability to decompile a Java class file is quite helpful for any Java developer who wants to look into the source of any open source or propriety library used in a project. Though I always prefer to attach source in Eclipse of most common libraries like JDK but it�s not always possible with increasing number of dependencies. Java decompiler (a program which can decompile Java class files to produce so urce files) is very helpful in such situation. By using Java decompiler you can easily check out the source of any .class file. Thanks to Eclipse IDE and increasing number of free plug-in available for Java developers, You can have powerful Java decompile in your armory. Earlier I used to used JadEclipse an Eclipse plugin which works well with JAD decompiler but knowing about JAD decompiler is not supporting Java 1.5 source, I was in hunt of another suitable and useful Eclipse plugin which can decompile . class file. My search ends with JD-Eclipse , this is another free Eclipse plug...

How to attach source in eclipse for Jars, debugging and code look-up � JDK Example

Attaching source of any Jar in Eclipse e.g. JDK or open source libraries like Spring framework is a good idea because it help during debugging and code development. As a Java programmer at least you should attach the source of JDK in Eclipse IDE to find out more about JDK classes. Though Eclipse IDE is pretty good on code assist, sometimes You want to know what's going inside a library or a JDK method, rather than just reading the documentation. Interview questions like How HashMap works in Java or How substring cause memory leak can only be answered if you are familiar with the source code of these classes. Once you attach source code of Java or Spring in Eclipse IDE , You can check code with just a single click. Some one may argue for Java decompiler like JAD which can create source from the .class file which is also a smart way to look code for open source library, but decompiled source file is not same as the original source file, as you lost comment and readability. As per...

How to escape String literal in Java using Eclipse IDE

Whenever you paste String in Eclipse which contains escape characters, to store in a String variable or just as String literal it will ask to manually escape special characters like single quotes, double quotes, forward slash etc. This problem is more prominent when you are pasting large chunk of data which contains escape characters like a whole HTML or XML file , which contains lots of single quotes e.g. �� and double quotes �� along with forward slash on closing tags. It�s very hard to manually escape all those characters and its pretty annoying as well. While writing JUnit test for XML documents, parsing and processing I prefer to have whole XML file as String in Unit test, which pointed me to look for that feature in Eclipse. As I said earlier in my post Top 30 Eclipse keyboard shortcuts , I always look to find new shortcut and settings in Eclipse which help to automate repetitive task. Thankfully Eclipse has one setting which automatically escapes text as soon as you paste it...

How to comment uncomment single line and block of code in Java - Eclipse Tips Tricks

Knowing Eclipse shortcut to comment and uncomment single line or block of code can save you lot of time while working in Eclipse. In fact I highly recommend every Java programmer to go through these top 30 Eclipse shortcut and 10 java debugging tips in Eclipse for improved productivity. If you are Java programmer, coding in Eclipse and want to comment and uncomment single line or block of code quickly you can either use ctrl + / to comment a single line and subsequently uncomment a commented line. If you want to comment a block of code or a complete method, you have two option you can either line comment (//) all those selected lines or block comment (/* */) those lines. For line comment multiple line, select multiple line and press ctrl + /, it will put // in front of every line. For block commenting in Eclipse, first select all the lines or code block you want to comment and then enter ctrl+shift+/ it will put /* on first line and */ on last line. Here is better illustrated...

Eclipse shortcut to System.out.println in Java program - Tips

Eclipse IDE provides quick shortcut keys to print System.out.println statement in Java but unfortunately not every Java programmers are familiar of that. Even programmers with 3 to 4 year of experience sometimes doesn't know this useful Eclipse shortcut to generate System.out.println messages. This Eclipse tips is to help those guys. Let me ask you one question, How many times you type System.out.println in your Java program? I guess multiple time, while doing programming , debugging and testing small stuff. System.out.println is the most preferred way to print something on console because it doesn�t required setup like configuring Log4J or java.util.Logger . Though I recommend using logging f or better information display in production code , nobody can undermine importance of System.out.println statement in Java. On the quest of learning Eclipse shortcut, some of them which I have discussed in my list of Top 30 Eclipse shortcut for Java programmers , I found a very use...

Eclipse shortcut to remove all unused imports in Java file

How to remove all unused imports in Eclipse Eclipse IDE gives warning "The import XXX is never used" whenever it detect unused import in Java source file and shows a yellow underline. Though unused import in Java file does not create any harm, it's unnecessary increase length and size of Java source file and if you have too many unused imports in your Java source file, those yellow underline and Eclipse warning affect readability and working. In our last post on Eclipse, we have seen dome Java debugging tips on Eclipse and in this post we will see Eclipse shortcut to remove all unused imports in Eclipse. There are many options to tackle this problem e.g. you can collapse import section of code in Eclipse or you can altogether remove all unused imports from Java file. Since Eclipse is favorite IDE of many Java programmer, who love to do things fast in shortcuts, I will also share Eclipse shortcut to remove unused imports from Java program in this article. This is one of...