Cannot get Xalan to run any example

2019-07-31 18:49发布

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.

标签: xslt xalan
2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-31 19:07

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).

查看更多
Lonely孤独者°
3楼-- · 2019-07-31 19:21

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 !

查看更多
登录 后发表回答