Now, we're going to test those classes through a new Eclipse project, which references the one with the generated classes.
So, we now create a new plug-in project:
File --> Create --> New --> Project... --> Plug-in Project.
And, in folder src, we create a new class with a stub for method main:
And we create, in method main(), a few lines of code:
package javaUsingEMFModel.LibrarySystem;
import org.eclipse.emf.ecore.*;
import LibraryModel.*;
import LibraryModel.impl.*;
import LibraryModel.util.*;
public class MainClass {
public static void main(String[] args) {
import org.eclipse.emf.ecore.*;
import LibraryModel.*;
import LibraryModel.impl.*;
import LibraryModel.util.*;
public class MainClass {
public static void main(String[] args) {
// Inicialize the LibraryModelPackageImpl
LibraryModelPackageImpl.init();
LibraryModelPackageImpl.init();
LibraryModelFactory factory = LibraryModelFactory.eINSTANCE;
// Create a new Book
Book book = factory.createBook();
// Create a new Book
Book book = factory.createBook();
// Give a title to the book
book.setTitle("Os Lusiadas");
// Create an Author, and define his/her name and surname
Author author1 = factory.createAuthor();
author1.setName("Luis");
author1.setSurname("Camoes");
// Add that author as an author of the previously created book
book.getAuthors().add(author1);
System.out.println(book.getTitle());
}
}
book.setTitle("Os Lusiadas");
// Create an Author, and define his/her name and surname
Author author1 = factory.createAuthor();
author1.setName("Luis");
author1.setSurname("Camoes");
// Add that author as an author of the previously created book
book.getAuthors().add(author1);
System.out.println(book.getTitle());
}
}
Related articles:
- First Eclipse Modeling Framework (EMF) example - 1
- First Eclipse Modeling Framework (EMF) example - 2
No comments:
Post a Comment