编译和运行openfire记录

错误1:使用ant编译的时候出现错误 UnsupportedClassVersionError:     Unsupported major.minor version 51.0

原因:因为jdk的版本是1.7,而jre的版本比jdk低。

解决方法:JAVA_HOME设置为jre的版本的位置。

另外需要正确配置java环境。

配置java环境方法如下:(方法转自http://zhidao.baidu.com/question/350104872.html)

1.打开我的电脑--属性--高级--环境变量 
2.新建系统变量JAVA_HOME 和CLASSPATH 
变量名:JAVA_HOME 
变量值:C:\Program Files\Java\jdk1.7.0
变量名:CLASSPATH 
变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;

3. 选择“系统变量”中变量名为“Path”的环境变量,双击该变量,把JDK安装路径中bin目录的绝对路径,添加到Path变量的值中,并使用半角的分号和已有的路径进行分隔。 
变量名:Path 
变量值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
这是java的环境配置,配置完成后直接启动eclipse,它会自动完成java环境的配置
2 Unable to find a javac compiler
  
  
  
  
原因:找不到jdk下的tools.jar
在   window--preferences---Ant   ---runtime--Classpath 添加 %java_home%/lib/下的tools.jar
具体是项目属性》Java Build Path-》Libraries-》Add external jars选择%java_home%/lib/tools.jar.
3 目录:/openfire_src/src/plugins/sip/src/java 报错说 SipCommRouter.java和SipManager.java 这两个类没有实现抽象方法和完成异常处理
解决方法:用快捷键ctrl+1,自动修复没有实现的抽象类。对于异常,用eclipse自动添加异常出来。添加后为
try {             serverTransaction.sendResponse(notImplemented);         }         catch (SipException ex) {             fireCommunicationsError(new CommunicationsException(                     "Failed to create a NOT_IMPLEMENTED response to a "                             + request.getMethod() + " request!", ex));         } catch (InvalidArgumentException e) {  // TODO Auto-generated catch block  e.printStackTrace();  } 
 
4 运行的时候出现错误:
Java HotSpot(TM) Client VM warning: MaxNewSize (262144k) is equal to or greater than the entire heap (262144k).  A new generation size of 262080k will be used. log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: “E:\MobileDev\openfire_src\target\openfire\logs\debug.log (文件名、目录名或卷标语法不正确。)  at java.io.FileOutputStream.openAppend(Native Method)  at java.io.FileOutputStream.<init>(Unknown Source)  at java.io.FileOutputStream.<init>(Unknown Source)  at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)  at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)  at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)  at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)  at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:220)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)  at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)  at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)  at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)  at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)  at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)  at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)  at org.jivesoftware.util.Log.<clinit>(Log.java:48)  at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:104)  at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:58) log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: “E:\MobileDev\openfire_src\target\openfire\logs\info.log (文件名、目录名或卷标语法不正确。)  at java.io.FileOutputStream.openAppend(Native Method)  at java.io.FileOutputStream.<init>(Unknown Source)  at java.io.FileOutputStream.<init>(Unknown Source)  at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)  at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)  at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)  at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)  at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:220)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)  at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)  at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)  at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)  at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)  at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)  at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)  at org.jivesoftware.util.Log.<clinit>(Log.java:48)  at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:104)  at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:58) log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: “E:\MobileDev\openfire_src\target\openfire\logs\warn.log (文件名、目录名或卷标语法不正确。)  at java.io.FileOutputStream.openAppend(Native Method)  at java.io.FileOutputStream.<init>(Unknown Source)  at java.io.FileOutputStream.<init>(Unknown Source)  at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)  at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)  at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)  at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)  at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:220)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)  at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)  at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)  at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)  at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)  at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)  at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)  at org.jivesoftware.util.Log.<clinit>(Log.java:48)  at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:104)  at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:58) log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: “E:\MobileDev\openfire_src\target\openfire\logs\error.log (文件名、目录名或卷标语法不正确。)  at java.io.FileOutputStream.openAppend(Native Method)  at java.io.FileOutputStream.<init>(Unknown Source)  at java.io.FileOutputStream.<init>(Unknown Source)  at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)  at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)  at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)  at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)  at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:220)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)  at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)  at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)  at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)  at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)  at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)  at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)  at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)  at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:73)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)  at org.jivesoftware.util.Log.<clinit>(Log.java:48)  at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:104)  at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:58) Could not locate home java.io.FileNotFoundException  at org.jivesoftware.openfire.XMPPServer.locateOpenfire(XMPPServer.java:873)  at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:347)  at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:468)  at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:212)  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)  at java.lang.reflect.Constructor.newInstance(Unknown Source)  at java.lang.Class.newInstance0(Unknown Source)  at java.lang.Class.newInstance(Unknown Source)  at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:113)  at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:58) 启动服务器时出错。请检查日志文件以获取更多信息。 Critical Error! The home directory has not been configured,  which will prevent the application from working correctly. 尝试手动添加了error.log文件也不管事。
后来看最后一个提示是
Critical Error! The home directory has not been configured,网上查的结果是openfire_Home 没有正确设置。我记得我添加了啊。后来对比了一看,才发现自己少写一个引号。写成了-DopenfireHome=${workspace_loc:openfire_src}/target/openfire",在等号后面少写了一个引号,怪不得找不到openfireHome呢!看来晚上要是困了的话最好还是休息下。这个小问题耽误我一两个小时。囧!
然后运行,就正常了。
控制台输出:
Openfire 3.8.1 [Apr 4, 2013 1:33:46 PM] Admin console listening at http://127.0.0.1:9090 
哈哈,现在可以去访问http://127.0.0.1:9090了
注:可以直接在openfire项目右键点击run。网上有资料说不能点击run,否则出现找不到openfireHome)会报    'Critical Error! The home directory has not been configured, ' ,其实不会报错的。网上的东西可能只适合发帖人,不适合自己。对网上的东西要半信半疑哈。


5 安装openfire时候的错误

使用http://127.0.0.1:9090提示新安装。依次下一步到选择数据库,选择mysql,但是却出错了。查看E:\MobileDev\openfire_src\target\openfire\logs\error.log 提示说

org.jivesoftware.database.SchemaManager - SchemaManager: Failed to execute SQL:
 CREATE TABLE ofRoster (   rosterID              BIGINT          NOT NULL,   username              VARCHAR(64)     NOT NULL,   jid                   VARCHAR(1024)   NOT NULL,   sub                   TINYINT         NOT NULL,   ask                   TINYINT         NOT NULL,   recv                  TINYINT         NOT NULL,   nick                  VARCHAR(255),   PRIMARY KEY (rosterID),   INDEX ofRoster_unameid_idx (username),   INDEX ofRoster_jid_idx (jid) );
2013.04.04 21:00:16 org.jivesoftware.database.SchemaManager - Specified key was too long; max key length is 767 bytes
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)

搜索的原因是MySQL的varchar索引只支持不超过768个字节。如果编码是utf-8的,由于utf-8是三个字节表示一个字符,所以支持768/3=256个字符。另GBK是双字节。所以只需要更改varchar的长度为255即可。方法是修改E:\MobileDev\openfire_src\target\openfire\resources\database\openfire_mysql.sql文件,把其中的

CREATE TABLE ofRoster (
  rosterID              BIGINT          NOT NULL,
  username              VARCHAR(64)     NOT NULL,
  jid                   VARCHAR(1024)   NOT NULL,
  sub                   TINYINT         NOT NULL,
  ask                   TINYINT         NOT NULL,
  recv                  TINYINT         NOT NULL,
  nick                  VARCHAR(255),
  PRIMARY KEY (rosterID),
  INDEX ofRoster_unameid_idx (username),
  INDEX ofRoster_jid_idx (jid)
);中的 jid                   VARCHAR(1024) 改为 jid                   VARCHAR(255) 即可!

注意:修改后很可能还是不能连接数据库,是因为上次操作已经创建了表。只需要把数据库中的所有表删除然后重新连接就可以了。

你可能感兴趣的:(编译和运行openfire记录)