SpeakerRemote.java
Код: Выделить всё
package test;
import javax.ejb.Remote;
@Remote
public interface SpeakerRemote {
String sayAPhrase( String phrase );
}
SpeakerBean.java
Код: Выделить всё
package test;
import javax.ejb.Stateless;
@Stateless
public class SpeakerBean implements SpeakerRemote {
@Override
public String sayAPhrase( String phrase ){
return "Speaker Service:\t" + phrase;
}
}
Я собрал его с помощью maven. Здесь я покажу вам вызывающую часть:
Invoker.java
Код: Выделить всё
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
public class Invoker {
public static InitialContext getContext() throws NamingException {
final Properties properties = new Properties();
properties.put( Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory" );
properties.put( Context.PROVIDER_URL, "jnp://127.0.0.1:1099" );
return new InitialContext( properties );
}
}
Main.java
Код: Выделить всё
import test.SpeakerRemote;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Main {
public static void main( String... args ) {
try {
InitialContext context = Invoker.getContext();
SpeakerRemote speaker = ( SpeakerRemote ) context.lookup( "SpeakerBean/remote" );
System.out.println( speaker.sayAPhrase( "Hello, World!" ) );
}
catch ( NamingException e ) {
e.printStackTrace();
}
}
}
"Невозможно создать экземпляр класса: org.jnp.interfaces. NamingContextFactory [Корневое исключение — java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]"
Пожалуйста, помогите мне, потому что мне действительно нужно чтобы это понять!
P.S. Я использую jboss 7.1.1 Final + EJB 3.1 + Maven 3.1.1 + Java 1.7 + Win7
Подробнее здесь: https://stackoverflow.com/questions/207 ... extfactory
Мобильная версия