欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MINA的第一个例子终于能运行了__2

程序员文章站 2024-01-13 09:52:34
...
MINA的第一个例子终于能运行了__1

二、
将mina包换成1.0,并引入mina-filter-ssl-1.0.0.jar后再执行,报错
java.lang.NoClassDefFoundError: edu/emory/mathcs/backport/java/util/concurrent/Executor

原来是mina1.0硬引入了别的类文件
import edu.emory.mathcs.backport.java.util.concurrent.Executor;

于是乎我就把整个edu.emory.mathcs.backport.java.util包给down了下来,并引入工程echoserver(mina1.0中的example)。但是里面的关于assert的代码全部报错,忽略这个错误,执行程序,正确执行,但是后台报错(估计由于那个assert的问题引起的)
9109 [AnonymousIoService-1] INFO org.apache.mina.example.echoserver.EchoProtocolHandler - [/127.0.0.1:2306] OPENED
java.lang.Error: Unresolved compilation problems: 
	assert cannot be resolved to a type
	Duplicate local variable state
	Syntax error on token "!=", = expected
	assert cannot be resolved to a type
	Syntax error on token "==", = expected

	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.workerDone(ThreadPoolExecutor.java:544)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:679)
	at java.lang.Thread.run(Thread.java:534)
11328 [AnonymousIoService-2] INFO org.apache.mina.example.echoserver.EchoProtocolHandler - [/127.0.0.1:2306] RECEIVED: DirectBuffer[pos=0 lim=9 cap=2048: 7A 68 61 6E 67 6C 65 0D 0A]
11328 [AnonymousIoService-2] INFO org.apache.mina.example.echoserver.EchoProtocolHandler - [/127.0.0.1:2306] WRITE: DirectBuffer[pos=0 lim=9 cap=16: 7A 68 61 6E 67 6C 65 0D 0A]
java.lang.Error: Unresolved compilation problems: 
	assert cannot be resolved to a type
	Duplicate local variable state
	Syntax error on token "!=", = expected
	assert cannot be resolved to a type
	Syntax error on token "==", = expected

	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.workerDone(ThreadPoolExecutor.java:544)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:679)
	at java.lang.Thread.run(Thread.java:534)
11328 [AnonymousIoService-3] INFO org.apache.mina.example.echoserver.EchoProtocolHandler - [/127.0.0.1:2306] SENT: DirectBuffer[pos=0 lim=9 cap=16: 7A 68 61 6E 67 6C 65 0D 0A]
java.lang.Error: Unresolved compilation problems: 
	assert cannot be resolved to a type
	Duplicate local variable state
	Syntax error on token "!=", = expected
	assert cannot be resolved to a type
	Syntax error on token "==", = expected

	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.workerDone(ThreadPoolExecutor.java:544)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:679)
	at java.lang.Thread.run(Thread.java:534)
15797 [AnonymousIoService-4] INFO org.apache.mina.example.echoserver.EchoProtocolHandler - [/127.0.0.1:2306] CLOSED
java.lang.Error: Unresolved compilation problems: 
	assert cannot be resolved to a type
	Duplicate local variable state
	Syntax error on token "!=", = expected
	assert cannot be resolved to a type
	Syntax error on token "==", = expected

	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.workerDone(ThreadPoolExecutor.java:544)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:679)
	at java.lang.Thread.run(Thread.java:534)


这个问题怎么解决啊??


找到了,解决办法:
JDK1.4版新加入的assertion机制(关键词:assert),由于JDK1.4编译器
预设是兼容1.3,所以要使用assert必须在编译时加上-source 1.4的参数.

C:\>javac -source 1.4 XXX.java
执行时则必须加-ea 或-enableassertions参数启动。

C:\>java -ea XXX
如要在Eclipse中使用assertion机制,请作以下设定:
设定一:(编译设定)
Windows->Preferance->Java->Compiler->Compliance and Classfiles
页面。将..JDK Compliance level->Compiler compliance level调成1.4。

设定二:(执行设定)
Run->Run->(x)=Arguments页面,在VM arguments加入-da参数,按下
Run button便可看到启动assertion后的执行结果。
(Eclipse 2.1.3 release + assertion测试)
<assert判别为false,所以show出AssertionError>

新版(m8+)的eclipse可以设vm arguments
另外提供一种设法,是在eclipse启动时加入vm arguments(跟加大eclipse预设内存大小的方式一样)
这样就不用每次run都得需去设vm arguments