4 Getting Started with Developing Applications with Oracle JDeveloper

JDeveloper provides several tools and features for developing applications. You can use these features to effectively build, test, run, and deploy your application. This chapter provides an overview of the features for developing applications available in JDeveloper.

This chapter includes the following sections:

4.1 About Developing Applications with Oracle JDeveloper

The features for developing applications in JDeveloper include:

  • Different types of window for managing and working with different object types and resources associated with applications, projects, and files.

  • Several visual and code editing tools to facilitate the task of creating different types of source documents. The editors are integrated with other windows in the IDE, thus drag and drop operations and simultaneous, automatic updates among the various integrated tools are supported.

  • Tools to simplify the task of testing and analyzing source code, processes, and application modules or packages.

4.2 Creating Applications and Projects

The application is the highest level in the control structure. It is a view of all the objects you need while you are working. An application keeps track of all your projects while you develop programs. A project is a logical container for a set that defines a JDeveloper program or portion of a program. A project might contain files representing different tiers of a multi-tier application, for instance, or different subsystems of a complex application. These files can reside in any directory and still be contained within a single project.

All of the projects within an application are displayed below that application. If you filter a project using the working set, the project is not displayed under the application. Closing an application or project closes all open editors or viewers for files in that application or project and unloads the files from memory.

You can remove application and project control files from the IDE without deleting them from the disk. (This is not true for other types of file, which will be deleted from the disk at the time that they are removed from the IDE.) JDeveloper can recognize many different file types, displaying each in its appropriate viewer or editor when you double-click the file.

When adding a project to an application, you can choose to:

  • Create a new project, with specific objects and attributes you define.

  • Create a new empty project, which inherits default project properties.

  • Open an existing set of files from outside JDeveloper into a new project.

Projects control their files lists directly through the directory. Applications and packages also define where and how the files within a project are stored.

Note:

The same object (physical file) can appear in more than one project. This means that any actions carried out on the object in one project will show up in the other project (although some effects will become apparent only after the project is compiled). For packages, two or more projects should not share a package unless, first, they also share a source path used to generate the package and, secondly, the package is already compiled and will never be changed.

4.2.1 How to Create an Application

The application is the highest level in the control structure. It is a view of all the objects you need while you are working. An application keeps track of all your projects while you develop programs..

To create a new application with a specific feature scope:

  1. Open the New Gallery by choosing File > New.
  2. In the New Gallery, in the Categories tree, under General, select Applications.
  3. In the Items list, double-click the application type you want to create.
  4. In the Create Application dialog, enter application details like the name and directory. For help with the wizard, press F1.
  5. Click Next to open the Project Name page, where you can optionally provide details for your project.
  6. When you are done, click Finish.

4.2.2 How to Create a Custom Application

You can either create an application with a specific feature scope, or create a custom application that contains a single project that can be customized to include any features.

To create a new custom application:

  1. Open the New Gallery by choosing File > New.
  2. In the New Gallery, in the Categories tree, under General, select Applications.
  3. In the Items list, double-click Custom Application. The Create Custom Application wizard opens.
  4. In the Create Custom Application dialog, enter application details like the name and directory. For help with the wizard, press F1.
  5. Click Next to open the Project Name page, where you can optionally provide details for your project.
  6. When you are done, click Finish.

4.2.3 How to Create a Project

A project is a logical container for a set of files that defines a JDeveloper program or portion of a program. You can create a project that is preconfigured with a specific set of features.

To create a new project with a specific feature scope:

  1. In the Applications window, select the application within which the project will appear.
  2. Click the Application Menu icon, and select New Project to open the Projects page of the New Gallery.
  3. In the Items list, double-click the project type you want to create.
  4. Complete the Create Project wizard, and click Finish. For help on the wizard, press F1.

The new project appears in the Applications window. It inherits whatever default properties you have already set. To alter project properties for this project, either double-click the filename or right-click and choose Project Properties.

4.2.4 Creating a New Custom Project

To create a new custom project:

  1. In the Applications window, open the application that will contain the new project.
  2. Click the Application Menu icon, and select New Project to open the Projects page of the New Gallery.
  3. Under Items, select Custom Project.
  4. Click OK.

4.3 Managing Applications and Projects

You can effectively manage your applications and projects using the Applications window. The Applications window organizes your projects in terms of higher-level logical components that gives you a logical view of your application and the data it contains. It provides an infrastructure that the different extensions can plug into and use to organize their data and menus in a consistent, abstract manner. While the Applications window can contain individual files (such as Java source files), it is designed to consolidate complex data. Complex data types such as entity objects, UML diagrams, EJB, or web services appear in this Applications window as single nodes. The raw files that make up these abstract nodes appear in the Structure window.

Applications displayed in the Applications window contain one or more projects. Within the projects are the root folders for the paths in that project. You can choose to view project contents as a directory tree or file list, and packages by tree or list. And you can sort the nodes within packages and directories by type.

4.3.1 How to Open an Existing Application

You have the option of creating new applications from scratch or opening existing ones. As soon as you create or import the application, it is added to the Applications node in the Applications window.

To open an existing application and add it to the Applications window:

  1. In the Applications window, select Open Application from the dropdown list.
  2. Navigate to the application file and select it.

    Be sure that the file type field either specifies .jws files or allows all types to be displayed.

  3. Click Open.

    The application is added to the list of applications in the Applications window.

4.3.2 How to Open an Existing Project

As soon as you create or import a project, it is added to the selected application.

To open an existing project and add it to an application:

  1. In the Applications window, select the application to which the project will be added.
  2. From the main menu, choose File > Open.
  3. Navigate to the project file and select it.

    Be sure that the file type field either specifies .jpr files or allows all types to be displayed.

  4. Click Open.

    The project is added to the active application.

4.3.3 How to Quickly Add Items to a Project Using the New Menu

After you have created your project, you can directly create components related to the project's features using the project context menu.

To add items using the project context menu:

  1. Right-click the project you want to add items to and click New. Alternatively, you can click the New button in the toolbar after selecting your project in the Applications window.

    Note:

    The File > New menu displays the same items as the project context menu, and also contains additional application-level items.

  2. In the New menu, click the item you want to add. If you want to choose an item from the New Gallery, click From Gallery. The second section of the context menu contains a list of recently created items for the current project type. The third section of the New menu contains a list of most-recently created items.

4.3.4 How to Import Existing Source Files into JDeveloper

You can create new files of various types from scratch or open existing ones. When opening existing files, you can import them, along with their file structure, into an existing project or build a completely new project around them.

Alternatively, you can add source files to projects you already have.

4.3.4.1 How to Import Existing Files into a New JDeveloper Project

You can import existing files of any type into JDeveloper, creating a new project as you do so.

To open existing files and import them into a new JDeveloper project:

  1. In the Applications window, select or create the application to which the new project will be added.
  2. With the application selected choose File > New to open the New Gallery.
  3. In the Categories tree, expand General and select Projects.
  4. In the Items list, double-click Project from Existing Source.
  5. On the Location page of the Project from Existing Source wizard, enter a name for the new .jpr file or accept the default.

    For more information on this or subsequent wizard pages, press F1 or click Help from within the wizard.

    Alternatively, you can select File > Import, and choose either Java Source or Source into New Project.

  6. Accept the default directory path, enter a new path, or click Browse to navigate to one.
  7. Click Next.
  8. On the Specify Source page, in the Java Content area, click Add to open the Choose Directory dialog.
  9. In the dialog, navigate to the directory containing the files you wish to add. Click Select to close the dialog and display the directory in the wizard.
  10. When you have finished adding directories, you can apply file or directory filters. To apply filters, click Add next to the Included tab.
  11. When the import list is complete, optionally select Copy Files to Project directory to clone the selected files in your project rather than simply pointing to the original source.
  12. Define a default output directory and default package.
  13. Click Finish.

    The new project appears under the selected application node, populated with the imported files.

You can fine tune your project directories structure, for example to point to resource directories, in the Project Properties dialog.

4.3.4.2 How to Import a WAR File into a New JDeveloper Project

You can import a WAR file into JDeveloper, creating at the same time a new project to contain its extracted contents.

To open a WAR file and import it into a new JDeveloper project:

  1. In the Applications window, select or create the application to which the new project will be added.
  2. With the application selected choose File > New to open the New Gallery.
  3. In the Categories tree, expand General and select Projects.
  4. In the Items list, double-click Project from WAR File.
  5. Complete the Create Project from WAR File wizard.

    For information when using this wizard, press F1.

The wizard analyzes the WAR file and extracts its contents.

The new project appears under the selected application node, populated with the imported files.

4.3.4.3 How to Import an EAR File into a New JDeveloper Application

When you import an EAR file, JDeveloper will always create a new application and populate it with projects based on the EAR modules extracted. You cannot add the contents of an EAR file to an existing application or project.

You should not use this procedure to import an EAR file that you simply wish to deploy using JDeveloper. To do this, create a new application and project, then copy your EAR file into the project directory (or add its location to the project's content). The EAR file will then appear in the Applications window under the project's Application Sources node. From here, you can deploy the file by right-clicking it and choosing Deploy to.

To open an EAR file and import it into a new JDeveloper application:

  1. From the main menu, choose File > Import and double-click EAR File.

    The Import EAR File wizard is not sensitive to context, so you need not select anything specific in the Applications window first.

  2. Complete the Import EAR File wizard.

    On the Finish page, the contents of the final application are displayed.

  3. Click Finish to accept the listing and create the application.

    The new application appears in the Applications window, populated with projects based on the imported modules.

4.3.5 How to Import Files into a Project

You can create new files of various types from scratch or open existing ones. When opening existing files, you can import them, along with their file structure, into an existing project or build a completely new project around them.

You can also create new projects from existing source.

Note:

You can use the Import Existing Sources wizard to add.zip or.jar files to projects. You cannot use it to add.war or.ear files. A .war file requires the Import WAR File wizard to property extract its contents into the project. An EAR file requires the Import EAR File wizard, which extracts its contents into a new application.

To open an existing file and add it to a project using the Import Existing Sources wizard:

  1. In the Applications window, select the project to which the file will be added.
  2. From the main menu, choose File > Import.
  3. In the Import dialog, double-click Existing Sources.
  4. On the Add Source Files and Directories page of the Import Existing Sources wizard, click Add to open the Select Files or Directories dialog.

    For more information on this or subsequent wizard pages, press F1 or click Help from within the wizard.

  5. In the dialog, navigate to the directory containing the files you wish to add, or to the individual files themselves, and click Open to close the dialog and display the files in the wizard.

    You can return to this dialog as many times as you want, adding as many individual files or directories as you would like, by clicking Add again once you have returned to the wizard.

  6. When you have finished adding files or directories, and have returned to the wizard, you can refine your list by selecting and deselecting individual files or by applying filters. To apply filters, click File Filter or Directory Filter.
  7. When your import list is complete, optionally select Copy Files to Project directory to clone the selected files in your project rather than simply pointing to the original source. If you select this option, accept the default src directory, enter a new directory, or click Browse to navigate to one.
  8. Click Next.
  9. On the Finish page, review the listing of new project files. To accept this list, click Finish.

    The files are now added to the selected project.

4.3.6 Managing Folders and Java Packages in a Project

JDeveloper enables you to create custom folders or Java packages within your project to better organize your project files.

4.3.6.1 How to Create a Folder or Java Package

To create a folder or Java package:

  1. In the Applications window, select the project or folder within which you want to create the custom folder.
  2. On the File menu, select New.
  3. In the New Gallery, under Categories, select General.
  4. Under Items, select Folder to create a new folder. To create a Java Package, under Items, select Java Package.
  5. In the Create Folder or Create Java Package dialog, specify the name of the folder or Java package, and the directory you want to create it in.

4.3.6.2 How to Delete a Folder or Java Package

To delete a folder or Java package:

  1. Select the folder or Java package that you want to delete.
  2. On the File menu, select Delete.
  3. On the Confirm Delete Folder dialog, confirm the deletion of the folder or Java package. Click Show Folder Files to see the files contained in the folder or Java package.

4.3.7 How to Manage Working Sets

Working sets allow you to configure the Applications window to show you a subset of files from your project. This is particularly useful when working with large projects. Until you create a working set, there are no default working sets. After you create a working set, the option All Files lets you to get back to the default view.

4.3.7.1 How to Group Objects into a Working Set

You can run and debug a working set in just the same way as you run and debug a project. This allows you to work on just a subset of a large application, for example a Java EE application, without affecting the entire application or incurring a performance hit.

To group objects in the Applications window into a working set:

  1. In the Applications window, select the objects that you want to include in a new working set.
  2. In the Applications window, click the Working Sets icon and select New from Selection.

    This opens a Save As dialog. For more information at any time, press F1 or click Help from within the Save As dialog.

  3. Enter a name for the working set, then click OK.

4.3.7.2 How to Create a Working Set by Defining File and Directory Filters

You can define a working set by selecting from files or containers in the Applications window, or by providing include and exclude filter patterns through the Manage Working Sets dialog.

To create a working set by defining file and directory filters:

  1. In the Applications window, click the Working Sets icon and select Manage Working Sets.

    This opens the Working Sets dialog. Use the tree on the left to select the projects to include. In the right panel, select which files in the current project to include. For more information at any time, press F1 or click Help from within the Working Sets dialog.

  2. Click Save As to save the working set.

4.3.7.3 How to Create a Working Set From Search Results in the Log Window

You can create one or more sets of files for working on within a project. Based on the scope of your search, the action to save the search results as a working set is available.

To create a working set from the results of a search in the Log window:

  1. In the Log window, right-click and choose Save as Working Set from the context menu.
  2. In the Create Working Set dialog, enter a name for the working set.

4.3.7.4 How to Identify the Current Working Set

A tooltip in JDeveloper identifies the working set you are currently using:

  • In the Applications window, hover the mouse over the Working Sets icon. The name of the current working set is displayed as a tooltip. Alternatively, click the Working Sets icon to bring up a menu in which the active working set is checked.

4.3.7.5 How to Change the Active Working Set

To change the active working set:

  • In the Applications window, click the Working Sets icon and select the working set you want to open.

    Files not belonging to the working set are removed from the Applications window but no editors are closed.

4.3.7.6 How to Edit Files and Projects in a Working Set

To edit files and projects in a working set:

  1. In the Applications window, click the Working Sets icon and select Manage Working Sets.

    This opens the Working Sets dialog. For more information at any time, press F1 or click Help from within the Working Sets dialog.

  2. Select the working set that you want to change from the Working Set drop-down list.
  3. Make the changes as required.

4.3.7.7 How to Show All Files in the Applications window

To restore the view in the Applications window to show all files:

  • In the Applications window, click the Working Sets icon and select (All Files).

4.3.7.8 How to Run and Debug a Working Set

Before you begin, ensure that you are using the working set you want to run or debug. This should include the projects that represent the Java EE modules (Web applications, EJB modules) that you are working on and any dependencies.

Be aware that any projects that are explicit dependencies (in the Dependencies page of the Project Properties dialog) will be included even if they are excluded from the working set.

To run and debug a working set:

  1. Choose Tools > Preferences > Run, then select the option Always Run or Debug the current working set and its dependencies.

    Note:

    This option is not available for the Database Developer or Java Developer roles.

  2. Click OK.

    The next time you run or debug, JDeveloper will use the current working set. You can change to run and debug the entire application by choosing Tools > Preferences > Run, then selecting the option Always Run or Debug the entire application.

4.3.8 How to Browse Files in JDeveloper Without Adding Them to a Project

Sometimes, you may not want to add files directly to a project, but yet have them handy for browsing. You can bring files into the JDeveloper IDE, without adding them to a project.

To browse files in JDeveloper without adding them to a project:

  1. From the main menu, choose File > Open.

    As you are only going to view the files, it doesn't matter which node in the Applications window is currently selected.

  2. Navigate to the file or files to be opened. Be sure that the file type field either specifies the appropriate file type or allows all types to be displayed
  3. Select the file or files. You can select as many files, or directories, from the list as you would like.

    Archive files appear twice: once as a virtual directory and then again as a file. If you will be opening an archive file, select its appearance in the list as a directory.

  4. With your selection made, click Open.

4.3.9 How to View an Archive

You can easily inspect the contents of any archive, after first opening the archived file in JDeveloper. You can add the contents of an archive to an existing or new JDeveloper project.

To open an archive in JDeveloper and view its contents:

  1. From the main menu, choose File > Open.

    As you are only going to view the contents of the archive, it doesn't matter which node in the Applications window is currently selected.

  2. Navigate to the directory containing the archive. Archive files appear twice: once as a virtual directory and then again as a file.

    If you do not see the archive files, double-check that all file types are being displayed.

  3. Select the second appearance of the archive, the archive as a file, and click Open.

4.3.10 How to View an Image File in JDeveloper

You can easily view any.gif, .jpg, .jpeg, or .png file from within JDeveloper.

To open and view an image in JDeveloper:

  1. From the main menu, choose File > Open.

    As you are only going to view the image, it doesn't matter which node in the Applications window is currently selected.

  2. Navigate to the image or images to be opened. Be sure that the file type field either specifies all file types or the image types.

  3. Select the image.

  4. With your selection made, click Open.

    The image is displayed in the main working area of JDeveloper.

To view an image already imported into JDeveloper:

  1. In the Applications window, select the image file.
  2. Double-click the file, or right-click and choose Open.

4.3.11 Setting Default Project Properties

The project properties you specify in the Default Project Properties dialog apply to all subsequent projects you create across applications. Those you specify in the Project Properties dialog apply only to the current project. You can also set custom properties to override the properties set in a current project. This is particularly useful in a multiuser development environment. Custom properties are not stored in the .jpr file.

4.3.12 How to Set Default Project Properties

When you set project properties for an individual project, you override the default values for that project alone.

The procedures you follow for setting default project properties are identical to those for setting properties for individual projects — with the exception that, as you are in default properties, you do not need to first select an individual project. Note that some project properties cannot be set from the Default Project Properties dialog.

To view or change the default settings for a project:

  1. From the main menu, choose Application > Default Project Properties.
  2. In the Default Project Properties dialog, select the appropriate category.
  3. View or set the various properties as desired.
  4. When finished, click OK.

4.3.13 How to Set Properties for Individual Projects

You can set the project properties for all subsequent projects, or fine-tune the properties for any individual project.

Additional project properties are also available, based upon specific tasks such as compiling, or debugging.

4.3.13.1 How to View or Change the Current Output Path for an Individual Project

When you set project properties for an individual project, you override the default values for that project alone.

To view or change the current output path for an individual project:

  1. In the Applications window, select the appropriate project.
  2. From the main menu, choose Application > Project Properties, or right-click and choose Project Properties.

    The Project Properties dialog opens with the input paths displayed on the last page that you viewed.

  3. On the Project Source Paths page, change the output directory as desired by typing in the new values or by clicking Browse.
  4. When finished, click OK.

4.3.13.2 How to Set the Target Java SE for a Project

Setting the target Java SE specifies which Java SE JDeveloper will use when compiling and running your project.

To view or change the current Java SE for an individual project:

  1. In the Applications window, select the appropriate project.
  2. From the main menu, choose Application > Project Properties, or right-click and choose Project Properties.

    The Project Properties dialog opens with the common input paths displayed or on the last page that you viewed.

  3. On the Libraries and Classpath page the Java SE Version used for the project is displayed. Click Change to define a new Java SE.
  4. When finished, click OK.

4.3.13.3 How to Manage Project Dependencies

Complex applications generally comprise multiple projects, which may be related though dependencies. That is, project A must depend on project B when project A uses classes or resources from project B. When this dependency is set, compiling project A will automatically compile project B.

Deployment profile dependencies are created and edited in the Project Properties dialog available from the Tools menu.

To manage the project dependencies for an individual project:

  1. In the Applications window, select the appropriate project.
  2. From the main menu, choose Application > Project Properties, or right-click and choose Project Properties.
  3. Select the Dependencies node.
  4. On the Dependencies page, view the current dependency hierarchy for the project.
  5. Select or deselect projects as desired.
  6. To change the current dependency ordering, click Ordering.
  7. When finished, click OK.

4.3.13.4 How to Associate Features with a Project Via a Template

When you create a project from a template, the project will inherit all the features available in the template. More features are added dynamically to the project as you create content in your project. Go to Project Properties > Features > Reconcile to filter the list of features that are actually in use in the project.

To associate features with a project via its project template:

Note:

This procedure is applicable only for new projects created from a template.

  1. From the main menu, choose Application > Manage Templates.
  2. In the Manage Application Templates dialog, click the project template for which the features are to be associated.

    Application templates are listed as first-level nodes under Application Templates. Project templates appear below their application template.

  3. In the panel to the right, select the appropriate features from the Available Project Templates list and use the shuttle buttons to transfer them to the Selected Project Templates list.
  4. When finished, click OK.

4.3.13.5 How to Associate Features with an Individual Project

When features are associated with a project, JDeveloper's design time filters the choices you see based upon what you are most likely to need for a project of this type.

To associate features with an individual project:

  1. In the Applications window, select the appropriate project.
  2. From the main menu, choose Application > Project Properties, or right-click and choose Project Properties.
  3. Select the Features node.
  4. On the Features page, click the Add Features button.
  5. In the Add Features dialog, select the features to be associated with the project in the Project Features list.
  6. Click the shuttle button to transfer your selection to the Selected list.
  7. Click OK.

4.3.13.6 How to Set Javadoc Properties for a Project

Every project you create carries the JDeveloper project defaults or those you have supplied yourself for all projects. You can also replace these defaults on a project-by-project basis. Setting these properties is the same in either case: only the location, and application, of the information differs.

To set Javadoc properties for an individual project:

  1. In the Applications window, select the project.
  2. From the main menu, choose Application > Project Properties, or right-click and choose Project Properties.
  3. Under Profiles, select the active profile node.
  4. Under the active profile node, select the Javadoc node.
  5. When finished, click OK to close the Project Properties dialog.

4.3.14 How to Manage Libraries

There are two categories of library: internal and external. Internal library definitions are persisted within the project file itself (that is, within the .jpr file) and are thus always available to anyone opening that project. However, internal library definitions are not sharable among any other projects. You can add an internal library to a project by going to the Libraries and Classpath page of the Project Properties dialog, and clicking Add JAR/Directory.

External library definitions are persisted within their own stand-alone library definition file (that is, the .library file). As such, external libraries can be checked into source control, referenced by any number of projects, and can be shared among all users in a team environment in the same way that java source files are. Since external libraries have their own unique URL, adding an external library to a project adds that URL to the project.

4.3.14.1 How to Add Application-level Libraries and Classpaths

Libraries are often required across many or all projects within an application. All libraries that you add at the application level are implicitly added to the libraries and classpaths of all projects within the application and are readily available at design and compile time.

Any library or classpath added at the application level for use during deployment are included in the packaged EAR lib directory and is selected for deployment by default.

To add an application-level library:

  1. Right-click the application in the application window.
  2. Select Application Properties from the contextual menu.
  3. Select the Libraries and Classpath node.
  4. Click Add Library.
  5. Locate the required library in the selection tree and click OK.

Libraries added at the application-level do not appear in the in the project properties Libraries and Classpath page by default. Check Show Application Libraries in the project properties Libraries and Classpath page to see all application-level libraries (this option is disabled if no application-level libraries exist). You can move the list of application-level libraries as a block to the top or bottom of the classpath entries using the Move to Top or Move to Bottom arrows. You cannot move an individual application-level library.

You can create and add an application-level library in the same way as described in How to Create a New Library and Add it to a New Project.

4.3.14.2 How to View the Current Libraries in a Project

When you include libraries in a project, the source paths defined for those libraries automatically become part of the project's classpath.

To view the current libraries for an individual project:

  1. In the Applications window, select the appropriate project.
  2. From the context menu, choose Project Properties.
  3. Select the Libraries and Classpath node.

    The libraries currently included in the project are shown in the Classpath Entries list.

4.3.14.3 How to Add an Existing Library to a Project

You can add an existing library to a project.

To add an existing library to a project:

  1. With the project selected in the Applications window, open the Project Properties dialog.
  2. Select the Libraries and Classpath node
  3. On the Libraries and Classpath page, click Add Library.
  4. Locate the required library in the selection tree and click OK.

4.3.14.4 How to Create a New Library and Add it to a New Project

You can create a new library and add it to a new project.

To create a new library and add it to a project:

  1. With the project selected in the Applications window, open the Project Properties dialog.
  2. Select the Libraries and Classpath node.
  3. On the Libraries and Classpath page, click Add Library.
  4. On the Add Library dialog, click New.
  5. In the Create Library dialog, enter a name for the new library and select its location.
  6. For each path type, click Add Entry or Add URL as appropriate. To remove a path, or correct an addition, click Remove. To rearrange the order of entries, use the reordering buttons to the right of the display area.
  7. Once you have clicked either Add Entry or Add URL, in the resulting selection dialog enter the filename or browse through the list to select one. When your entry is complete, click Select.
  8. In the Create Library dialog, click OK.
  9. On the Libraries and Classpath page, if finished click OK.

4.3.14.5 How to Edit an Existing Library in a Project

You can edit an existing library in a project.

To edit an existing library in a project:

  1. With the project selected in the Applications window, open the Project Properties dialog.
  2. Select the Libraries and Classpath node.
  3. On the Libraries and Classpath page, select the library to be altered from the Classpath Entries list.
  4. Click Edit. (This button remains the View button if the library is not editable.)
  5. In the Edit Library Definition dialog, the appropriate library's name should appear in the first field. Make any desired changes to the library name by typing directly into the field.
  6. For each Edit Path dialog, click Add Entry or Add URL as appropriate. To remove a path, or correct an addition, click Remove. To rearrange the order of entries, use the reordering buttons to the right of the display area.
  7. Once you have clicked either Add Entry or Add URL, in the resulting selection dialog enter the directory name or browse through the list to select one. When your entry is complete, click Select.
  8. In the Edit Library dialog, click OK.
  9. On the Libraries and Classpath page, if finished click OK.

4.3.14.6 How to Remove Libraries from a Project

When you remove libraries from a project, the source paths defined for those libraries no longer form part of the project's classpath.

To remove a library from a project:

  1. In the Applications window, select the appropriate project.
  2. From the main menu, choose Application > Project Properties, or right-click and choose Project Properties.
  3. Select the Libraries and Classpath node.
  4. On the Libraries page, select the desired library or libraries from the Libraries list and click Remove.
  5. If finished, click OK.

4.3.14.7 How to Import Libraries or Java SEs Outside the Project Scope

You can work with libraries completely outside the JDeveloper project scope, setting them up to be either available to you for use in any of your projects or available to a group of users across an installation.

To work with libraries or Java SEs outside of the scope of a project:

  1. From the main menu, choose Tools > Manage Libraries.
  2. In the Manage Libraries dialog, select either the Libraries or the Java SE Definitions tab.
  3. Select the User node to import libraries for your own use. Select the Extension node to import libraries for use across a group.
  4. Click Load Dir.
  5. In the Load Directories dialog, navigate to the library that you wish to import and click Select.
  6. When finished, click OK.

4.3.14.8 How to Create Libraries or Java SEs Outside the Project Scope

You can work with libraries completely outside the JDeveloper project scope, setting them up to be either available to you for use in any of your projects or available to a group of users across an installation.

To create libraries or Java SEs outside the scope of a project:

  1. From the main menu, choose Tools > Manage Libraries.
  2. In the Manage Libraries dialog, select either the Libraries or the Java SE Definitions tab.
  3. Select the User node to create libraries for your own use. Select the Extension node to create libraries for use across a group.
  4. Click New.
  5. In the Create Library dialog or the Create Java SE dialog, complete the details for the new library or Java SE.
  6. When finished, click OK.

4.3.14.9 How to Edit Libraries or Java SEs Outside the Project Scope

You can work with libraries completely outside the JDeveloper project structure, setting them up to be either available to you for use in any of your projects or available to a group of users across an installation.

To edit libraries or Java SEs outside the scope of a project:

  1. From the main menu, choose Tools > Manage Libraries.
  2. In the Manage Libraries dialog, select either the Libraries or the Java SE Definitions tab.
  3. In the tab list, select the library to be edited. Its attributes are displayed in the fields to the right.
  4. To change the Java SE executable, click Browse.
  5. To change the class, source, or doc paths, select the path that you want to change then click one of the buttons beneath the paths panel: Add Entry, Add URL, or Remove.

    You can also reorder the entries, by clicking the up and down buttons in the right margin.

  6. When finished, click OK.

4.3.14.10 How to Delete Libraries or Java SEs Outside the Project Scope

You can work with libraries completely outside the JDeveloper project scope, setting them up to be either available to you for use in any of your projects or available to a group of users across an installation.

To delete libraries or Java SEs outside the scope of a project:

  1. From the main menu, choose Tools > Manage Libraries.
  2. In the Manage Libraries dialog, select either the Libraries or the Java SE Definitions tab.
  3. In the tab list, select the library to be deleted. You can delete only those libraries you have created.
  4. Click Remove and respond to the confirmation dialog.

    The library is deleted immediately.

  5. To close the Manage Libraries dialog, click OK.

4.3.15 How to Manage Application and Project Templates

Application and project templates provide you with a quick way to create the project structure for standard applications with the appropriate combination of features already specified. The new application created from template appears in the Applications window already partitioned into tiered projects, with the associated features set.

The application template you select determines the initial project structure, the named project folders within the application. The project templates define the associated features. You can then filter the work you do in JDeveloper such that the choices available are focused on the features you are working with.

4.3.15.1 How to Define a New Application Template

An application template organizes one or more project templates which specify the project types expected in the application. Using such templates enables you to standardize the way you develop an application.

To define a new application template:

  1. Begin the process of creating a new application.
  2. In the Create Application dialog, click Manage Templates. Alternately, if you are not in this dialog, choose Application > Manage Templates.

    For more information at any time, press F1 or click Help from within the appropriate dialog.

  3. In the Manage Templates dialog, select the Application Templates node and click to open the Create Application Template dialog
  4. Enter a name for the new template and click OK.

    The new template appears in the template list of the Manage Templates dialog. All application templates are listed as first-level nodes under Application Templates.

  5. Complete defining the Application Template. For more information at any time, press F1 or click Help from within the Manage Templates dialog.

The application template appears in the New Gallery in the Applications category of the Business Tier.

4.3.15.2 How to Define a New Project Template

Project templates specify the various types of projects expected in a given application. Project templates are contained within application templates.

To define a new project template:

  1. Define a new application template.

    Alternately, if the template has already been defined, choose Application > Manage Templates.

  2. In the Manage Templates dialog, select the Project Templates node and click the Add icon to open the Create Project Template dialog.
  3. Enter a name for the new template and click OK.

    The new template appears in the template list of the Manage Templates dialog. All project templates are listed as first-level nodes under Project Templates.

  4. Complete defining the Project Template. For more information at any time, press F1 or click Help from within the Manage Templates dialog.

The project template appears in the New Gallery in the Projects category.

4.3.15.3 How to Share Application and Project Templates

You can create an application or project template in a shared location. Other users can read templates from the shared location and use the same templates for their application and projects.

To create a shared template:

  1. Choose Application > Manage Templates.
  2. In the Manage Templates dialog, select either the Application Templates or Project Templates node and click the Add a shared location icon.
  3. In the Add Templates Directory dialog, enter or browse to the location where you want the shared template to be stored.

The shared templates folder is listed under both the Application Templates and Project Templates node.

4.3.15.4 How to Edit an Existing Application or Project Template

You can edit existing user-defined application or project templates.

To edit an existing application or project template:

  1. From the main menu, choose Application > Manage Templates.
  2. In the Manage Templates dialog, select the template you want to edit.

    For more information at any time, press F1 or click Help from within the Manage Templates dialog.

  3. In the panel to the right, edit the attributes of the templates as desired.
  4. When finished, click OK.

4.3.15.5 How to Delete an Existing Application or Project Template

You can delete existing user-defined application or project templates.

To delete an existing application or project template:

  1. From the main menu, choose Application > Manage Templates.
  2. In the Manage Templates dialog, select the name of the template to be deleted.

    Application templates are listed as first-level nodes under Application Templates. Project templates are listed as first-level nodes under Project Templates.

    For more information at any time, press F1 or click Help from within the Manage Templates dialog.

  3. Click Delete.
  4. Click OK.

4.3.16 How to Manage File Templates

JDeveloper allows you to create file templates with pre-populated custom data and use them in your application. For example, you can create a Java class file template that contains basic header tagging, then when you need to add a Java class file in your application, you would start from your created template and that would save you from manually entering basic header data in every single Java class.

You can create templates for all the files types supported in JDeveloper such as Java, html, xml, etc.

There are two workflows for managing file templates: you can edit an existing template and you can create a new template. The workflows are described below.

To edit an existing template:

  1. Open your application in JDeveloper and navigate to Tools > Preferences > File Templates. JDeveloper provides an out-of-the-box Java class template.

  2. In the File Templates dialog go to the folder directory and navigate to General > Java.

  3. Click the provided template, Copyrighted Class. The template details and template content appears on the right pane.

    By default the built-in templates are not editable. If you start typing to modify the content of the template, you will be prompted to confirm that you want to modify the built-in template.

  4. Modify the template by adding a simple line of text above the @author line. For example,

    * Enter a description of this class.

    Note:

    JDeveloper provides out of the box variables to use in your templates. To understand those variables see, Available File Template Variables.

    You can use the Reset button on the top-right corner of the page to revert the template to its original text.

  5. Click OK to close the Preferences dialog.

  6. To use the template in your application, navigate to New > Gallery > General > Java and you will see on the right pane the Copyrighted Class template.

  7. Select the template and click OK.

    After defining the File Name, the new class is created using the text in the created template.

    Figure 4-1 Edit File Template

    This image is described in the surrounding text

    Line 28 shows the text that you added to the template on step 4.

To create a new template:

  1. Open your application in JDeveloper and navigate to Tools > Preferences > File Templates. JDeveloper provides an out-of-the-box Java class template.
  2. In the File Templates dialog navigate to the folder directory to General > Java.
  3. Click the provided template, Copyrighted Class. The template details and template content appears on the right pane. You will use this Java class template as a starting point for developing your new template.
  4. Click the Copy icon at the top right corner of the page.

    The Copy Template - Copyright Class dialog appears

    Figure 4-2 New File Template Dialog

    This image is described in the surrounding text
  5. JDeveloper populates the new template details, but the following fields can be modified:
    • Id—the id for this new template

    • Name—he name of the template as it will appear in the Gallery

    • File Name—the path and file name for this new template. You can modify any part of the file name, including location.

    • Category—the main category in the Gallery

    • Folder—the id for this new template

    • Description—the description of the file as it will appear in the Gallery

    • Messages—the place where any errors in the template definition are described, for example if you enter a duplicate template id. The messages area is empty when there are no errors. This field cannot be modified.

    In this example we will only rename the new template as My Copyrighted Java Class

  6. Click OK.

    A copy of the existing template is created.

  7. Delete all the existing template text and enter the following:
    /**
    * Enter a description of this class. 
     */
    
    public class ${name} {
    
      public ${name}(){
        super();
      }
    }
    

    Note:

    JDeveloper provides out of the box variables to use in your templates. To understand those variables see, Available File Template Variables.

  8. Click OK. The new template is created.
  9. To use the new template in your application, navigate to New > Gallery > General > Java and you will see on the right pane the created My Copyrighted Java Class template.

    Figure 4-3 New File Template - Select From Gallery

    This image is described in the surrounding text
  10. Select the new template and click OK. After defining the file name, the new class is created using the text in the created template.

    Figure 4-4 New File Template - Editor View

    This image is described in the surrounding text

4.3.16.1 Available File Template Variables

JDeveloper provides the following File Template Variables out-of-the-box:

  • name—the name, without extension, of the file that will be created

  • nameAndExt—the name, without extension, of the file that will be created

  • date—the current time, in this format: Feb 16, 2008 from DateFormat.getDateInstance() during template processing

  • package—the current package is specified

  • time—the current time, in this format: 7:37:58 PM from DateFormat.getTimeInstance() during template processing.

  • dateTime—the current date, from DateFormat.getDateTimeInstance() during template processing

  • user—the current user name, as returned from System.getProperty("user.name")

4.3.17 How to Save an Application or Project

You can save an application or project in several ways.

To save all the components across applications, including all projects:

  • From the main menu, choose File > Save All or click the Save All icon.

Alternately, you can save components individually by using File > Save.

It is important to note that saving the application or project container (.jws, .jpr) file alone does not save the individual files governed by that application or project. Nor does saving individual contained files save the container node.

Each node is an independent entity and must be saved as such. Using Save All takes care of changes to these container files, as well as all content files.

Using Save or Save As on a selected application or project node saves or duplicates the .jws or .jpr file only: it does not save or duplicate the files contained within the node.

Note too that if you do a Save As on an application or a project container file, that container is replaced, but the files contained are not altered. If you do a Save As on an individual file, that file is duplicated. However, if you want to rename a file, you should use File > Rename.

4.3.18 How to Save an Individual Component or File

Saving the application or project container (.jws, .jpr) file alone does not save the individual files governed by that application or project. Nor does saving individual contained files save the container node.

Each node is an independent entity and must be saved as such. Using Save All takes care of changes to these container files, as well as all content files.

Using Save or Save As on a selected application or project node saves or duplicates the .jws or .jpr file only: it does not save or duplicate the files contained within the node.

You can rename an individual file or component using File > Rename.

Note that if you do a Save As on an application or a project container file, that container is replaced, but the files contained are not altered. If you do a Save As on an individual file, that file is duplicated.

To save an individual component or file:

  1. In the Applications window, select the component or file to be saved.
  2. From the main menu, choose File > Save or click the Save icon in the toolbar.

    The file is immediately saved, its italicized name changing to Roman font.

4.3.19 How to Rename an Application, Project, or Individual Component

You can rename application control files, project control files, and individual files. The correct way of renaming Java classes is to use refactoring.

To rename an application or project container, or an individual source file:

  1. In the Applications window, select the node to be saved.
  2. From the main menu, choose File > Rename.

    For simple files, the Rename dialog opens. For Java files, the Rename File dialog opens.

  3. If the Rename File dialog has opened, choose between renaming only the selected file, or renaming the file, the class defined by it, and all references to the class

    If you choose to rename the class and update references, the Rename Object_Name dialog opens.

  4. If the Rename Object_Name dialog opens, change the name and choose options as required, then click OK.
  5. If the Rename dialog opens, change the name as required and click Save.

    The node now appears in the Applications window with the new name.

Alternately, you can use File > Save As. Note that Rename always replaces the target file. Save As replaces application or project container (.jws, .jpr) files, but duplicates source files.

When you are saving files, remember that saving a container file alone does not save the contents of the entire application or project. For that, you need to use Save All.

4.3.20 How to Relocate an Application, Project, or Project Contents

The Applications window presents a visual representation of the logical structure of applications and projects. It is not a file directory. It does not necessarily represent the physical location of those files.

To change the physical location of individual files, you can work in JDeveloper. To change the physical location of a group of files, it is easier to work through your operating system's file manager.

To change the association of files with projects or projects with applications, you would work in the Applications window, adding or removing as appropriate.

Note:

The best practice for relocating Java classes is to use the options available on the Refactor menu.

To change the physical location of an individual file, whether within the project or a container (.jws or .jpr) file:

  1. In the Applications window, select the file to be moved.

  2. From the main menu, choose File > Rename. If you have chosen a Java file, the Rename File dialog will open. You will be able to relocate the file only if you choose the option Rename the file only, do not update references in this dialog.

  3. In the Rename dialog, navigate to the new location for the file and change the file's name if you wish.

  4. Click Save.

    The file is now physically stored in the new directory. Its logical representation does not change in the Applications window unless you explicitly alter it.

To change the physical location of an entire application or directory:

  1. In your operating system's file manager, navigate to the directory in which the files currently reside. Files stored in the JDeveloper default directory reside in the mywork folder.

  2. Select the entire directory (application, project, or files within a project) to be moved and move it to the new location.

    The files have now been moved, but JDeveloper no longer knows where they are.

  3. When you return to JDeveloper, in the Applications window, and choose Open Application from the drop-down list.

  4. Navigate to the new physical location of the application or project and click Open.

To change the physical location of a group of files from one project to another:

  1. In your operating system's file manager, navigate to the directory in which the files currently reside.
  2. Select the files to be moved and move them to the new location.
  3. When you return to JDeveloper, select the project in the Applications window, and choose Project Properties from the context menu.
  4. In the Project Source Paths page of the Project Properties dialog, use the Add button and navigate to the location of the files you want to add.

    The files are now physically located where you placed them in step 2, and logically associated in the Applications window wherever you targeted them in step 4.

4.3.21 How to Close an Application, Project, or Other File

When you close an application, project, or file in the Applications window, that application or project is unloaded from memory. When an application or project is closed, it appears in its unexpanded form in the Applications window.

In addition, you can remove applications, projects, or files from the Applications window, which removes them only from the list, or you can delete them permanently, wherever they reside, from within JDeveloper.

To close an application or project:

  1. In the Applications window, select the application or project to be closed.
  2. From the main menu, choose File > Close.

    If any files within that application or project were changed and not saved, you are prompted to save them.

    The application or project now collapses and appears in the Applications window with the plus sign indicating that is ready for expansion.

You can close a file opened in a viewer or an editor by clicking on the close box of the corresponding document tab above the editor window.

4.3.22 How to Remove a File from a Project

You can remove files from a project, which removes them only from the Applications window list, or you can delete them permanently, wherever they reside, from within JDeveloper.

To remove a file from a project:

  1. In the Applications window, select the file or files you wish removed.
  2. Select File > Delete.
  3. The Confirm Delete Dialog is displayed. If you are certain that you want to delete the file, click Yes.

4.3.23 How to Remove a Project from an Application

You can remove projects from the application by deleting the project control file (.jpr) from within JDeveloper.

To remove a project from an application:

  1. In the Applications window, select the project you wish to remove.
  2. Select File > Delete Project.
  3. The Confirm Delete Project Dialog is displayed. To confirm the deletion, click Yes.

4.3.24 How to Remove an Application

You can close an application and remove it from the Applications window. If you want to delete the application

To remove an application from the IDE:

  1. In the Applications window, click the Application Menu.
  2. Select Close Application.
  3. The Confirm Close Application Dialog is displayed. Select an option based on your preference.
  4. Select Application > Delete to delete the application and its contents.