Last active
August 29, 2015 14:07
-
-
Save mythosil/b33430a4e97a26d68241 to your computer and use it in GitHub Desktop.
Use Weld with Java SE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sample Application using Weld with Java SE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mythosil.weldse; | |
public class Calc { | |
public int add(int a, int b) { | |
return a + b; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.mythosil</groupId> | |
<artifactId>weldse</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<dependencies> | |
<dependency> | |
<groupId>org.jboss.weld</groupId> | |
<artifactId>weld-se</artifactId> | |
<version>1.0.1-Final</version> | |
</dependency> | |
</dependencies> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<maven.compiler.source>1.8</maven.compiler.source> | |
<maven.compiler.target>1.8</maven.compiler.target> | |
</properties> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mythosil.weldse; | |
import javax.inject.Inject; | |
import javax.inject.Singleton; | |
import org.jboss.weld.environment.se.Weld; | |
import org.jboss.weld.environment.se.WeldContainer; | |
@Singleton | |
public class WeldApplication { | |
@Inject | |
private Calc calc; | |
public void run() { | |
System.out.println(calc.add(1, 3)); | |
} | |
public static void main(String[] args) { | |
Weld weld = new Weld(); | |
WeldContainer container = weld.initialize(); | |
WeldApplication app = container.instance().select(WeldApplication.class).get(); | |
app.run(); | |
weld.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment