Generating Java Files

You generate Java source files from the classes and interfaces of a model. A separate file, with the file extension .java, is generated for each class or interface that you select from the model, along with a generation log file. You can only generate Java files from one model at a time.

The following PowerDesigner variables are used in the generation of Java source files:

Variable

Description

Default

J2EEVERIF

Batch program for verifying if the deployment jar for an EJB is correct

verifier.bat

JAR

Command for archiving java files

jar.exe

JAVA

Command for running JAVA programs

java.exe

JAVAC

Command for compiling JAVA source files

javac.exe

JAVADOC

Command for defining JAVA doc comments

javadoc.exe

To review or edit these variables, select Tools > General Options and click the Variables category. For example, you could add the JAVACLASSPATH variable in this table in order to override your system's CLASSPATH environment variable.

  1. Select Language > Generate Java Code to open the Generation dialog.
  2. Enter a directory in which to generate the files, and specify whether you want to perform a model check (see Checking an OOM).
  3. [optional] Select any additional targets to generate for. These targets are defined by any extensions that may be attached to your model (see Working with Generation Targets).
  4. [optional] Click the Selection tab and specify the objects that you want to generate from. By default, all objects are generated.
  5. [optional] Click the Options tab and set any appropriate generation options:

    Option

    Description

    Java: Sort class members primarily by

    Sorts attributes and operations by:
    • Visibility- [default] Public attributes and operations are generated before private ones
    • Type - Attributes and operations are sorted by type whatever their visibility

    Java: Class members type sort

    Sorts attributes and operations in the order:
    • Attributes – Operations - Attributes are generated before the operations
    • Operations – Attributes - Operations are generated before the attributes

    Java: Class members visibility sort

    Sorts attributes and operations in the order:
    • Public – Private - Public attributes and operations are generated before private ones
    • Private – Public - Private attributes and operations are generated before public attributes and operations
    • None - Attributes and operations order remains unchanged

    Java: Generate package imports

    When a class is used by another class, it is referenced by a class import:
    import package1.package2.class.
    This options allows you to declare import of the whole package, and saves time whenever many classes of the same package are referenced:
    import package1.package2.*;

    Java: Generate object ids as JavaDoc tags

    Generates information used for reverse engineering like object identifiers (@pdoid) that are generated as documentation tags. If you do not want these tags to be generated, you have to set this option to False

    Java: Generate default accessors for navigable associations

    Generates the getter and setter methods for navigable associations

    Ant: Generate Ant build.xml file

    Generates the build.xml file. You can use this file if you have installed Ant

    EJB: Generate CMP field accessors in component interfaces

    Generates CMP fields getter and setter operations to EJB interfaces

    EJB: Generate CMR field accessors in component interfaces

    Generates CMR fields getter and setter declarations in EJB interfaces

    EJB: Add Java classes source code in the JAR file

    Includes Java classes code in the JAR

    EJB: Generate value object class and associated navigation methods for CMP Entity Beans

    Generates an additional class named %Component.Code%ValueObject for each CMP bean class and declares all the CMP fields as public attributes. In addition, a getter and a setter are generated in the bean class for each CMR relationship

    J2EE: Jar Web component classes

    Archives Web component classes in a Jar

    Note: For information about modifying the options that appear on this and the Tasks tab and adding your own options and tasks, see Customizing and Extending PowerDesigner > Object, Process, and XML Language Definition Files > Generation Category.
  6. [optional] Click the Generated Files tab and specify which files will be generated. By default, all files are generated.

    For information about customizing the files that will be generated, see Customizing and Extending PowerDesigner > Extension Files > Generated Files (Profile).

  7. [optional] Click the Tasks tab and specify any appropriate generation tasks to perform:

    Task

    Description

    Java: Compile Java sources

    Starts a compiler using the javac command to compile Java source files.

    Java: Package compiled classes in a JAR file

    Compiles source files and package them in a JAR file

    Java: Run Java application

    Compiles source files and run the Java application using the java command

    Java: Generate Javadoc

    Generates Javadoc

    Java: Package J2EE application in an EAR file

    Calls commands for building EJB component source, creating a JAR file for Java classes and a deployment descriptor, building the Web component source code, creating an EAR file for Web component classes and a deployment descriptor, and creating an EAR archive containing all generated JAR/WAR files

    Java: Run J2EE verifier

    Calls commands for building EJB component source code, creating a JAR file for Java classes and a deployment descriptor, building the Web component source code, creating a WAR file for Web component classes and a deployment descriptor, creating an EAR archive containing all generated JAR/WAR files, and running the J2EE verifier on generated archives

    WSDL: Compile and package Web Service server-side code into an archive

    Calls commands for building EJB and Web component source code, running the WSCompile tool, creating a WAR file for Web component classes and deployment descriptor, and creating a JAR file for Java classes and deployment descriptor

    WSDL: Compile and package Web Service client proxy into an archive

    Calls commands for building EJB and Web component source code, running the WSCompile tool, and creating a WAR file for client-side artifacts

    Note: Packages with the <<archive>> stereotype will generate a JAR (when they or one of their descendant packages not stereotyped <<archive>> contain one EJB) or a WAR (when they contain a servlet or JSP). Each archive contains the package and all of its non-stereotyped descendants. The model acts as the root package and is considered to be stereotyped <<archive>>.

  8. Click OK to begin generation.

    When generation is complete, the Generated Files dialog opens, listing the files that have been generated to the specified directory. Select a file in the list and click Edit to open it in your associated editor, or click Close to exit the dialog.