Cannot get Xalan to run any example

旧巷老猫 提交于 2019-12-11 13:13:38

问题


I downloaded Xalan-Java Version 2.7.1, unpack it, and then set the PATH for java and CLASSPATH for xalan:

set path=%PATH%;c:\Program Files\Java\jre6\bin

set classpath=%CLASSPATH%;c:\Xalan\

(I also tried setting the classpath only for xalan.jar, xercesImpl.jar, xml-apis.jar)

When testing a simple Hello World example (or any other example):

java org.apache.xalan.xslt.Process -in hello.xml -xsl hello.xsl -out hello.html

I always get this:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xalan/xslt
/Process
Caused by: java.lang.ClassNotFoundException: org.apache.xalan.xslt.Process
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.apache.xalan.xslt.Process.  Program will exit

What is the problem ? Someone has an idee ?

Thanks.


回答1:


Ok, this is what I did to make it work, finally:

Copy the xalan.jar to the c:\Program Files (x86)\Java\jre6\lib\
Running the file like this from command line:

java -classpath "c:\Program Files (x86)\Java\jre6\
lib\xalan.jar";"c:\xalan-j_2_7_1\serializer.jar" org.apache.xalan.xslt.Process -
in hello.xml -xsl hello.xsl

Without serializer.jar it doesn't work !




回答2:


Serializer should not be needed in all cases. For example, if you XSLT was making use of pipeDocument then it would be needed.

This error points to not finding "org.apache.xalan.xslt.Process" of xalan.jar. Recheck your classpath. Exclude hello.xml and hello.xsl to avoid them muddying the water. If your classpath is correct, this alone

java org.apache.xalan.xslt.Process

will provide output (Xalan-J command line options).



来源:https://stackoverflow.com/questions/8196178/cannot-get-xalan-to-run-any-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!