javawaveblogs-20

Showing posts with label NetBeans. Show all posts
Showing posts with label NetBeans. Show all posts

Monday, November 26, 2012

Restful webservice using CFX and Spring




1. Create a new Maven Web project using Netbeans IDE. (Version used for this post is 7.3 beta3)



2. Run through the wizard to create the Maven Web Application. here i have given the name "CFXSpring" as the project name.


3. In the next screen of the wizard select the server of your choice.  Here i have selected Glassfish server which comes bundled with Netbeans.


4. Then click on finish, your project is ready to use. Here you can notice the following folder structure is created by Maven for you.


5. Now its time to add Spring MVC Framework to our application. So right click on the project node in project window and go to properties menu item. IDE will pop up a properties window for you. In that window go to "Frameworks" categories.  In the right panel of the window you will get a empty text area with an "Add" button to its right. Just Click on the Add button.Another framework window will pop up with the list of frameworks works available to choose from.  Select Spring Web MVC from that window.  See the screen shot below for clarity.



6. Now select the Spring Framework version you like to use with this application.  Here i have selected 2.5.6 to use with my application.  see the figure below.


7. Once the above step is done.  Spring frame work will be added to the project by the IDE, by including the needed dependencies to the POM.XML file. By the way adding the dependencies to the project dependencies folder. see the figure below.


8. Now you can see there is a change in the project folder structure also.  A new folder "WEB-INF" is added to the project. That folder will also contain "applicationContext.xml" which is nothing but the Spring Configuration file where we will be wiring our beans and bean dependencies through property or constrructer injection. also you can see "web.xml" which is nothing but the web applications deployment descriptor.

9. In "web.xml" you can see already "org.springframework.web.servlet.DispatcherServlet" is configured for you by the IDE. so no need for us to do any extra configuration with respect to spring.

10. Now its time to add CFX dependencies to POM.XML.  This we will do manually with out using any of the IDE's wizards.

11. Open the "pom.xml" file which will be located in the projectfiles folder of the project.

12. Go to "dependencies" tag. and add the following dependency to it.

<dependency>             <groupId>org.apache.cxf</groupId>             <artifactId>cxf-rt-frontend-jaxrs</artifactId>             <version>2.6.2</version>         </dependency>

Wednesday, November 14, 2012

Camel-Jetty Step by Step using Netbeans IDE


Camel-Jetty Step by Step using Netbeans IDE
1. Create a Maven Java project using Netbeans IDE (Version used - 7.3 beta2)
  1. Go to New project wizard and Create a new maven java project
  2. Here for our sample the project is named as “MyHTTP”
  1. Click on finish
  2. now the IDE will create a Java Maven project for you with the recommended folder structure like below.
  1. Just check the POM.XML found inside the “ProjectFiles” folder. which will have the dependencies and plugin’s added automatically by the IDE. POM created for “MyHTTP” is shown below.
  1. Now its time to add Camel dependencies to our POM.XML file. add the following dependencies to your pom.xml file inside the dependencies tag.
        

       






















       
  1. Once the dependencies are added just clean and build your project. so that maven will download the required jar files listed in the dependencies tag to your project from the central repository. and also will pack the required JAR files to your “\MyHTTP\target\” path with name “MyHTTP-1.0-SNAPSHOT.jar”.
  2. Now in your project you can see a main class created with the name “App.java”.
  3. its time to edit the java class App.java and add the following code to it.
package com.mm.myhttp;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
/**
 *
 * @author Muthu
 */
public class App {
    public static void main(String[] args) {
        DefaultCamelContext camelContext = new DefaultCamelContext();
        try {
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() throws Exception {
                    from("jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true")
                            .process(new Processor() {
                        @Override
                        public void process(Exchange exchng) throws Exception {
                            System.out.println("Inside process exchange");
                            String body = exchng.getIn().getBody(String.class);
                            // this is the way to access HttpServletRequest
                            HttpServletRequest req =
                                    exchng.getIn().getBody(HttpServletRequest.class);
                            // send a html response back to client
                            exchng
                                    .getOut()
                                    .setBody(""
                                    + "Simple Demo for Camel-Jetty component"
                                    + "
");
                        }
                    });
                }
            });
            camelContext.start();
        } catch (Exception ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

  1. the important part of the code is “from("jetty:http://0.0.0.0/myapp/myservice/?sessionSupport=true")” from route which starts jetty server and listens to the http url mentioned in the from route.
  2. then the route flows to the process where a html response is set to the body and returned to the client.
  3. To test this application, just run the Java Maven project with App.java as the main class.
  1. In the Output window you can see the http service running at port 80. and our component uses Jetty-7.5.4 to run the service.
  1. Now hit the url(http://localhost/myapp/myservice/) using your browser and you should be able to see the html response back from the service.

Thursday, March 20, 2008

Highlights of NetBeans 6.1

Highlights of NetBeans 6.1 include:

* JavaScript support such as semantic highlighting, code completion, type analysis, quick fixes, semantic checks and refactoring;

* Performance enhancements including faster startup and code completion;

* Spring framework support with features such as configuration file support, code completion and hyperlinks to speed navigation;

* New MySQL support in the Database Explorer to make it easier to create, launch and view MySQL databases;

* Significant enhancements to the Ruby/JRuby support, including a new Ruby platform manager, support for the latest version of Rails and new hints and quick fixes in the editor;

* Beta support for the ClearCase version control system - made available as a plugin from the Update Center.

download from --> http://dlc.sun.com.edgesuite.net/netbeans/6.1/beta/

Wednesday, September 19, 2007

NetBeans 6.0 Keyboard Shortcuts

Finding, Searching, and Replacing

Ctrl-F3 Search word at insert point
F3/Shift-F3 Find next/previous in file
Ctrl-F/H Find/Replace in file
Alt-F7 Find usages
Ctrl-Shift-P Find/replace in projects
Alt-Shift-U Find usages results
Alt-Shift-H Turn off search result

highlights

Alt-Left Next in jump list
Alt-Right Previous in jump list
Ctrl-R Rename
Ctrl-U, then U Convert selection to

uppercase
Ctrl-U, then L Convert selection to

lowercase
Ctrl-U, then S Toggle case of selection
Alt-Shift-V Paste formatted

Navigating through Source Code
Ctrl-O/Alt-Shift-O Go to type/file
Ctrl-Shift-T Go to JUnit test
Alt-O Go to source
Ctrl-B Go to declaration
Ctrl-G Go to line
Ctrl-Shift-M Toggle add/remove

bookmark
Ctrl-Shift-Next/previous bookmark
Period/Comma
Ctrl-Next/previous
Period/Comma usage/compile error
Ctrl-Shift-1/2/3 Select in

Projects/Files/Favorites
Ctrl-[ Move caret to matching
bracket
Ctrl-K/Ctrl-Shift KNext/previous word match

Coding in Java

Alt-Insert Generate code
Ctrl-Shift-I Fix all class imports
Alt-Shift-I Fix selected class's import
Alt-Shift-F Reformat selection
Alt-Shift-Shift tab to the left/right
Left/Right
Ctrl-/ Add/remove comment lines
Ctrl/Alt-F12 Inspect members/hierarchy
Ctrl-E Delete current line

Compiling, Testing, and Running

F9 Compile package/ file
F11 Build main project
Shift-F11 Clean & build main project
Ctrl-Q Set request parameters
Ctrl-Shift-U Create JUnit test
Ctrl-F6/Alt-F6 Run JUnit test on file/project
F6/Shift-F6 Run main project/file

Opening and Toggling betweenViews

Ctrl-Tab (Ctrl-`) Toggle between open

documents
Shift-Escape Maximize window (toggle)
Ctrl-F4/Ctrl-W Close currently selected

window
Ctrl-Shift-F4 Close all windows
Shift-F10 Open contextual menu
Alt-Shift-D Undock window

Debugging

Ctrl-F5 Start debugging main project
Ctrl-Shift-F5 Start debugging current file
Ctrl-Shift-F6 Start debugging test for file

(JUnit)
Shift-F5/F5 Stop/Continue debugging

session
F4 Run to cursor location in file
F7/F8 Step into/over
Ctrl-F7 Step out
Ctrl-Alt-Up Go to called method
Ctrl-Alt-Down Go to calling method
Ctrl-F9 Evaluate expression
Ctrl-F8 Toggle breakpoint
Ctrl-Shift-F8 New breakpoint
Ctrl-Shift-F7 New watch

When typing in the Source Editor, you can generate the
text in the right-column of the following list by typing
the abbreviation that is listed in the left-column and
then pressing Tab.

Java Editor Code Templates

En
Enumeration

Ex
Exception

Ob Object
Psf public static final

Psfb
public static final boolean

Psfi
public static final int

Psfs
public static final String

St
String

ab abstract
bo boolean

br break
ca catch (
cl class

cn continue
df default:

dowhile
do {
} while (condition);

eq
equals

ex extends
fa false

fi final
fl float

forc for (Iterator it = collection.iterator();
it.hasNext();) {
Object elem = (Object) it.next();
}
fore for (Object elem : iterable) {
}
fori for (int i = 0; i < arr.length; i++) {
}

fy
finally

ie
interface

ifelse if (condition){}else {
}
im implements
iof instanceof

ir
import

le
length

newo
Object name = new Object(args);

pe
protected

pr private
psf private static final
psfb private static final boolean
psfi private static final int
psfs private static final String
pst printStackTrace();

psvm
public static void main(String[] args){

}
pu public
re return
serr System.err.println ("|");
sout System.out.println ("|");
st static
sw switch (
sy synchronized
tds Thread.dumpStack();
th throws
trycatch try {}

catch (Exception e) {}
tw throw
twn throw new
wh while (
whilei while (it.hasNext()) {

Object elem = (Object) it.next();
}

Tuesday, September 18, 2007

NetBeans IDE 6.0

NetBeans IDE 6.0

The NetBeans IDE is a modular, standards-based, integrated development environment (IDE) written in the Java programming language. The NetBeans project consists of an open source IDE and an application platform, which can be used as a generic framework to build any kind of application.

for more information: http://www.netbeans.org/index.html

Working with Netbeans and ubuntu

1) Download JDK example: jdk1.6.0-beta2.bin into your home folder.

2) In terminal run : ./jdk1.6.0-beta2.bin
(make sure to chmod +x so that it can actually run)
result : you will get a folder in home such as jdk1.6.0/

3) In terminal run : sudo mv jdk1.6.0 /opt
result : you just moved jdk1.6.0 into /opt folder.
So now /opt/jdk1.6.0 is the location of the jdk.

4) In terminal run : sudo rm /usr/bin/java
result: remove any link that is in your system path for java.
So you can replace it with the jdk in /opt

5) In terminal run : sudo ln -s /opt/jdk1.6.0/jre/bin/java /usr/bin
result : made a link to your new jdk.
So that it is easy to be found by other programs

6) Dowload the latest snapshot of netbeans ex. nebeans 6.0

7) In terminal run : ./nebeans6.0-xxxx.bin
result : netbeans installer will find you jdk and will use it
for installation of the IDE.
At the end of installation you should have an icon on your desktop
for nebeans that uses java JDK that you placed in your /opt/jdk1.6.0 folder.

In netbeans folder structure you can find a file ~/netbeans6/etc/netbeans.conf
in there you can also point to a jdk of your choosing
like this : netbeans_jdkhome="/opt/jdk1.6.0"

diggthis