gpt4 book ai didi

java - 在 Tomcat 7 中部署的 war 在 Linux 上的行为与在 Windows 上的行为不同

转载 作者:太空狗 更新时间:2023-10-29 12:42:49 26 4
gpt4 key购买 nike

我什至不确定如何问这个问题,但是:我有两台服务器,一台是运行 Ubuntu 13.10 的 Linux VM,另一台是 Windows 7。我在两者上都运行了 Apache Tomcat 7.0.42。我在两者上都运行了 Java 1.8.0_66。我已经将应用程序构建为 .war 文件,并在两个 Tomcat 中部署了相同的 .war。此 war 文件读取 xml 文件并使用 xsl 文件对其执行转换。我在两个安装中使用完全相同的文件作为输入 - 所有文件都放置在 Tomcat 环境中的相同文件夹结构中。

问题:生成的转换文件在每台机器上都不同。两个生成的版本都是格式正确的,但它们包含不同的内容。差别不大,但是一个(在 Linux 上生成的那个)比 Windows 有更多的元素。

鉴于安装和数据源是相同的,是否有人对这种不同行为的来源有什么建议?

需要注意一点:在Windows上运行.war生成的结果是预期的结果。

这是执行转换的方法,在 Windows 和 Linux 中给出不同的结果(在每个上使用完全相同的文件。)

// Performs an XSLT transformation on the source stream using the transform stream and writes the result to
// an output file stream.
//
protected OutputStream performTransform(InputStream source, InputStream transform, OutputStream outputFile) {

// Force the use of Saxon for the transformer
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
Transformer transformer;
logger.info("Perform Transform: " + source + " using " + transform + " to " + outputFile);
try {
try {
transformer = factory.newTransformer(new StreamSource(transform));
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");

try {
transformer.transform(new StreamSource(source), new StreamResult(outputFile));
} catch (TransformerException e) {
logger.error("Transform Exception ", e);
}
} catch (TransformerConfigurationException e) {
logger.error("Transform Configurtion Exception ", e);
}

try {
outputFile.close();
} catch (IOException e) {
logger.error("Exception closing output stream ", e);
}
} catch (Exception e) {
logger.error("Catchall Exception performing transform ", e);
} finally {
try {
outputFile.close();
} catch (IOException e) {
logger.error("Exception closing output stream a second time ", e);
}
}

return outputFile;
}

最佳答案

我相信this可以为您指明正确的方向。基本上,它是说确保您执行相同的编码(在这种情况下最好使用 UTF-8)来标准化输出。 Linux 和 Windows 有不同的换行符(分别为\n 和\r\n),这也可能导致结果文件之间的空格差异(这可能会破坏转换,因为 position() function is confused )。

关于java - 在 Tomcat 7 中部署的 war 在 Linux 上的行为与在 Windows 上的行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36070057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com