Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:07:28+00:00 2026-06-08T11:07:28+00:00

I am trying to generate Java code from EA UML Class Diagram. I define

  • 0

I am trying to generate Java code from EA UML Class Diagram. I define two classes and they have a Composition Relation ship.

say, class A contains a List of class B.

I am able to set the default collection class to List in the Code Generation Dialog Box and it correctly generates the code as:

class B {
 public List<B> m_B;
};

But i am not able to get to generate the import statement automatically. like below:

import java.util.List;
class B {
 public List<B> m_B;
};

I know there is a section in the Code Generation Dialog Box where i can specify the complete import statement, but i have many classes and i would like EA to automatically generate the import statements.

I fiddled with the Code Templates also but i could not get it to import anything other than hard coded import statements in the Code Templates.

the macros

importPackagePath
importClassName

seem to be empty.

Can anyone help me to modify the code template to figure out the imports to be done?

Thanks,

Regards,

Vimal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:07:31+00:00Added an answer on June 8, 2026 at 11:07 am

    I think you should steer clear of the code generation templates. The problem here is that the handling of collection classes goes outside the normal code generation. If a class has a member whose type is a class in another package, EA generates correct import statements – but only if the classes are present in the model, which the collecion classes aren’t.

    There are three ways to get around this:

    1) Accept that the generated code is broken.

    Generate the code, then open it up in an IDE (NetBeans, Eclipse or whatever you’re using) and let it take an educated guess at adding the correct import statements.

    This is quick and easy, but you’ll need to check the results. There is also a risk: if your “B” class imports a package which contains a “List” class, the compiler won’t complain but the referenced “List” class isn’t the one from java.util, which means you’re not getting the code you thought you did.

    2) Model the collection classes.

    Create a package “java” with a child “util” and a template class “List”, then change the model so that instead of a 0..* relationship to B, A has a “1” relationship to this “List” type (not B), but instantiated with type B. The correct relationship for this would be template binding.

    On way of modelling the collection classes is to import rt.jar into your project. This takes a looong time though, and make sure you disable automatic diagram generation or you might run out of memory. But you will then have all utility classes imported once and for all.

    If you want to be on the safe side, remove the collection classes from the Java options (Tools – Options – Source Code Engineering – Java), so EA doesn’t try to use them. But if you change all the relationships, EA won’t use the configured collection classes.

    This results in the most correct model, and also solves the problem of how to refer to other utility classes (eg Calendar), but can be a lot of work if you’ve got a large model without the collection classes.

    3) Use fully-qualified names for the collection classes.

    In the Java options, instead of List<#TYPE#> enter java.util.List<#TYPE#>. The Java compiler doesn’t need import statements if the types are referred to by their fully-qualified names.

    This is extremely quick and easy, and the generated code is correct. Downside is that the code gets a bit bulkier.

    If you only need the collection classes to work, I’d go with this. If you want to refer to other common utility classes, I’d say import rt.jar and rework the model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate on-the-fly PDF reports from Java objects. I have not
I want to generate java code from xsd using JAXB 2.1 XJC. I have
I'm trying to generate Java classes from the FpML (Finanial Products Markup Language) version
I'm trying to execute a script from within my java code which looks like:
I am trying to create a UML class diagram and corresponding class definition (in,
I am trying to upload files using Java URL class and I have found
I am trying to generate java file from wsdlurl. some of them are working
I'm trying to consume a Java based SOAP web service from VBA code in
I'm trying to generate a PDF from a Pentaho .prpt report file in Java.
I am trying to generate java source files from a package of *.xsd files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.