head first 读书笔记:观察者模式(openfire 消息通知 demo)

本文介绍了一种使用Subject-Observer模式在Openfire服务器接收消息,并将消息实时同步到最近联系人界面和正在聊天界面的方法。通过创建Openfire类作为Subject,实现了消息的发送和接收,同时通过Observer类注册监听者,确保了消息能够被多个界面接收到并进行相应的展示。代码示例展示了如何实现这一功能,包括消息的注册、移除和通知过程,以及如何通过单例模式和属性注入来简化实例化和管理过程。

场景:我们要从openfire服务器获取消息,然后同步更新到最近联系人界面和正在聊天的界面。此系统必须可扩展(公布一组API,让其他开发人员也可以写出自己的即时通讯),也就是用户可以自己增加或者删除接收消息的界面。


直接上代码:


父类


@interface Subject : NSObject


//注册监听者

- (void)registObserver:(Observer *)o;


//移除监听者

- (void)removeObserver:(Observer *)o;


//通知监听者

- (void)notifyObserver;


@end



@interface Observer : NSObject



//更新

- (void)updateDispayWithContent:(NSString *)content fromPeople:(NSString *)from toPeople:(NSString *)to;


@end



子类:


@interface Openfire : Subject




//发送消息

- (void) sendMessage:(NSString *)content fromPoeple:(NSString *)from toPeople:(NSString *)to;


@end


@interface Openfire()



@property (retain, nonatomic) NSMutableArray *observers;


@property (retain, nonatomic) NSString *fromPeople;

@property (retain, nonatomic) NSString *toPeople;

@property (retain, nonatomic) NSString *messageContent;


@end



@implementation Openfire



- (void)dealloc{

    

    [self.observers release];

    self.observers = nil;

    

    [super dealloc];

}


- (id)init{

    

    self = [super init];

    

    if (self) {

        

        self.observers = [[NSMutableArray alloc] init];

        

    }

    return self;

}


//创建数据库单例模式

+ (id)shareOpenfire{

    

    static dispatch_once_t openfireToken;

    static id shareOpenfire = nil;

    

    dispatch_once(&openfireToken, ^{

        shareOpenfire = [[[self class] alloc] init];

    });

    return shareOpenfire;

}



//注册监听者

- (void)registObserver:(Observer *)o{

    

    [self.observers addObject:o];

}


//移除监听者

- (void)removeObserver:(Observer *)o{

    

    NSInteger i = [self.observers indexOfObject:o];

    

    if (i>=0 && i<[self.observers count]) {

        

        [self.observers removeObjectAtIndex:i];

    }

}


//通知监听者

- (void)notifyObserver{

   

    for (int i=0; i<[self.observers count]; i++) {

        

        Observer *o = [self.observers objectAtIndex:i];

        

        [o updateDispayWithContent:self.messageContent fromPeople:self.fromPeople toPeople:self.toPeople];

    }

}



//收到消息

- (void)receiveMessage{


    [self notifyObserver];

}



//发送消息

- (void) sendMessage:(NSString *)content fromPoeple:(NSString *)from toPeople:(NSString *)to{


    self.messageContent = content;

    self.fromPeople = from;

    self.toPeople = to;

    

    [self receiveMessage];

}



@end



@interface Chat : Observer


//初始化

- (id)initWithSubject:(Subject *)obj;



@end


@interface Chat()



@property (retain, nonatomic) Subject *openfire;


@end



@implementation Chat



- (void)dealloc{

    

    if (self.openfire) {

        

        [self.openfire removeObserver:self];

        

        [self.openfire release];

        self.openfire = nil;

    }

    

    [super dealloc];

}


//初始化

- (id)initWithSubject:(Subject *)obj{


    self = [super init];

    

    if (self) {

        

        if (obj) {

            self.openfire = obj;

            

            [self.openfire registObserver:self];

        }

    }

    

    return self;


}


//更新

- (void)updateDispayWithContent:(NSString *)content fromPeople:(NSString *)from toPeople:(NSString *)to{


    [self displayMessage:content fromPeople:from toPeople:to];

}




//显示

- (void)displayMessage:(NSString *)content fromPeople:(NSString *)from toPeople:(NSString *)to{

    

    

    NSLog(@"chat收到消息:%@ from%@ to%@", content, from, to);

    

}



@end




测试代码;


    Openfire *o = [[Openfire alloc] init];


    Chat *c = [[Chat alloc]initWithSubject:o];

    Recent *r = [[Recent alloc]initWithSubject:o];

    

    [o sendMessage:@"测试。。。" fromPoeple:@"lichenglong" toPeople:@"ping"];

    [o sendMessage:@"test。。。" fromPoeple:@"lichenglong" toPeople:@"li"];

    [o sendMessage:@"hello。。。" fromPoeple:@"lichenglong" toPeople:@"lee"];

    [o sendMessage:@"你好。。。" fromPoeple:@"lichenglong" toPeople:@"chen"];


    [o release];

    [c release];

    [r release];




[root@yfw ~]# cd /opt/openfire/bin [root@yfw bin]# ./start.sh Using Java: /usr/lib/jvm/java-17-openjdk/bin/java Java Version: openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing) Classpath: /opt/openfire/resources:/opt/openfire/lib/activation-1.1.jar:/opt/openfire/lib/apache-el-9.0.107.jar:/opt/openfire/lib/apache-jsp-9.0.107.jar:/opt/openfire/lib/asm-9.8.jar:/opt/openfire/lib/asm-commons-9.8.jar:/opt/openfire/lib/asm-tree-9.8.jar:/opt/openfire/lib/bcpg-jdk18on-1.78.1.jar:/opt/openfire/lib/bcpkix-jdk18on-1.78.1.jar:/opt/openfire/lib/bcprov-jdk18on-1.78.1.jar:/opt/openfire/lib/bcutil-jdk18on-1.78.1.jar:/opt/openfire/lib/caffeine-3.2.0.jar:/opt/openfire/lib/checker-qual-3.33.0.jar:/opt/openfire/lib/common-image-3.9.4.jar:/opt/openfire/lib/common-io-3.9.4.jar:/opt/openfire/lib/common-lang-3.9.4.jar:/opt/openfire/lib/commons-codec-1.15.jar:/opt/openfire/lib/commons-dbcp2-2.9.0.jar:/opt/openfire/lib/commons-ip-math-1.32.jar:/opt/openfire/lib/commons-lang3-3.18.0.jar:/opt/openfire/lib/commons-logging-1.2.jar:/opt/openfire/lib/commons-pool2-2.9.0.jar:/opt/openfire/lib/commons-text-1.10.0.jar:/opt/openfire/lib/dom4j-2.1.4.jar:/opt/openfire/lib/dwr-3.0.2-RELEASE.jar:/opt/openfire/lib/ecj-3.33.0.jar:/opt/openfire/lib/error_prone_annotations-2.18.0.jar:/opt/openfire/lib/failureaccess-1.0.1.jar:/opt/openfire/lib/guava-32.0.1-jre.jar:/opt/openfire/lib/hsqldb-2.7.1.jar:/opt/openfire/lib/httpclient-4.5.13.jar:/opt/openfire/lib/httpcore-4.4.13.jar:/opt/openfire/lib/i18n-5.0.2.jar:/opt/openfire/lib/imageio-bmp-3.9.4.jar:/opt/openfire/lib/imageio-core-3.9.4.jar:/opt/openfire/lib/istack-commons-runtime-3.0.11.jar:/opt/openfire/lib/j2objc-annotations-2.8.jar:/opt/openfire/lib/jakarta.activation-1.2.2.jar:/opt/openfire/lib/jakarta.annotation-api-1.3.5.jar:/opt/openfire/lib/jakarta.transaction-api-1.3.3.jar:/opt/openfire/lib/jakarta.xml.bind-api-2.3.3.jar:/opt/openfire/lib/jansi-1.18.jar:/opt/openfire/lib/javax.activation-api-1.2.0.jar:/opt/openfire/lib/javax.mail-1.6.2.jar:/opt/openfire/lib/jaxb-api-2.3.1.jar:/opt/openfire/lib/jaxb-runtime-2.3.3.jar:/opt/openfire/lib/jaxen-1.2.0.jar:/opt/openfire/lib/jcip-annotations-1.0.jar:/opt/openfire/lib/jcl-over-slf4j-2.0.9.jar:/opt/openfire/lib/jetty-ee-12.0.24.jar:/opt/openfire/lib/jetty-ee8-annotations-12.0.24.jar:/opt/openfire/lib/jetty-ee8-apache-jsp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-nested-12.0.24.jar:/opt/openfire/lib/jetty-ee8-plus-12.0.24.jar:/opt/openfire/lib/jetty-ee8-security-12.0.24.jar:/opt/openfire/lib/jetty-ee8-servlet-12.0.24.jar:/opt/openfire/lib/jetty-ee8-webapp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-api-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-common-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-servlet-12.0.24.jar:/opt/openfire/lib/jetty-http-12.0.24.jar:/opt/openfire/lib/jetty-io-12.0.24.jar:/opt/openfire/lib/jetty-jmx-12.0.24.jar:/opt/openfire/lib/jetty-jndi-12.0.24.jar:/opt/openfire/lib/jetty-plus-12.0.24.jar:/opt/openfire/lib/jetty-security-12.0.24.jar:/opt/openfire/lib/jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-servlet-api-4.0.6.jar:/opt/openfire/lib/jetty-session-12.0.24.jar:/opt/openfire/lib/jetty-util-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-common-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-server-12.0.24.jar:/opt/openfire/lib/jetty-xml-12.0.24.jar:/opt/openfire/lib/jmdns-1.0.jar:/opt/openfire/lib/jsmpp-2.3.10.jar:/opt/openfire/lib/json-20231013.jar:/opt/openfire/lib/jspecify-1.0.0.jar:/opt/openfire/lib/jsr305-3.0.2.jar:/opt/openfire/lib/jtds-1.3.1.jar:/opt/openfire/lib/jzlib-1.1.3.jar:/opt/openfire/lib/libidn-1.35.jar:/opt/openfire/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/opt/openfire/lib/log4j-api-2.20.0.jar:/opt/openfire/lib/log4j-core-2.20.0.jar:/opt/openfire/lib/log4j-slf4j2-impl-2.20.0.jar:/opt/openfire/lib/mssql-jdbc-9.4.1.jre11.jar:/opt/openfire/lib/mysql-connector-java-5.1.49.jar:/opt/openfire/lib/netty-all-4.1.118.Final.jar:/opt/openfire/lib/netty-buffer-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-haproxy-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http2-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-memcache-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-mqtt-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-redis-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-smtp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-socks-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-stomp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-xml-4.1.118.Final.jar:/opt/openfire/lib/netty-common-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-proxy-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-ssl-ocsp-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-classes-macos-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-epoll-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-kqueue-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-aarch_64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-riscv64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-x86_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-native-unix-common-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-rxtx-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-sctp-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-udt-4.1.118.Final.jar:/opt/openfire/lib/ojdbc11-23.7.0.25.01.jar:/opt/openfire/lib/ons-23.7.0.25.01.jar:/opt/openfire/lib/oraclepki-23.7.0.25.01.jar:/opt/openfire/lib/orai18n-23.7.0.25.01.jar:/opt/openfire/lib/postgresql-42.7.7.jar:/opt/openfire/lib/rsi-23.7.0.25.01.jar:/opt/openfire/lib/shaj-0.5.jar:/opt/openfire/lib/simplefan-23.7.0.25.01.jar:/opt/openfire/lib/sitemesh-2.5.0.jar:/opt/openfire/lib/slf4j-api-2.0.9.jar:/opt/openfire/lib/startup.jar:/opt/openfire/lib/taglibs-standard-impl-1.2.5.jar:/opt/openfire/lib/taglibs-standard-spec-1.2.5.jar:/opt/openfire/lib/tinder-2.1.0.jar:/opt/openfire/lib/txw2-2.3.3.jar:/opt/openfire/lib/ucp-23.7.0.25.01.jar:/opt/openfire/lib/xdb-23.7.0.25.01.jar:/opt/openfire/lib/xmppserver-5.0.2.jar:/opt/openfire/lib/xpp3-1.1.4c.0.jar Starting OpenFire... OpenFire started (PID 1138145) Check logs: tail -f /opt/openfire/logs/nohup.out [root@yfw bin]#
最新发布
11-16
[root@yfw ~]# cd /etc/systemd/system [root@yfw system]# ls -l /opt/openfire/lib/startup.jar -rwxr-xr-x 1 openfire openfire 51542 Feb 1 1980 /opt/openfire/lib/startup.jar [root@yfw system]# sudo -u openfire cat /opt/openfire/lib/startup.jar | head -c 4 PK[root@yfw system]# sudo sed -i '/^su -s \/bin\/sh -c/c\ > su -s /bin/sh -c "\ > echo \"DEBUG: Current user: $(whoami)\";\ > echo \"DEBUG: Current dir: $(pwd)\";\ > echo \"DEBUG: Checking startup.jar...\";\ > ls -l lib/startup.jar;\ > file lib/startup.jar;\ > java -cp lib/startup.jar org.jivesoftware.openfire.starter.ServerStarter --help 2>&1 || echo \\\"Failed to run ServerStarter\\\";\ > echo \"Starting OpenFire正式启动...\";\ > exec '\"$JAVA\"' \ > -server \ > -Xms64m \ > -Xmx512m \ > -DopenfireHome=\"'$OPENFIRE_HOME'\" \ > -Dopenfire.lib.dir=\"'$OPENFIRE_HOME'/lib\" \ > -Dlog4j.configurationFile=\"file://'$OPENFIRE_HOME'/lib/log4j2.xml\" \ > -classpath '\"$CP\"' \ > org.jivesoftware.openfire.starter.ServerStarter" openfire >> "$LOG_FILE" 2>&1 &\' /opt/openfire/bin/start.sh [root@yfw system]# /opt/openfire/bin/start.sh Using Java: /usr/lib/jvm/java-17-openjdk/bin/java Java Version: openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing) Classpath: /opt/openfire/lib/activation-1.1.jar:/opt/openfire/lib/apache-el-9.0.107.jar:/opt/openfire/lib/apache-jsp-9.0.107.jar:/opt/openfire/lib/asm-9.8.jar:/opt/openfire/lib/asm-commons-9.8.jar:/opt/openfire/lib/asm-tree-9.8.jar:/opt/openfire/lib/bcpg-jdk18on-1.78.1.jar:/opt/openfire/lib/bcpkix-jdk18on-1.78.1.jar:/opt/openfire/lib/bcprov-jdk18on-1.78.1.jar:/opt/openfire/lib/bcutil-jdk18on-1.78.1.jar:/opt/openfire/lib/caffeine-3.2.0.jar:/opt/openfire/lib/checker-qual-3.33.0.jar:/opt/openfire/lib/common-image-3.9.4.jar:/opt/openfire/lib/common-io-3.9.4.jar:/opt/openfire/lib/common-lang-3.9.4.jar:/opt/openfire/lib/commons-codec-1.15.jar:/opt/openfire/lib/commons-dbcp2-2.9.0.jar:/opt/openfire/lib/commons-ip-math-1.32.jar:/opt/openfire/lib/commons-lang3-3.18.0.jar:/opt/openfire/lib/commons-logging-1.2.jar:/opt/openfire/lib/commons-pool2-2.9.0.jar:/opt/openfire/lib/commons-text-1.10.0.jar:/opt/openfire/lib/dom4j-2.1.4.jar:/opt/openfire/lib/dwr-3.0.2-RELEASE.jar:/opt/openfire/lib/ecj-3.33.0.jar:/opt/openfire/lib/error_prone_annotations-2.18.0.jar:/opt/openfire/lib/failureaccess-1.0.1.jar:/opt/openfire/lib/guava-32.0.1-jre.jar:/opt/openfire/lib/hsqldb-2.7.1.jar:/opt/openfire/lib/httpclient-4.5.13.jar:/opt/openfire/lib/httpcore-4.4.13.jar:/opt/openfire/lib/i18n-5.0.2.jar:/opt/openfire/lib/imageio-bmp-3.9.4.jar:/opt/openfire/lib/imageio-core-3.9.4.jar:/opt/openfire/lib/istack-commons-runtime-3.0.11.jar:/opt/openfire/lib/j2objc-annotations-2.8.jar:/opt/openfire/lib/jakarta.activation-1.2.2.jar:/opt/openfire/lib/jakarta.annotation-api-1.3.5.jar:/opt/openfire/lib/jakarta.transaction-api-1.3.3.jar:/opt/openfire/lib/jakarta.xml.bind-api-2.3.3.jar:/opt/openfire/lib/jansi-1.18.jar:/opt/openfire/lib/javax.activation-api-1.2.0.jar:/opt/openfire/lib/javax.mail-1.6.2.jar:/opt/openfire/lib/jaxb-api-2.3.1.jar:/opt/openfire/lib/jaxb-runtime-2.3.3.jar:/opt/openfire/lib/jaxen-1.2.0.jar:/opt/openfire/lib/jcip-annotations-1.0.jar:/opt/openfire/lib/jcl-over-slf4j-2.0.9.jar:/opt/openfire/lib/jetty-ee-12.0.24.jar:/opt/openfire/lib/jetty-ee8-annotations-12.0.24.jar:/opt/openfire/lib/jetty-ee8-apache-jsp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-nested-12.0.24.jar:/opt/openfire/lib/jetty-ee8-plus-12.0.24.jar:/opt/openfire/lib/jetty-ee8-security-12.0.24.jar:/opt/openfire/lib/jetty-ee8-servlet-12.0.24.jar:/opt/openfire/lib/jetty-ee8-webapp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-api-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-common-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-servlet-12.0.24.jar:/opt/openfire/lib/jetty-http-12.0.24.jar:/opt/openfire/lib/jetty-io-12.0.24.jar:/opt/openfire/lib/jetty-jmx-12.0.24.jar:/opt/openfire/lib/jetty-jndi-12.0.24.jar:/opt/openfire/lib/jetty-plus-12.0.24.jar:/opt/openfire/lib/jetty-security-12.0.24.jar:/opt/openfire/lib/jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-servlet-api-4.0.6.jar:/opt/openfire/lib/jetty-session-12.0.24.jar:/opt/openfire/lib/jetty-util-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-common-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-server-12.0.24.jar:/opt/openfire/lib/jetty-xml-12.0.24.jar:/opt/openfire/lib/jmdns-1.0.jar:/opt/openfire/lib/jsmpp-2.3.10.jar:/opt/openfire/lib/json-20231013.jar:/opt/openfire/lib/jspecify-1.0.0.jar:/opt/openfire/lib/jsr305-3.0.2.jar:/opt/openfire/lib/jtds-1.3.1.jar:/opt/openfire/lib/jzlib-1.1.3.jar:/opt/openfire/lib/libidn-1.35.jar:/opt/openfire/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/opt/openfire/lib/log4j-api-2.20.0.jar:/opt/openfire/lib/log4j-core-2.20.0.jar:/opt/openfire/lib/log4j-slf4j2-impl-2.20.0.jar:/opt/openfire/lib/mssql-jdbc-9.4.1.jre11.jar:/opt/openfire/lib/mysql-connector-j-8.2.0.jar:/opt/openfire/lib/netty-all-4.1.118.Final.jar:/opt/openfire/lib/netty-buffer-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-haproxy-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http2-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-memcache-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-mqtt-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-redis-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-smtp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-socks-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-stomp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-xml-4.1.118.Final.jar:/opt/openfire/lib/netty-common-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-proxy-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-ssl-ocsp-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-classes-macos-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-epoll-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-kqueue-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-aarch_64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-riscv64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-x86_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-native-unix-common-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-rxtx-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-sctp-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-udt-4.1.118.Final.jar:/opt/openfire/lib/ojdbc11-23.7.0.25.01.jar:/opt/openfire/lib/ons-23.7.0.25.01.jar:/opt/openfire/lib/oraclepki-23.7.0.25.01.jar:/opt/openfire/lib/orai18n-23.7.0.25.01.jar:/opt/openfire/lib/postgresql-42.7.7.jar:/opt/openfire/lib/rsi-23.7.0.25.01.jar:/opt/openfire/lib/shaj-0.5.jar:/opt/openfire/lib/simplefan-23.7.0.25.01.jar:/opt/openfire/lib/sitemesh-2.5.0.jar:/opt/openfire/lib/slf4j-api-2.0.9.jar:/opt/openfire/lib/startup.jar:/opt/openfire/lib/taglibs-standard-impl-1.2.5.jar:/opt/openfire/lib/taglibs-standard-spec-1.2.5.jar:/opt/openfire/lib/tinder-2.1.0.jar:/opt/openfire/lib/txw2-2.3.3.jar:/opt/openfire/lib/ucp-23.7.0.25.01.jar:/opt/openfire/lib/xdb-23.7.0.25.01.jar:/opt/openfire/lib/xmppserver-5.0.2.jar:/opt/openfire/lib/xpp3-1.1.4c.0.jar Starting OpenFire... /opt/openfire/bin/start.sh: line 48: cd: $OPENFIRE_HOME: No such file or directory /opt/openfire/bin/start.sh: line 49: exec: $JAVA: not found [root@yfw system]# tail -f /opt/openfire/logs/nohup.out DEBUG: Current user: root DEBUG: Current dir: /opt/openfire DEBUG: Checking startup.jar... -rwxr-xr-x 1 openfire openfire 51542 Feb 1 1980 lib/startup.jar lib/startup.jar: Zip archive data, at least v1.0 to extract Error: LinkageError occurred while loading main class org.jivesoftware.openfire.starter.ServerStarter java.lang.UnsupportedClassVersionError: org/jivesoftware/openfire/starter/ServerStarter has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0 "Failed to run ServerStarter" Starting OpenFire正式启动... sh: line 0: exec: -s: invalid option exec: usage: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
11-16
[root@yfw ~]# cd /etc/systemd/system [root@yfw system]# # 停止正在运行的进程 [root@yfw system]# pkill -f openfire [root@yfw system]# [root@yfw system]# # 删除可能导致冲突的目录 [root@yfw system]# sudo rm -rf /opt/openfire/embedded-db [root@yfw system]# sudo rm -rf /opt/openfire/work [root@yfw system]# sudo rm -rf /opt/openfire/temp [root@yfw system]# # 停止正在运行的进程 [root@yfw system]# pkill -f openfire [root@yfw system]# [root@yfw system]# # 删除可能导致冲突的目录 [root@yfw system]# sudo rm -rf /opt/openfire/embedded-db [root@yfw system]# sudo rm -rf /opt/openfire/work [root@yfw system]# sudo rm -rf /opt/openfire/temp [root@yfw system]# sudo mkdir -p /opt/openfire/embedded-db [root@yfw system]# sudo chown -R openfire:openfire /opt/openfire/embedded-db [root@yfw system]# sudo chmod 755 /opt/openfire/embedded-db [root@yfw system]# sudo chown -R openfire:openfire /opt/openfire/logs [root@yfw system]# sudo chown -R openfire:openfire /opt/openfire/conf [root@yfw system]# /opt/openfire/bin/start.sh Using Java: /usr/lib/jvm/java-17-openjdk/bin/java Java Version: openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing) Classpath: /opt/openfire/lib/activation-1.1.jar:/opt/openfire/lib/apache-el-9.0.107.jar:/opt/openfire/lib/apache-jsp-9.0.107.jar:/opt/openfire/lib/asm-9.8.jar:/opt/openfire/lib/asm-commons-9.8.jar:/opt/openfire/lib/asm-tree-9.8.jar:/opt/openfire/lib/bcpg-jdk18on-1.78.1.jar:/opt/openfire/lib/bcpkix-jdk18on-1.78.1.jar:/opt/openfire/lib/bcprov-jdk18on-1.78.1.jar:/opt/openfire/lib/bcutil-jdk18on-1.78.1.jar:/opt/openfire/lib/caffeine-3.2.0.jar:/opt/openfire/lib/checker-qual-3.33.0.jar:/opt/openfire/lib/common-image-3.9.4.jar:/opt/openfire/lib/common-io-3.9.4.jar:/opt/openfire/lib/common-lang-3.9.4.jar:/opt/openfire/lib/commons-codec-1.15.jar:/opt/openfire/lib/commons-dbcp2-2.9.0.jar:/opt/openfire/lib/commons-ip-math-1.32.jar:/opt/openfire/lib/commons-lang3-3.18.0.jar:/opt/openfire/lib/commons-logging-1.2.jar:/opt/openfire/lib/commons-pool2-2.9.0.jar:/opt/openfire/lib/commons-text-1.10.0.jar:/opt/openfire/lib/dom4j-2.1.4.jar:/opt/openfire/lib/dwr-3.0.2-RELEASE.jar:/opt/openfire/lib/ecj-3.33.0.jar:/opt/openfire/lib/error_prone_annotations-2.18.0.jar:/opt/openfire/lib/failureaccess-1.0.1.jar:/opt/openfire/lib/guava-32.0.1-jre.jar:/opt/openfire/lib/hsqldb-2.7.1.jar:/opt/openfire/lib/httpclient-4.5.13.jar:/opt/openfire/lib/httpcore-4.4.13.jar:/opt/openfire/lib/i18n-5.0.2.jar:/opt/openfire/lib/imageio-bmp-3.9.4.jar:/opt/openfire/lib/imageio-core-3.9.4.jar:/opt/openfire/lib/istack-commons-runtime-3.0.11.jar:/opt/openfire/lib/j2objc-annotations-2.8.jar:/opt/openfire/lib/jakarta.activation-1.2.2.jar:/opt/openfire/lib/jakarta.annotation-api-1.3.5.jar:/opt/openfire/lib/jakarta.transaction-api-1.3.3.jar:/opt/openfire/lib/jakarta.xml.bind-api-2.3.3.jar:/opt/openfire/lib/jansi-1.18.jar:/opt/openfire/lib/javax.activation-api-1.2.0.jar:/opt/openfire/lib/javax.mail-1.6.2.jar:/opt/openfire/lib/jaxb-api-2.3.1.jar:/opt/openfire/lib/jaxb-runtime-2.3.3.jar:/opt/openfire/lib/jaxen-1.2.0.jar:/opt/openfire/lib/jcip-annotations-1.0.jar:/opt/openfire/lib/jcl-over-slf4j-2.0.9.jar:/opt/openfire/lib/jetty-ee-12.0.24.jar:/opt/openfire/lib/jetty-ee8-annotations-12.0.24.jar:/opt/openfire/lib/jetty-ee8-apache-jsp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-nested-12.0.24.jar:/opt/openfire/lib/jetty-ee8-plus-12.0.24.jar:/opt/openfire/lib/jetty-ee8-security-12.0.24.jar:/opt/openfire/lib/jetty-ee8-servlet-12.0.24.jar:/opt/openfire/lib/jetty-ee8-webapp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-api-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-common-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-servlet-12.0.24.jar:/opt/openfire/lib/jetty-http-12.0.24.jar:/opt/openfire/lib/jetty-io-12.0.24.jar:/opt/openfire/lib/jetty-jmx-12.0.24.jar:/opt/openfire/lib/jetty-jndi-12.0.24.jar:/opt/openfire/lib/jetty-plus-12.0.24.jar:/opt/openfire/lib/jetty-security-12.0.24.jar:/opt/openfire/lib/jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-servlet-api-4.0.6.jar:/opt/openfire/lib/jetty-session-12.0.24.jar:/opt/openfire/lib/jetty-util-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-common-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-server-12.0.24.jar:/opt/openfire/lib/jetty-xml-12.0.24.jar:/opt/openfire/lib/jmdns-1.0.jar:/opt/openfire/lib/jsmpp-2.3.10.jar:/opt/openfire/lib/json-20231013.jar:/opt/openfire/lib/jspecify-1.0.0.jar:/opt/openfire/lib/jsr305-3.0.2.jar:/opt/openfire/lib/jtds-1.3.1.jar:/opt/openfire/lib/jzlib-1.1.3.jar:/opt/openfire/lib/libidn-1.35.jar:/opt/openfire/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/opt/openfire/lib/log4j-api-2.20.0.jar:/opt/openfire/lib/log4j-core-2.20.0.jar:/opt/openfire/lib/log4j-slf4j2-impl-2.20.0.jar:/opt/openfire/lib/mssql-jdbc-9.4.1.jre11.jar:/opt/openfire/lib/mysql-connector-j-8.2.0.jar:/opt/openfire/lib/netty-all-4.1.118.Final.jar:/opt/openfire/lib/netty-buffer-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-haproxy-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http2-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-memcache-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-mqtt-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-redis-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-smtp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-socks-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-stomp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-xml-4.1.118.Final.jar:/opt/openfire/lib/netty-common-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-proxy-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-ssl-ocsp-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-classes-macos-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-epoll-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-kqueue-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-aarch_64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-riscv64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-x86_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-native-unix-common-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-rxtx-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-sctp-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-udt-4.1.118.Final.jar:/opt/openfire/lib/ojdbc11-23.7.0.25.01.jar:/opt/openfire/lib/ons-23.7.0.25.01.jar:/opt/openfire/lib/oraclepki-23.7.0.25.01.jar:/opt/openfire/lib/orai18n-23.7.0.25.01.jar:/opt/openfire/lib/postgresql-42.7.7.jar:/opt/openfire/lib/rsi-23.7.0.25.01.jar:/opt/openfire/lib/shaj-0.5.jar:/opt/openfire/lib/simplefan-23.7.0.25.01.jar:/opt/openfire/lib/sitemesh-2.5.0.jar:/opt/openfire/lib/slf4j-api-2.0.9.jar:/opt/openfire/lib/startup.jar:/opt/openfire/lib/taglibs-standard-impl-1.2.5.jar:/opt/openfire/lib/taglibs-standard-spec-1.2.5.jar:/opt/openfire/lib/tinder-2.1.0.jar:/opt/openfire/lib/txw2-2.3.3.jar:/opt/openfire/lib/ucp-23.7.0.25.01.jar:/opt/openfire/lib/xdb-23.7.0.25.01.jar:/opt/openfire/lib/xmppserver-5.0.2.jar:/opt/openfire/lib/xpp3-1.1.4c.0.jar Starting OpenFire... OpenFire started (PID 1106518) Check logs: tail -f /opt/openfire/logs/nohup.out [root@yfw system]# tail -f /opt/openfire/logs/nohup.out DEBUG: User = $(whoami) DEBUG: Current dir = $(pwd) DEBUG: OPENFIRE_HOME = $OPENFIRE_HOME DEBUG: Java executable = $(which java) openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing) DEBUG: Launching OpenFire... Error: Could not find or load main class org.jivesoftware.openfire.starter.ServerStarter Caused by: java.lang.ClassNotFoundException: org.jivesoftware.openfire.starter.ServerStarter
11-16
[root@yfw ~]# cd /etc/systemd/system [root@yfw system]# #!/bin/bash [root@yfw system]# # deploy-openfire.sh [root@yfw system]# [root@yfw system]# OPENFIRE_HOME=/opt/openfire [root@yfw system]# USER=openfire [root@yfw system]# [root@yfw system]# pkill -f openfire || true [root@yfw system]# [root@yfw system]# rm -rf $OPENFIRE_HOME/embedded-db/* [root@yfw system]# rm -rf $OPENFIRE_HOME/work/* [root@yfw system]# rm -rf $OPENFIRE_HOME/temp/* [root@yfw system]# [root@yfw system]# cat > $OPENFIRE_HOME/conf/openfire.xml << 'EOF' > <?xml version="1.0" encoding="UTF-8"?> > <jive> > <adminConsole> > <port>9090</port> > <securePort>9091</securePort> > </adminConsole> > <locale>en</locale> > <setup>true</setup> > </jive> > EOF [root@yfw system]# [root@yfw system]# chown -R $USER:$USER $OPENFIRE_HOME/{conf,logs,embedded-db} [root@yfw system]# [root@yfw system]# $OPENFIRE_HOME/bin/start.sh Using Java: /usr/lib/jvm/java-17-openjdk/bin/java Java Version: openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing) Classpath: /opt/openfire/lib/activation-1.1.jar:/opt/openfire/lib/apache-el-9.0.107.jar:/opt/openfire/lib/apache-jsp-9.0.107.jar:/opt/openfire/lib/asm-9.8.jar:/opt/openfire/lib/asm-commons-9.8.jar:/opt/openfire/lib/asm-tree-9.8.jar:/opt/openfire/lib/bcpg-jdk18on-1.78.1.jar:/opt/openfire/lib/bcpkix-jdk18on-1.78.1.jar:/opt/openfire/lib/bcprov-jdk18on-1.78.1.jar:/opt/openfire/lib/bcutil-jdk18on-1.78.1.jar:/opt/openfire/lib/caffeine-3.2.0.jar:/opt/openfire/lib/checker-qual-3.33.0.jar:/opt/openfire/lib/common-image-3.9.4.jar:/opt/openfire/lib/common-io-3.9.4.jar:/opt/openfire/lib/common-lang-3.9.4.jar:/opt/openfire/lib/commons-codec-1.15.jar:/opt/openfire/lib/commons-dbcp2-2.9.0.jar:/opt/openfire/lib/commons-ip-math-1.32.jar:/opt/openfire/lib/commons-lang3-3.18.0.jar:/opt/openfire/lib/commons-logging-1.2.jar:/opt/openfire/lib/commons-pool2-2.9.0.jar:/opt/openfire/lib/commons-text-1.10.0.jar:/opt/openfire/lib/dom4j-2.1.4.jar:/opt/openfire/lib/dwr-3.0.2-RELEASE.jar:/opt/openfire/lib/ecj-3.33.0.jar:/opt/openfire/lib/error_prone_annotations-2.18.0.jar:/opt/openfire/lib/failureaccess-1.0.1.jar:/opt/openfire/lib/guava-32.0.1-jre.jar:/opt/openfire/lib/hsqldb-2.7.1.jar:/opt/openfire/lib/httpclient-4.5.13.jar:/opt/openfire/lib/httpcore-4.4.13.jar:/opt/openfire/lib/i18n-5.0.2.jar:/opt/openfire/lib/imageio-bmp-3.9.4.jar:/opt/openfire/lib/imageio-core-3.9.4.jar:/opt/openfire/lib/istack-commons-runtime-3.0.11.jar:/opt/openfire/lib/j2objc-annotations-2.8.jar:/opt/openfire/lib/jakarta.activation-1.2.2.jar:/opt/openfire/lib/jakarta.annotation-api-1.3.5.jar:/opt/openfire/lib/jakarta.transaction-api-1.3.3.jar:/opt/openfire/lib/jakarta.xml.bind-api-2.3.3.jar:/opt/openfire/lib/jansi-1.18.jar:/opt/openfire/lib/javax.activation-api-1.2.0.jar:/opt/openfire/lib/javax.mail-1.6.2.jar:/opt/openfire/lib/jaxb-api-2.3.1.jar:/opt/openfire/lib/jaxb-runtime-2.3.3.jar:/opt/openfire/lib/jaxen-1.2.0.jar:/opt/openfire/lib/jcip-annotations-1.0.jar:/opt/openfire/lib/jcl-over-slf4j-2.0.9.jar:/opt/openfire/lib/jetty-ee-12.0.24.jar:/opt/openfire/lib/jetty-ee8-annotations-12.0.24.jar:/opt/openfire/lib/jetty-ee8-apache-jsp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-nested-12.0.24.jar:/opt/openfire/lib/jetty-ee8-plus-12.0.24.jar:/opt/openfire/lib/jetty-ee8-security-12.0.24.jar:/opt/openfire/lib/jetty-ee8-servlet-12.0.24.jar:/opt/openfire/lib/jetty-ee8-webapp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-api-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-common-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-servlet-12.0.24.jar:/opt/openfire/lib/jetty-http-12.0.24.jar:/opt/openfire/lib/jetty-io-12.0.24.jar:/opt/openfire/lib/jetty-jmx-12.0.24.jar:/opt/openfire/lib/jetty-jndi-12.0.24.jar:/opt/openfire/lib/jetty-plus-12.0.24.jar:/opt/openfire/lib/jetty-security-12.0.24.jar:/opt/openfire/lib/jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-servlet-api-4.0.6.jar:/opt/openfire/lib/jetty-session-12.0.24.jar:/opt/openfire/lib/jetty-util-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-common-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-server-12.0.24.jar:/opt/openfire/lib/jetty-xml-12.0.24.jar:/opt/openfire/lib/jmdns-1.0.jar:/opt/openfire/lib/jsmpp-2.3.10.jar:/opt/openfire/lib/json-20231013.jar:/opt/openfire/lib/jspecify-1.0.0.jar:/opt/openfire/lib/jsr305-3.0.2.jar:/opt/openfire/lib/jtds-1.3.1.jar:/opt/openfire/lib/jzlib-1.1.3.jar:/opt/openfire/lib/libidn-1.35.jar:/opt/openfire/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/opt/openfire/lib/log4j-api-2.20.0.jar:/opt/openfire/lib/log4j-core-2.20.0.jar:/opt/openfire/lib/log4j-slf4j2-impl-2.20.0.jar:/opt/openfire/lib/mssql-jdbc-9.4.1.jre11.jar:/opt/openfire/lib/mysql-connector-j-8.2.0.jar:/opt/openfire/lib/netty-all-4.1.118.Final.jar:/opt/openfire/lib/netty-buffer-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-haproxy-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http2-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-memcache-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-mqtt-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-redis-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-smtp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-socks-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-stomp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-xml-4.1.118.Final.jar:/opt/openfire/lib/netty-common-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-proxy-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-ssl-ocsp-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-classes-macos-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-epoll-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-kqueue-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-aarch_64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-riscv64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-x86_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-native-unix-common-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-rxtx-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-sctp-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-udt-4.1.118.Final.jar:/opt/openfire/lib/ojdbc11-23.7.0.25.01.jar:/opt/openfire/lib/ons-23.7.0.25.01.jar:/opt/openfire/lib/oraclepki-23.7.0.25.01.jar:/opt/openfire/lib/orai18n-23.7.0.25.01.jar:/opt/openfire/lib/postgresql-42.7.7.jar:/opt/openfire/lib/rsi-23.7.0.25.01.jar:/opt/openfire/lib/shaj-0.5.jar:/opt/openfire/lib/simplefan-23.7.0.25.01.jar:/opt/openfire/lib/sitemesh-2.5.0.jar:/opt/openfire/lib/slf4j-api-2.0.9.jar:/opt/openfire/lib/startup.jar:/opt/openfire/lib/taglibs-standard-impl-1.2.5.jar:/opt/openfire/lib/taglibs-standard-spec-1.2.5.jar:/opt/openfire/lib/tinder-2.1.0.jar:/opt/openfire/lib/txw2-2.3.3.jar:/opt/openfire/lib/ucp-23.7.0.25.01.jar:/opt/openfire/lib/xdb-23.7.0.25.01.jar:/opt/openfire/lib/xmppserver-5.0.2.jar:/opt/openfire/lib/xpp3-1.1.4c.0.jar Starting OpenFire... OpenFire started (PID 1108946) Check logs: tail -f /opt/openfire/logs/nohup.out [root@yfw system]# echo "查看日志: tail -f $OPENFIRE_HOME/logs/nohup.out" 查看日志: tail -f /opt/openfire/logs/nohup.out [root@yfw system]# tail -f /opt/openfire/logs/nohup.out at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) at java.base/java.lang.Class.newInstance(Class.java:645) at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Check JDBC properties; data source was not be initialised at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ... 11 more Error starting the server. Please check the log files for more information.
11-16
[root@yfw ~]# cd /etc/systemd/system [root@yfw system]# cat /opt/openfire/resources/database.properties database.defaultProvider.driver=com.mysql.jdbc.Driver database.defaultProvider.serverURL=jdbc:mysql://localhost:3306/openfire_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&useSSL=false database.defaultProvider.username=openfire database.defaultProvider.password=openfire_password_123 database.defaultProvider.testSQL=SELECT 1 database.defaultProvider.dialect=org.jivesoftware.database.MySQLDialect [root@yfw system]# ls -l /opt/openfire/resources/database.properties -rw-r--r-- 1 openfire openfire 453 Nov 15 13:41 /opt/openfire/resources/database.properties [root@yfw system]# ls -l /opt/openfire/resources/database.properties -rw-r--r-- 1 openfire openfire 453 Nov 15 13:41 /opt/openfire/resources/database.properties [root@yfw system]# # 停止服务 [root@yfw system]# pkill -f openfire [root@yfw system]# [root@yfw system]# # 删除工作目录(包含数据库连接池缓存) [root@yfw system]# sudo rm -rf /opt/openfire/work/* [root@yfw system]# [root@yfw system]# # 删除临时文件 [root@yfw system]# sudo rm -rf /opt/openfire/temp/* [root@yfw system]# [root@yfw system]# # 删除现有配置(强制进入 setup 流程) [root@yfw system]# sudo rm -f /opt/openfire/conf/*.xml [root@yfw system]# sudo -u openfire /opt/openfire/bin/start.sh Using Java: /usr/lib/jvm/java-17-openjdk/bin/java Java Version: openjdk version "17.0.1" 2021-10-19 LTS OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS) OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing) Classpath: /opt/openfire/lib/activation-1.1.jar:/opt/openfire/lib/apache-el-9.0.107.jar:/opt/openfire/lib/apache-jsp-9.0.107.jar:/opt/openfire/lib/asm-9.8.jar:/opt/openfire/lib/asm-commons-9.8.jar:/opt/openfire/lib/asm-tree-9.8.jar:/opt/openfire/lib/bcpg-jdk18on-1.78.1.jar:/opt/openfire/lib/bcpkix-jdk18on-1.78.1.jar:/opt/openfire/lib/bcprov-jdk18on-1.78.1.jar:/opt/openfire/lib/bcutil-jdk18on-1.78.1.jar:/opt/openfire/lib/caffeine-3.2.0.jar:/opt/openfire/lib/checker-qual-3.33.0.jar:/opt/openfire/lib/common-image-3.9.4.jar:/opt/openfire/lib/common-io-3.9.4.jar:/opt/openfire/lib/common-lang-3.9.4.jar:/opt/openfire/lib/commons-codec-1.15.jar:/opt/openfire/lib/commons-dbcp2-2.9.0.jar:/opt/openfire/lib/commons-ip-math-1.32.jar:/opt/openfire/lib/commons-lang3-3.18.0.jar:/opt/openfire/lib/commons-logging-1.2.jar:/opt/openfire/lib/commons-pool2-2.9.0.jar:/opt/openfire/lib/commons-text-1.10.0.jar:/opt/openfire/lib/dom4j-2.1.4.jar:/opt/openfire/lib/dwr-3.0.2-RELEASE.jar:/opt/openfire/lib/ecj-3.33.0.jar:/opt/openfire/lib/error_prone_annotations-2.18.0.jar:/opt/openfire/lib/failureaccess-1.0.1.jar:/opt/openfire/lib/guava-32.0.1-jre.jar:/opt/openfire/lib/hsqldb-2.7.1.jar:/opt/openfire/lib/httpclient-4.5.13.jar:/opt/openfire/lib/httpcore-4.4.13.jar:/opt/openfire/lib/i18n-5.0.2.jar:/opt/openfire/lib/imageio-bmp-3.9.4.jar:/opt/openfire/lib/imageio-core-3.9.4.jar:/opt/openfire/lib/istack-commons-runtime-3.0.11.jar:/opt/openfire/lib/j2objc-annotations-2.8.jar:/opt/openfire/lib/jakarta.activation-1.2.2.jar:/opt/openfire/lib/jakarta.annotation-api-1.3.5.jar:/opt/openfire/lib/jakarta.transaction-api-1.3.3.jar:/opt/openfire/lib/jakarta.xml.bind-api-2.3.3.jar:/opt/openfire/lib/jansi-1.18.jar:/opt/openfire/lib/javax.activation-api-1.2.0.jar:/opt/openfire/lib/javax.mail-1.6.2.jar:/opt/openfire/lib/jaxb-api-2.3.1.jar:/opt/openfire/lib/jaxb-runtime-2.3.3.jar:/opt/openfire/lib/jaxen-1.2.0.jar:/opt/openfire/lib/jcip-annotations-1.0.jar:/opt/openfire/lib/jcl-over-slf4j-2.0.9.jar:/opt/openfire/lib/jetty-ee-12.0.24.jar:/opt/openfire/lib/jetty-ee8-annotations-12.0.24.jar:/opt/openfire/lib/jetty-ee8-apache-jsp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-nested-12.0.24.jar:/opt/openfire/lib/jetty-ee8-plus-12.0.24.jar:/opt/openfire/lib/jetty-ee8-security-12.0.24.jar:/opt/openfire/lib/jetty-ee8-servlet-12.0.24.jar:/opt/openfire/lib/jetty-ee8-webapp-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-api-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-common-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-ee8-websocket-servlet-12.0.24.jar:/opt/openfire/lib/jetty-http-12.0.24.jar:/opt/openfire/lib/jetty-io-12.0.24.jar:/opt/openfire/lib/jetty-jmx-12.0.24.jar:/opt/openfire/lib/jetty-jndi-12.0.24.jar:/opt/openfire/lib/jetty-plus-12.0.24.jar:/opt/openfire/lib/jetty-security-12.0.24.jar:/opt/openfire/lib/jetty-server-12.0.24.jar:/opt/openfire/lib/jetty-servlet-api-4.0.6.jar:/opt/openfire/lib/jetty-session-12.0.24.jar:/opt/openfire/lib/jetty-util-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-common-12.0.24.jar:/opt/openfire/lib/jetty-websocket-core-server-12.0.24.jar:/opt/openfire/lib/jetty-xml-12.0.24.jar:/opt/openfire/lib/jmdns-1.0.jar:/opt/openfire/lib/jsmpp-2.3.10.jar:/opt/openfire/lib/json-20231013.jar:/opt/openfire/lib/jspecify-1.0.0.jar:/opt/openfire/lib/jsr305-3.0.2.jar:/opt/openfire/lib/jtds-1.3.1.jar:/opt/openfire/lib/jzlib-1.1.3.jar:/opt/openfire/lib/libidn-1.35.jar:/opt/openfire/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/opt/openfire/lib/log4j-api-2.20.0.jar:/opt/openfire/lib/log4j-core-2.20.0.jar:/opt/openfire/lib/log4j-slf4j2-impl-2.20.0.jar:/opt/openfire/lib/mssql-jdbc-9.4.1.jre11.jar:/opt/openfire/lib/mysql-connector-java-5.1.49.jar:/opt/openfire/lib/netty-all-4.1.118.Final.jar:/opt/openfire/lib/netty-buffer-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-haproxy-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http2-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-http-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-memcache-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-mqtt-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-redis-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-smtp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-socks-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-stomp-4.1.118.Final.jar:/opt/openfire/lib/netty-codec-xml-4.1.118.Final.jar:/opt/openfire/lib/netty-common-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-proxy-4.1.118.Final.jar:/opt/openfire/lib/netty-handler-ssl-ocsp-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-classes-macos-4.1.118.Final.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-resolver-dns-native-macos-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-epoll-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-classes-kqueue-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-aarch_64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-riscv64.jar:/opt/openfire/lib/netty-transport-native-epoll-4.1.118.Final-linux-x86_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-aarch_64.jar:/opt/openfire/lib/netty-transport-native-kqueue-4.1.118.Final-osx-x86_64.jar:/opt/openfire/lib/netty-transport-native-unix-common-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-rxtx-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-sctp-4.1.118.Final.jar:/opt/openfire/lib/netty-transport-udt-4.1.118.Final.jar:/opt/openfire/lib/ojdbc11-23.7.0.25.01.jar:/opt/openfire/lib/ons-23.7.0.25.01.jar:/opt/openfire/lib/oraclepki-23.7.0.25.01.jar:/opt/openfire/lib/orai18n-23.7.0.25.01.jar:/opt/openfire/lib/postgresql-42.7.7.jar:/opt/openfire/lib/rsi-23.7.0.25.01.jar:/opt/openfire/lib/shaj-0.5.jar:/opt/openfire/lib/simplefan-23.7.0.25.01.jar:/opt/openfire/lib/sitemesh-2.5.0.jar:/opt/openfire/lib/slf4j-api-2.0.9.jar:/opt/openfire/lib/startup.jar:/opt/openfire/lib/taglibs-standard-impl-1.2.5.jar:/opt/openfire/lib/taglibs-standard-spec-1.2.5.jar:/opt/openfire/lib/tinder-2.1.0.jar:/opt/openfire/lib/txw2-2.3.3.jar:/opt/openfire/lib/ucp-23.7.0.25.01.jar:/opt/openfire/lib/xdb-23.7.0.25.01.jar:/opt/openfire/lib/xmppserver-5.0.2.jar:/opt/openfire/lib/xpp3-1.1.4c.0.jar Starting OpenFire... /opt/openfire/bin/start.sh: line 53: /opt/openfire/logs/openfire.pid: Permission denied OpenFire started (PID 1135236) Check logs: tail -f /opt/openfire/logs/nohup.out [root@yfw system]# tail -f /opt/openfire/logs/openfire.log at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] 2025.11.15 13:41:42.370 WARN [main]: org.jivesoftware.util.JiveGlobals - Default properties have not been loaded from file. Using a non-persisting dummy properties object.
11-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值