使用eclipse通过jboss开发简单的ejb应用(jboss7.x & ejb3.x)

  1. 创建ejb bean服务
    在eclipse中创建mavne项目ilucky-ejb-3.0,然后右键,将其转化为ejb项目,图下:

这里写图片描述

然后创建如下两个class:

package com.ilucky.ejb.service;

import javax.ejb.Remote;

/**
 * 标注为远程接口
 */
@Remote
public interface HelloWorld {
    public String sayHello();
}
package com.ilucky.ejb.service;

import java.util.Random;

import javax.ejb.Stateless;

@Stateless
public class HelloWorldBean implements HelloWorld {
    public HelloWorldBean() {
    }

    public static void main(String[] args) {
        HelloWorldBean hw = new HelloWorldBean();
        try {
            hw.sayHello();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * TODO: 是否需要操作数据库
     * @throws Exception 
     */
    public String sayHello() {
    //  try {
            Random r = new Random();
            int i = r.nextInt(10);
            System.out.println("=============EJB Client comming=================(i % 3)=" + (i % 3));
            if(i % 3 == 0) {
                int j = 0;
                //try {
                    //throw new Exception("测试");
                    System.out.println("========> zero " + i/j);
            }
//              } catch (Exception e) {
//                  e.printStackTrace();
//              }
//          
//          }
//      } catch (Exception e) {
//          e.printStackTrace();
//          System.out.println("-----------------------------END-------------------------------");
//          System.out.println(e.toString());
//      }
        return "Hello World !!!";
    }
}
/**
15:39:26,980 ERROR [stderr] (EJB default - 2) java.lang.ArithmeticException: / by zero
15:39:26,983 ERROR [stderr] (EJB default - 2)   at com.ilucky.ejb.service.HelloWorldBean.sayHello(HelloWorldBean.java:22)
15:39:26,985 ERROR [stderr] (EJB default - 2)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:39:26,986 ERROR [stderr] (EJB default - 2)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
15:39:26,987 ERROR [stderr] (EJB default - 2)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:39:26,988 ERROR [stderr] (EJB default - 2)   at java.lang.reflect.Method.invoke(Method.java:606)
15:39:26,989 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
15:39:26,992 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:26,994 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
15:39:26,995 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)
15:39:26,998 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,001 ERROR [stderr] (EJB default - 2)   at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
15:39:27,003 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,005 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
15:39:27,006 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,007 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
15:39:27,008 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
15:39:27,010 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,011 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
15:39:27,013 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,014 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)
15:39:27,016 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)
15:39:27,017 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)
15:39:27,018 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,019 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropogatingInterceptor.processInvocation(EJBRemoteTransactionPropogatingInterceptor.java:80)
15:39:27,020 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,021 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
15:39:27,022 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,023 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
15:39:27,024 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,025 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
15:39:27,026 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,027 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
15:39:27,028 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
15:39:27,029 ERROR [stderr] (EJB default - 2)   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
15:39:27,030 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
15:39:27,030 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:300)
15:39:27,032 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$200(MethodInvocationMessageHandler.java:64)
15:39:27,032 ERROR [stderr] (EJB default - 2)   at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:194)
15:39:27,033 ERROR [stderr] (EJB default - 2)   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
15:39:27,034 ERROR [stderr] (EJB default - 2)   at java.util.concurrent.FutureTask.run(FutureTask.java:262)
15:39:27,035 ERROR [stderr] (EJB default - 2)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
15:39:27,036 ERROR [stderr] (EJB default - 2)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
15:39:27,037 ERROR [stderr] (EJB default - 2)   at java.lang.Thread.run(Thread.java:745)
15:39:27,037 ERROR [stderr] (EJB default - 2)   at org.jboss.threads.JBossThread.run(JBossThread.java:122)
15:39:27,038 INFO  [stdout] (EJB default - 2) -----------------------------END-------------------------------
15:39:27,039 INFO  [stdout] (EJB default - 2) java.lang.ArithmeticException: / by zero
*/

相关的pom文件如下:

<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.ilucky.ejb</groupId>
  <artifactId>ilucky-ejb-3.0</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>ilucky-ejb-3.0</name>
  <url>http://maven.apache.org</url>

  <!-- <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
    </dependency>
  </dependencies>
</project>
 -->
 <properties>
        <!-- Explicitly declaring the source encoding eliminates the following 
            message: -->
        <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered 
            resources, i.e. build is platform dependent! -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- JBoss dependency versions -->
        <version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>
        <version.org.jboss.spec.jboss.javaee.6.0>3.0.0.Final</version.org.jboss.spec.jboss.javaee.6.0>

        <!-- other plugin versions -->
        <version.compiler.plugin>2.3.1</version.compiler.plugin>
        <version.ejb.plugin>2.3</version.ejb.plugin>

        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.6</maven.compiler.target>
        <maven.compiler.source>1.6</maven.compiler.source>

        <!-- IluckySi -->
        <!-- Optional: to use jboss-as:run goal -->
        <!-- <jboss-as.home>C:\Users\iByteCode\Desktop\jboss-as-7.1.0.Final</jboss-as.home>  -->
        <jboss-as.home>E:\software\jboss\jboss-as-7.1.0.Final</jboss-as.home>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
            <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill 
                of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) 
                of artifacts. We use this here so that we always get the correct versions 
                of artifacts. Here we use the jboss-javaee-6.0 stack (you can read this as 
                the JBoss stack of the Java EE 6 APIs). You can actually use this stack with 
                any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! -->
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <!-- Import the Common Annotations API (JSR-250), we use provided scope 
            as the API is included in JBoss AS 7 -->
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.1_spec</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Import the EJB 3.1 API, we use provided scope as the API is included 
            in JBoss AS 7 -->
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.1_spec</artifactId>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <!-- <finalName>${artifactId}</finalName> -->
        <!-- Set the name of the deployment -->
        <plugins>
            <!-- JBoss AS plugin to deploy the application -->
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>${version.org.jboss.as.plugins.maven.plugin}</version>
                <configuration>

                    <!-- IluckySi -->
                     <jbossHome>${jboss-as.home}</jbossHome>  

                    <filename>${project.build.finalName}.jar</filename>
                </configuration>
            </plugin>
            <!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation 
                processors -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.compiler.plugin}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>${version.ejb.plugin}</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                    <!-- this is false by default -->
                    <generateClient>true</generateClient>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

最后,打包并将ilucky-ejb-3.0-0.0.1-SNAPSHOT.jar部署到jboss服务器目录/opt/jboss/jboss-as-7.1.0.Final/standalone/deployments下,启动jboss。

2 . 创建ejb client服务
创建maven项目ilucky-ejb-3.0-client,直接看代码:

package com.ilucky.ejb;

import javax.naming.Context;
import javax.naming.NamingException;

import com.ilucky.ejb.service.HelloWorld;

public class Client {

    public static void main(String[] args) {
        HelloWorld bean = doLookup();
        System.out.println(bean.sayHello()); // 4. Call business logic
    }

    private static HelloWorld doLookup() {
        Context context = null;
        HelloWorld bean = null;
        try {
            // 1. Obtaining Context
            context = ClientUtility.getInitialContext();
            // 2. Generate JNDI Lookup name
            String lookupName = getLookupName();
            // 3. Lookup and cast
            bean = (HelloWorld) context.lookup(lookupName);

        } catch (NamingException e) {
            e.printStackTrace();
        }
        return bean;
    }

    private static String getLookupName() {
        /*
         * The app name is the EAR name of the deployed EJB without .ear suffix.
         * Since we haven't deployed the application as a .ear, the app name for
         * us will be an empty string
         */
        String appName = "";

        /*
         * The module name is the JAR name of the deployed EJB without the .jar
         * suffix.
         */
        //String moduleName = "ejbmavendemo-1.0-SNAPSHOT";
        String moduleName = "ilucky-ejb-3.0-0.0.1-SNAPSHOT";

        /*
         * AS7 allows each deployment to have an (optional) distinct name. This
         * can be an empty string if distinct name is not specified.
         */
        String distinctName = "";

        // The EJB bean implementation class name
        String beanName = "HelloWorldBean";

        // Fully qualified remote interface name
       // final String interfaceName = "com.theopentutorials.ejb3.HelloWorld";
        final String interfaceName = "com.ilucky.ejb.service.HelloWorld";

        // Create a look up string name
        String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName
                + "/" + beanName + "!" + interfaceName;

        return name;
    }

}
package com.ilucky.ejb;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class ClientUtility {

    private static Context initialContext;
    private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";

    public static Context getInitialContext() throws NamingException {
        if (initialContext == null) {
            Properties props = new Properties();
            props.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);

            // Ilucky
            //properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
            // props.put(Context.INITIAL_CONTEXT_FACTORY, " javax.naming.spi.InitialContextFactory");
 //           props.put(Context.PROVIDER_URL, "http-remote://10.0.3.42:4447"); 
//            props.put(Context.SECURITY_PRINCIPAL, "sdx");
//            props.put(Context.SECURITY_CREDENTIALS, "123");
  //            properties.put("jboss.naming.client.ejb.context", true);  
//            properties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
//            properties.put("remote.connections", "default");
//            properties.put("remote.connection.default.host", "10.0.3.42");
//            properties.put("remote.connection.default.port", "4447"); 
//            properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false"); 
             // properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
              initialContext = new InitialContext(props);
        }
        return initialContext;
    }
}

/**
test
123456
testrole
*/

并且在src/main/resources目录下创建jboss-ejb-client.properties文件,内容如下:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=10.0.3.42
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

#---------------------------------------------------------------------------------
remote.connection.x1.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
remote.connection.x1.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false
#java.naming.provider.url=http-remote://10.0.3.42:4447
java.naming.security.principal=sdx
java.naming.security.credentials=123
#jboss.naming.client.ejb.context=true
#remote.connections=default
#endpoint.name=client-endpoint
#remote.connection.default.port = 4447
#remote.connection.default.host=10.0.3.42
#remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
#remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

相关的pom文件如下:

<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.ilucky.ejb</groupId>
  <artifactId>ilucky-ejb-3.0-client</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>ilucky-ejb-3.0-client</name>
  <url>http://maven.apache.org</url>

   <properties>
        <!-- Explicitly declaring the source encoding eliminates the following
            message: -->
        <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
            resources, i.e. build is platform dependent! -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- JBoss dependency versions -->
        <version.org.jboss.as>7.1.1.Final</version.org.jboss.as>
        <version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>
        <version.org.jboss.spec.jboss.javaee.6.0>3.0.0.Final</version.org.jboss.spec.jboss.javaee.6.0>

        <!-- other plugin versions -->
        <version.compiler.plugin>2.3.1</version.compiler.plugin>
        <version.exec.plugin>1.2.1</version.exec.plugin>

        <!-- maven-compiler-plugin -->
        <maven.compiler.target>1.6</maven.compiler.target>
        <maven.compiler.source>1.6</maven.compiler.source>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Define the version of JBoss' Java EE 6 APIs we want to use -->
            <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
                of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
                of artifacts. We use this here so that we always get the correct versions
                of artifacts. Here we use the jboss-javaee-6.0 stack (you can read this as
                the JBoss stack of the Java EE 6 APIs). You can actually use this stack with
                any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! -->
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.jboss.as</groupId>
                <artifactId>jboss-as-ejb-client-bom</artifactId>
                <version>${version.org.jboss.as}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
    <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <!-- Import the transaction spec API, we use runtime scope because we aren't
            using any direct reference to the spec API in our client code -->
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.1_spec</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Import the EJB 3.1 API, we use runtime scope because we aren't using
            any direct reference to EJB spec API in our client code -->
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.1_spec</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- ADD  -->
        <!-- We depend on the EJB remote business interfaces of this application -->
        <dependency>
             <groupId>com.ilucky.ejb</groupId>
              <artifactId>ilucky-ejb-3.0</artifactId>
              <version>0.0.1-SNAPSHOT</version>
        </dependency>


        <!-- JBoss EJB client API jar. We use runtime scope because the EJB client
            API isn't directly used in this example. We just need it in our runtime classpath -->
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jboss-ejb-client</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- client communications with the server use XNIO -->
        <dependency>
            <groupId>org.jboss.xnio</groupId>
            <artifactId>xnio-api</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.xnio</groupId>
            <artifactId>xnio-nio</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- The client needs JBoss remoting to access the server -->
        <dependency>
            <groupId>org.jboss.remoting3</groupId>
            <artifactId>jboss-remoting</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- Remote EJB accesses can be secured -->
        <dependency>
            <groupId>org.jboss.sasl</groupId>
            <artifactId>jboss-sasl</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- data serialization for invoking remote EJBs -->
        <dependency>
            <groupId>org.jboss.marshalling</groupId>
            <artifactId>jboss-marshalling-river</artifactId>
            <scope>runtime</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!-- Enforce Java 1.6 -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.compiler.plugin}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>

            <!-- Add the maven exec plugin to allow us to run a java program via maven -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${version.exec.plugin}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                    <workingDirectory>${project.build.directory}/exec-working-directory</workingDirectory>
                    <arguments>
                        <!-- automatically creates the classpath using all project dependencies,
                            also adding the project build directory -->
                        <argument>-classpath</argument>
                        <classpath>
                        </classpath>
                        <argument>com.ilucky.ejb.Client</argument>
                    </arguments>
                </configuration>
            </plugin>

                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <encoding>UTF-8</encoding>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.ilucky.ejb.Client</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

将client服务打包成ilucky-ejb-3.0-client-0.0.1-SNAPSHOT.jar文件,执行:
java -jar ilucky-ejb-3.0-client-0.0.1-SNAPSHOT.jar

demo下载:
http://download.csdn.net/download/sidongxue2/9940532

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值