Netbeans To Eclipse

Answer: Both Eclipse and NetBeans are the best IDEs used in order to develop Java applications. When developers are new to the development environment, a single view for all the types of applications, with a build-in plug-in for many functionalities and a stable framework of NetBeans IDE, is preferred. NetBeans 6.0p1 Eclipse Europa 3.3.1 Apache Tomcat 6.0.14 (configured in both NetBeans and Eclipse) (1) The Eclipse Way Of Things. Start Eclipse with a clean workspace containing a working Tomcat 6 runtime and server configuration. Use the 'Dynamic Web Project' provided by Eclipse WTP as a.

After building my environment for JavaServer Faces in the Eclipse IDE it was time to move onto NetBeans. It should be simple, I thought. I was very, very wrong.

NetBeans Step 1

Create a new project for Maven->Web Application. Fill in the usual details about the Maven project. When complete and the project appears immediately edit the pom.xml file and replace the section that starts with <dependencies> until the end with the contents from my pom.xml file from my previous blog posts.

At this point the project is ready for you to write your code. Or so I thought . . .

NetBeans revealed a flaw in my pom.xml file. In Eclipse the classpath of a Maven project includes the server’s library. This makes the TomEE lib folder’s jar files available to Eclipse. This is not the case with NetBeans. When it handles a Maven based project it expects all references to libraries to be declared in the pom.xml only. The ability to add libraries to a project through the IDE is removed.

When I began working on this project I was looking for a Maven dependency that referred to the TomEE libraries and not the Java EE 6 Oracle libraries. So the following dependency refers to the wrong version of the libraries.

Here is where I made one of many mistakes. I believed that the Maven TomEE plugin provided the correct libraries. So I placed in my pom.xml file:

This plugin has nothing to do with TomEE libraries. Instead its purpose is to allow a Maven pom.xml to be written that could, as listed on the TomEE maven Plugin page, do the following:

  • easy provisioning of a TomEE server
  • server start and stop
  • application deploy and undeploy

I did not notice the problem in Eclipse because it saw the TomEE libraries but when I tried to write a Facelet template file with NetBeans it reported that there was No Faces library in the classpath. So back to Google I went.

I found a blog entitled Developing Java EE 6 Applications With TomEE and NetBeans. It created a project by using an archetype. It showed how to add an archetype to Netbeans. It used the tomee-webapp-archetype.

The issue that I have with archetypes is that I must tell my students to delete or ignore parts of the project they create. When I used Maven in the classroom with Eclipse last term I used the maven-archetype-quickstart. Most of my students were confused by the generated files and chose to leave them in place unchanged. Most of my students’ projects displayed “Hello World!” in the console when run because they would not change the App.java file. Now I plan to start projects without an archetype.

What I was really interested in was the pom.xml file it created. It contained the dependency I was looking for that referenced the library used by TomEE:

It also included a plugin for the JPA. Great, now for some testing.

The sample code ran in NetBeans although it complained about the following tag in an xhtml file:

Now I was getting ticked off. The sample web app does work and the error is ignored. I know it works because I changed the color to green. What I don’t understand is how the authors of this archetype felt it was acceptable to leave an error in their code. A little research revealed that it should have been written as:

Import Netbeans To Eclipse

I now think I’m all set. As a further test I decide to try to add a new JSF Facelets template file. I could not create the file because NetBeans declared that there was No Facelets Libraries Found. But I thought org.apache.openejb.javaee-api would take care of this. A look into the Dependencies folder of the project revealed that there were no JSF libraries. So back to Google and the following was added:

How can we be told that JSF should be used in place of Servlets and JSPs only to discover that org.apache.openejb.javaee-api does not include MyFaces? I found my fix and so it’s time to move on.

The archetype sample code now ran flawlessly and I could add new Facelet template files.

I had successfully followed the Eclipse JSF Tools Tutorial – JSF 2.0 using may Maven based project setup. You can find this tutorial in the Eclipse help system. I uploaded it to my SVN repository and then brought it down to NetBeans. It ran successfully in NetBeans. Now I replaced most of the pom.xml file with the new components from the archetype sample and it continued to run flawlessly. I was on a roll. So I updated the repository from NetBeans and brought the project back into Eclipse. Eclipse was not happy.

Eclipse complained about a section of the JPA plugin in the pom.xml file.

I could comment these lines out but NetBeans was okay with them. The error message in Eclipse stated that “Plugin execution not covered by lifecycle configuration”. Back to Google and a solution was found. It seems Eclipse’s m2e plugin needs information about the lifecycle and this needed to be added to the pom.xml. You can read about this here.

So more elements were added to the pom.xml. I did discover that while you normally place plugins as a child of the <plugins> tag, the fix for Eclipse required the plugins to be children of <pluginManagement><plugins>.

Once Eclipse was happy I moved the project back through SVN to NetBeans and it did not mind the Eclipse specific elements in the pom.xml. The Eclipse tutorial project worked on both platforms and I could create the project from scratch on both platforms.

The last niggling problem was a warning whenever I ran the Eclipse tutorial. TomEE wrote out to the console:

WARNING: Attribute ‘for’ of label component with id j_id_a is not defined

I popped this into Google and came up with this answer.

The author of the Eclipse tutorial wrote:

This was the cause of the problem and the Stack Overflow author of the answer made some pretty strong remarks about whomever writes this in tutorials. I concurred. The fix is:

The tutorial also failed to use CDI correctly but that was a simple fix.

Eclipse

Here is the final version of the pom.xml file. Final, that is, until I discover some other component of the Java EE 6 Web profile that is missing from the org.apache.openejb.javaee-api.

Please let me know if you see any errors. The fix for the Eclipse lifecycle error has meaningless information in it because I could not find any meaningful values. What I saw all appeared quite arbitrary.

Import Netbeans Project To Eclipse

I think that I can now begin planning the curriculum for my courses.

Netbeans

This chapter describes how to download and install the e(fx)clipse tool, which enables you to create a new JavaFX FXML project using Eclipse IDE, start Scene Builder from within the IDE, and run Scene Builder sample applications.

The JavaFX integration with the Eclipse IDE is provided with the e(fx)clipse tool. It is assumed that you have already installed Scene Builder before continuing with the rest of this section. Go to the JavaFX Scene Builder Installation Guide for installation information.

Downloading and Installing e(fx)clipse

Go to http://www.eclipse.org/efxclipse/install.html for information about the available options to download and install the e(fx)clipse tool to use with your JavaFX Scene Builder installation.


Note:

The information in this chapter is based on the pre-configured distribution of Eclipse 4.2.2. SDK with e(fx)clipse 0.8.1


Netbeans To Eclipse Migration

Creating a New JavaFX FXML Project

To create a new JavaFX FXML project using Eclipse, you must first create a new JavaFX project and then add a new FXML document to that JavaFX project.

  1. From the Eclipse IDE Main menu, select File, choose New, and then Other, as shown in Figure 2-1.

    Figure 2-1 Create a New File


    Description of 'Figure 2-1 Create a New File'
  2. From the New dialog box, expand the JavaFX folder, and select the JavaFX Project wizard, as shown in Figure 2-2.

    Figure 2-2 Choose the JavaFX Project Wizard


    Description of 'Figure 2-2 Choose the JavaFX Project Wizard'
  3. Enter the project name, specify the JRE to use, and select the Project layout option. Click Finish to complete the project creation, as shown in Figure 2-3.

    Figure 2-3 Create a New Java Project


    Description of 'Figure 2-3 Create a New Java Project'
  4. Now create a new FXML document

    1. Right-click the Test folder in the Package Explorer.

    2. Select New and then Other.

    3. Expand the JavaFX folder in the New dialog box and then choose New FXML Document, as shown in Figure 2-4. Click Next

    Figure 2-4 Create a New FXML Document


    Description of 'Figure 2-4 Create a New FXML Document'
  5. In the FXML File dialog box, complete the creation of the new FXML document using the following steps:

    1. If not automatically set to test/src, specify the Source folder value by clicking Browse. Navigate to the src folder of the JavaFX project that you just created in the previous steps. Leave the Package field as is.

    2. In the Name field, enter Sample for the FXML file name, as shown in Figure 2-5.

    3. If not already set, specify the FXML document's root element by clicking Browse and selecting an item from the Find Preloader dialog box. The default value shown is AnchorPane.

    4. Leave Dynamic Root unselected. It is for advanced users who want to manage custom types.

    5. Restart from usb mac. Click Finish to close the dialog box.
      You can now complete the creation of your JavaFX FXML layout

    Figure 2-5 Finish Creating a New FXML File


    Description of 'Figure 2-5 Finish Creating a New FXML File'

Editing an FXML File Using Scene Builder

You can edit an FXML file using the Eclipse FXML editor or by opening the file using the JavaFX Scene Builder tool:

  1. In the IDE's Package Explorer tab, expand the Test and src folders.

  2. Right-click the Sample.fxml file and select Open with Scene Builder, as shown in Figure 2-6.
    A separate window for Scene Builder is opened and displays the Sample.fxml layout in the Content panel area. You may have to increase the size of the default AchorPane that appears in the Content panel. You may start to add controls.

    Figure 2-6 Open Sample.fxml File in Scene Builder


    Description of 'Figure 2-6 Open Sample.fxml File in Scene Builder'
  3. Use JavaFX Scene Builder User Guide to learn more about the available Scene Builder features and Getting Started with JavaFX Scene Builder to create a simple issue tracking application.

Where to Go From Here

Now that you are familiar with the integration between the Scene Builder tool and Eclipse IDE, look at JavaFX Scene Builder User Guide to learn more about the available Scene Builder features. Follow the steps described in Getting Started with JavaFX Scene Builder to create a simple issue tracking application.

Netbeans Eclipse Intellij

You can also try the sample applications provided with the Scene Builder release. The samples are Netbeans projects, so use the following information to learn how to use a sample using Eclipse IDE.

Using Scene Builder Samples From Eclipse IDE

Use the following information to use the Scene Builder samples. The HelloWorld application is used for illustratative purpose.

Netbeans Eclipse Theme

  1. Ensure that you have downloaded JavaFX Scene Builder Samples bundle from http://www.oracle.com/technetwork/java/javafx/downloads/index.html and extracted its contents.

  2. Create a new JavaFX Project by selecting File, and then choosing New and then Other.

  3. In the New wizard, expand the JavaFX folder and choose JavaFX Project. Click Next.

  4. In the New Java Project dialog box, enter HelloWorld for the Project Name, as shown in Figure 2-7, and click Next.

    Figure 2-7 Create a JavaFX Project for the HelloWorld Sample


    Description of 'Figure 2-7 Create a JavaFX Project for the HelloWorld Sample'
  5. In the Details section of the Java Settings dialog box, click Link additional source option. The Link Source dialog box is displayed.

  6. Click Browse and navigate to the location of the src folder for the Scene Builder HelloWorld sample application and click OK, as shown in Figure 2-8.


    Note:

    Ignore the error “The folder is already a source folder.” because the Folder name field is automatically filled in


    Figure 2-8 Open the HelloWorld Sample's src Folder


    Description of 'Figure 2-8 Open the HelloWorld Sample's src Folder'
  7. Change the default value in the Folder name text field to src_samples, or any folder name of your choice, and click Finish.

  8. Back in the New Java Project wizard, click Finish.

  9. Run the HelloWorld sample, as shown in Figure 2-9:

    1. In the Project Explorer window, expand the src_samples and helloworld folders for the HelloWorld project.

    2. Right-click the node for the Main.java source file.

    3. Choose Run As and then Java Application.

    Figure 2-9 Run Scene Builder HelloWorld Sample


    Description of 'Figure 2-9 Run Scene Builder HelloWorld Sample'

    The HelloWorld application is displayed, as shown in Figure 2-10.

    Figure 2-10 Hello World Sample Running


    Description of 'Figure 2-10 Hello World Sample Running'