Results 1 to 4 of 4
  1. #1
    gvanto is offline Member
    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0

    Question Main.java for Java EE 7 on Eclipse (Kepler)

    Hi all,

    I'm currently working my way through the "Beginning Java EE 7 - Antonio Goncalvez" book (which is good, although some simple things are left to one's own research) and I'm a little stuck on page 62 the Main class is written for Weld (which I don't have as I am using Eclipse with Glassfish server)

    Java Code:
    Listing 2-51. Main Class Using the CDI Container to Invoke the BookService
    public class Main {
    public static void main(String[] args) {
    Weld weld = new Weld();
    WeldContainer container = weld.initialize();
    BookService bookService = container.instance().select(BookService.class).get();
    Book book = bookService.createBook("H2G2", 12.5f, "Geeky scifi Book");
    System.out.println(book);
    weld.shutdown();
    }
    }
    So I am wondering how I can get this to work without using Weld?

    any help appreciated
    gvanto

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,090
    Rep Power
    6

    Default Re: Main.java for Java EE 7 on Eclipse (Kepler)

    What do you mean "I don't have weld"? It is the standard CDI implementation and part of Glassfish since the JEE6 platform. You just didn't setup your application's classpath properly.

    Note that it is quite uncommon that you would actually have a client like this in an enterprise stack, don't judge how it works by what you are doing here.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    gvanto is offline Member
    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0

    Default Re: Main.java for Java EE 7 on Eclipse (Kepler)

    when I put:

    Weld weld = new Weld();

    I get 'Weld' underlined red and the IDE suggests to create a new class called 'Weld' ?
    No import option is available ... ??

  4. #4
    gvanto is offline Member
    Join Date
    Nov 2013
    Posts
    10
    Rep Power
    0

    Default Re: Main.java for Java EE 7 on Eclipse (Kepler)

    Ok I have found the jar related to Weld and got following code... but now the weld.initialize() method is not available (even though this is in the book's code sample):

    package org.aptovia.javaee7.CDBOOKSTORE;

    import org.glassfish.weld.WeldContainer;
    import org.jboss.weld.Weld;

    /**
    * Enterprise Application Client main class.
    *
    */
    public class Main {

    public static void main( String[] args ) {

    Weld weld = new Weld();
    WeldContainer container = weld.initialize(); //this initialize method is not found :(

    System.out.println( "Hello World Enterprise Application Client!" );
    }
    }

Similar Threads

  1. Exception in thread main java.lang.nosuchmethoderror main
    By prikesh_joshi7 in forum Java Applets
    Replies: 3
    Last Post: 01-26-2012, 04:19 PM
  2. Replies: 1
    Last Post: 11-23-2011, 05:52 AM
  3. Replies: 7
    Last Post: 01-20-2010, 11:35 AM
  4. Using Eclipse IDE:java.lang.NoClassDefFoundError: main
    By Ms.Ranjan in forum New To Java
    Replies: 6
    Last Post: 12-12-2008, 10:17 PM
  5. Replies: 5
    Last Post: 10-06-2008, 12:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •