Initializing WeldContainer - HELP PLEASE!
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 where the Main class is written for Weld :
The weld.initialize() method below cannot be found, no idea why :-( Any help would be much appreciated.
Quote:
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(); //it says here can't find this method! ?! there's an option called 'current()'
System.out.println( "Hello World Enterprise Application Client!" );
}
}
Re: Initializing WeldContainer - HELP PLEASE!
No worries, found it: import org.jboss.weld.environment.se.Weld;
NOT: import org.jboss.weld.Weld;
arrrrgg ... so we learn eh.
Re: Initializing WeldContainer - HELP PLEASE!
When in doubt, read the documentation.
Re: Initializing WeldContainer - HELP PLEASE!
Sorry couldn't find that in any documentation :(
Now getting build error with maven:
Quote:
gert@gert-VirtualBox:~/workspace/CDBOOKSTORE$ mvn compile -U
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building CDBOOKSTORE 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading:
http://repo.maven.apache.org/maven2/...d-se-2.1.0.pom
[WARNING] The POM for org.jboss.weld.se:weld-se:jar:2.1.0 is missing, no dependency information available
Downloading:
http://repo.maven.apache.org/maven2/...d-se-2.1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.689s
[INFO] Finished at: Fri Nov 08 13:04:41 EST 2013
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project CDBOOKSTORE: Could not resolve dependencies for project org.aptovia.javaee7:CDBOOKSTORE:app-client:0.0.1-SNAPSHOT: Could not find artifact org.jboss.weld.se:weld-se:jar:2.1.0 in central (
Directory Browsing Disabled) -> [Help 1]
I have set my pom.xml file to include following dependency (I've put 2.1.0 as version since it seems its the latest version: Maven Repository: org.jboss.weld)
so I'm not sure why getting this error?
Quote:
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.1.0</version>
</dependency>
Any help much appreciated
gvanto
Re: Initializing WeldContainer - HELP PLEASE!
OK seems I was missing 'Final' from the end of the version:
The Central Repository Search Engine
Now my proj builds fine, but when trying to execute get following error:
Quote:
gert@gert-VirtualBox:~/workspace/CDBOOKSTORE$ mvn exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building CDBOOKSTORE 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.6:copy (default) @ CDBOOKSTORE ---
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ CDBOOKSTORE ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.158s
[INFO] Finished at: Fri Nov 08 13:49:11 EST 2013
[INFO] Final Memory: 9M/21M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project CDBOOKSTORE: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid -> [Help 1]
I have in my POM.xml file specified the mainClass: (am I missing something somewhere? the pom.xml file seems Ok according to: Exec Maven Plugin - Usage )
Quote:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-acr-plugin</artifactId>
<version>1.0</version>
<extensions>true</extensions>
<configuration>
<archive>
<manifest>
<mainClass>org.aptovia.javaee7.CDBOOKSTORE.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.aptovia.javaee7.CDBOOKSTORE.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Re: Initializing WeldContainer - HELP PLEASE!
Quote:
Originally Posted by
gvanto
Sorry couldn't find that in any documentation :(
You can't have tried very hard.
JBoss has lots of documentation, including this section covering the SE implementation you are using.
If in doubt, go to the source.
Re: Initializing WeldContainer - HELP PLEASE!
Weld is indeed one of the better documented technologies out there. I must say that JBoss/Red Hat itself has bettered their practices in recent years; it used to be that you had to scour the forums to get answers as a non-commercial user of their stuff, but nowadays everything is neatly documented.
Re: Initializing WeldContainer - HELP PLEASE!
Oh yes.
They seem to have taken a leaf out of the Spring and Hibernate books.
Re: Initializing WeldContainer - HELP PLEASE!
well Hibernate is also JBoss/Red Hat ;) In that respect Hibernate documentation is very lengthy, but it doesn't push the envelope; the HQL documentation for example tends to stick to the basic examples and doesn't show most of the things that you would run into in application that actually do mildly exciting things (such as combining different query structures); I still have to regularly ask Google to find the stackoverflow threads that actually do explain how to do it.
Re: Initializing WeldContainer - HELP PLEASE!
Ah, well, I was thinking JBoss 2003, so pre-Hibernate acquisition.
I still wake up screaming...