一、javamail 异常
1. java.lang.NoClassDefFoundError: javax/mail/Authenticator 表示没找到mail.jar等javamail所需的依赖库,将这些依赖文件放到tomcat自带库文件夹或部署项目的WEB-INF/lib目录下即可。
2. Tomcat: java.lang.ClassCastException: javax.mail.Session 这个异常说明Tomcat自带库和webapp项目库里均有mail.jar和activation.jar依赖文件,删除两者之一即可。
官方说明:
Although Tomcat 5.5 supports J2EE, you still need to get the activation.jar (Java Activation Framework) and mail.jar (JavaMail) files from Sun's site.
JavaMail API
Java Activation Framework (JAF)
The ClassCastException is most likely being thrown being thrown because you have either of those two libraries in a WEB-INF/lib directory within one of your applications. To avoid this problem, make sure that you only have the libraries in the $TOMCAT_HOME/common/lib/ directory.
Also be sure to read the JNDI resources page on the Apache Tomcat site: http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html
二、hibernate异常
1. org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect). Could not synchronize database state with session
说明操作的对象应用了乐观锁;version
错误原因:当在进行操作时,当前version版本与DB中version版本不一致:
A:另外有人对此记录进行了相似操作;
B:自己操作有误:。
例如通过编辑页面来修改一条记录时,传回来的form对象中version为空,然后又指导这些form中的值copy到相应的实体对象中,此时此实体对象中的version也为空,当update时version不一致就会出错。
解决:
A. 用form传数据时把version也传过来
B. 从DB中把version查出来赋给实体对象再更新
三、开发工具
1. eclipse中jboss启动时提示 50 seconds. 超时
解决方法1:双击servers中的”JBoss v4.2 at localhost”,在timeout选项中调大start时间就可以了。
解决方法2:eclipse中jboss启动时提示
Server JBoss v4.2 at localhost was unable to start within 50 seconds.
If the server requires more time, try increasing the timeout in the server editor.
解决办法,修改
workspace\.metadata\.plugins\org.eclipse.wst.server.core\servers.xml
<server auto-publish-setting="1" hostname="localhost" id="JBoss v4.2 at localhost" name="JBoss v4.2 at localhost" runtime-id="JBoss v4.2" server-type="org.eclipse.jst.server.generic.jboss42" server-type-id="org.eclipse.jst.server.generic.jboss42" start-timeout="50" stop-timeout="15" timestamp="7">
把 start-timeout="50" 改为 start-timeout="500000"
重启eclipse就可以了
2. eclipse 安装jboss tools 重启报错(Juno Service Release 2, Jboss4.2.3.GA)
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: Cannot cast org.eclipse.core.commands.CommandManager to org.eclipse.core.commands.CommandManager
...
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.ClassCastException: Cannot cast org.eclipse.core.commands.CommandManager to org.eclipse.core.commands.CommandManager
... 27 more
...
org.eclipse.e4.core.di.InjectionException: Unable to process "CommandProcessingAddon.commandService": no actual value was found for the argument "ECommandService".
...
org.eclipse.e4.core.di.InjectionException: Unable to process "BindingProcessingAddon.commandService": no actual value was found for the argument "ECommandService".
...
java.lang.NullPointerException
at org.eclipse.e4.ui.internal.workbench.E4Workbench.processHierarchy(E4Workbench.java:172)
...
解决办法:
Problems with Eclipse's workspaces tend to be painful. Try going to your installation path, and find configuration\org.eclipse.equinox.simpleconfigurator\.
Open bundle.info and then delete the lower version of duplicate entry for org.eclipse.core.commands. Then restart the eclipse with the -clean option.
四、apache httpd常见错误
1. Starting httpd: httpd: apr_sockaddr_info_get() failed for MYHOST
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName.
这个问题应该是没有在 /etc/httpd/conf/httpd.conf 中设定 ServerName 所以它会用主机上的名称来取代,首先会去找 /etc/hosts 中有没有主机的定义。
所以要解决这个问题可以设定 ServerName 或者在 /etc/hosts 中填入自己的主机名 MYHOST,像这样:
>vi /etc/hosts
127.0.0.1 localhost.localdomain localhost MYHOST
2. 登陆时提示:“缺少 mysqli 扩展。请检查 PHP 配置
请检查 PHP 配置,查看php.ini 文件,发现没有mysql扩展,所以需要安装php-mysql
3. The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.
yum install php-mbstring
4. The mcrypt extension is missing. Please check your PHP configuration.
I installed php 5.3 and some modules using
yum install php53-{module-name}
But mcrypt did not work.
I searched like this:
yum list php* | grep mcry
The only package that came up was
php-mcrypt.x86-64 5.1.6-15.e15.centos.1 extras
I have the same exact problem with mhash. The results for php are even more confusing.
I know this is probably a dumb question, but any help would be appreciated. I am used to Ubuntu's simple "apt-get install" and everything works. CentOS seems to be a lot more detail oriented.
The package you are looking for exists! All you need to do is
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install php-mcrypt
5. 严重: Unable to set localhost. This prevents creation of a GUID.
Cause was: gom.localdomain: gom.localdomain
java.net.UnknownHostException: gom.localdomain: gom.localdomain
at java.net.InetAddress.getLocalHost(InetAddress.java:1426)
at net.sf.ehcache.Cache.<clinit>(Cache.java:199)
修改/etc/hosts文件。在其中加上一条(对应改成你自己的机器名称),重启后问题解决。
127.0.0.1 gom.localdomain
五、J2EE常见错误
1. uploadify与struts2 整合时遇到的异常
刚开始以为form没设置enctype="multipart/form-data"属性,修改uplaodify源码,还是老问题,后来又以为是uploadify的flash SessionID 与Server不同所致,于是回传SessionId,还是不能解决问题。在无数次尝试之后发现是名称问题,真他妈郁闷呀….
File名称不能命名为upload,我该为myupload之后,一切都正常了…
当时项目要求用的是struts2 v2.3.4的版本,不知是不是这个问题
JSP
<input licencePhotoname="upload" type="file" />
Action源码
private File upload;//和HTML中input标记name同名
private String uploadFileName;//Struts2拦截器获得的文件名
private String uploadContentType;
报的错误如下:
[com.opensymphony.xwork2.ognl.OgnlValueStack]-[WARN] Error setting expression 'Upload' with value '[Ljava.lang.String;@ff5d3f'
ognl.MethodFailedException: Method "setUpload" failed for object
com.ttni.haveFun.Action.upload.FileUploadAction@1e229be[java.lang.NoSuchMethodException:
com.ttni.haveFun.Action.upload.FileUploadAction.setUpload([Ljava.lang.String;)]
......
Cannot create type class java.io.File from value Submit Query - [unknown location]
....
2. log4j:WARN Error initializing output writer.
log4j:WARN Unsupported encoding?
把 log4j.appender.stdout.Encoding=UTF-8 这一行去掉就可以了
3. Syntax error on line 292 of /etc/httpd/conf/httpd.conf: DocumentRoot must be a directory
解决办法:
The link you posted under "Other websites" highlights the root cause of your problem, which is Selinux.
Unless the server is part of a super secure environment, I would simply disable Selinux.
On RedHat / CentOS / Scientific Linux this can easily be done by editing /etc/sysconfig/selinux - find the parameter "selinux" and change the option "enforcing" to "disabled" as per the extract below:
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
It is probably wise to reboot the server after making this change.