Có vẻ như tôi đã làm điều này một lần trong quá khứ, nhưng tôi không thể tìm thấy bất kỳ tham chiếu nào đến những gì tôi đã làm để làm cho nó hoạt động.Cách chỉ định triển khai JAXB cụ thể?
Tôi có một ứng dụng web mà tôi muốn chỉ định một triển khai JAXB khác với ứng dụng được cung cấp bởi máy chủ web/jre của tôi. Tôi đã tải xuống phần tạo tác thích hợp từ maven và thấy rằng bình được đóng gói đúng cách trong chiến tranh của tôi, tuy nhiên, khi tôi khởi động ứng dụng web của mình, tôi thấy rằng nó vẫn đang sử dụng triển khai JRE kèm theo.
Tôi mơ hồ nhớ điều gì đó về tệp thuộc tính mà tôi có thể định cấu hình, nhưng không thể tìm thấy tham chiếu đến cách cấu hình nó. Hơn nữa, nếu việc thực hiện tôi muốn sử dụng là cùng một (chỉ là một phiên bản mới hơn), các tên lớp sẽ giống như được đóng gói trong JRE. Làm cách nào tôi có thể chỉ định rằng tôi muốn sử dụng các gói được nhóm trong WAR của tôi?
EDIT
Tôi hiện đang chạy trên JBoss 7.0.2, với Oracle JDK 1.6_0_27, JAXB RI mà đi kèm với JRE (Tôi nghĩ rằng đó là v2.1). Tôi đang cố gắng nâng cấp lên JAXB RI 2.2.5 (được tìm thấy trên MvnRepository).
Tôi đã thực hiện xong việc đào thêm một chút sáng nay, và nhận thấy một thông báo lỗi lạ trong nhật ký của tôi:
09:43:18,325 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry jaxb-api.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
09:43:18,325 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry activation.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
09:43:18,326 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry jsr173_1.0_api.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
09:43:18,326 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry jaxb1-impl.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
Mà tôi thấy rất lạ. Tôi không chắc nơi nó tìm thấy thông tin đó. Nghiên cứu thêm một chút đã tìm thấy dòng này trong MANIFEST.MF:
Class-Path: jaxb-api.jar activation.jar jsr173_1.0_api.jar jaxb1-impl.jar
Vì vậy, bây giờ tôi thậm chí còn bối rối hơn bao giờ hết. Nó sẽ xuất hiện rằng việc thực hiện jaxb phụ thuộc vào api, kích hoạt, jsr và jaxb1 jars thực hiện. Nhưng chúng không được liệt kê trong jaxb pom. Một chút đào trực tuyến tìm thấy tôi this link mà thảo luận về cách sử dụng JAXB 2.2 trong một môi trường Java6SE. Thật không may, điều này dường như không có tác dụng; Tôi vẫn nhận được các thông báo WARN ở trên.
Tôi đang sử dụng đoạn mã sau để liệt kê triển khai JAXB đang chạy; có lẽ điều này là không chính xác?
/**
* Print the JAXB Implementation information
*/
public static void outputJaxpImplementationInfo() {
logger.debug(getImplementationInfo("DocumentBuilderFactory", DocumentBuilderFactory.newInstance().getClass()));
logger.debug(getImplementationInfo("XPathFactory", XPathFactory.newInstance().getClass()));
logger.debug(getImplementationInfo("TransformerFactory", TransformerFactory.newInstance().getClass()));
logger.debug(getImplementationInfo("SAXParserFactory", SAXParserFactory.newInstance().getClass()));
}
/**
* Get the JAXB implementation information for a particular class
* @param componentName
* @param componentClass
* @return
*/
private static String getImplementationInfo(String componentName, Class componentClass) {
CodeSource source = componentClass.getProtectionDomain().getCodeSource();
return MessageFormat.format(
"{0} implementation: {1} loaded from: {2}",
componentName,
componentClass.getName(),
source == null ? "Java Runtime" : source.getLocation());
}
đoạn này tạo ra các bản ghi sau:
10:28:27,402 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,402 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - DocumentBuilderFactory implementation: __redirected.__DocumentBuilderFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
10:28:27,403 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,403 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - XPathFactory implementation: __redirected.__XPathFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
10:28:27,404 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,404 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - TransformerFactory implementation: __redirected.__TransformerFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
10:28:27,406 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,406 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - SAXParserFactory implementation: __redirected.__SAXParserFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
Có thể việc triển khai JAXB phụ thuộc vào một mức độ nào đó. Để khôi phục, JAXB RI được sử dụng để yêu cầu sử dụng cơ chế JRE 'xác nhận' nếu bộ nhớ phục vụ. Bạn có thể vui lòng chỉ định các chi tiết của môi trường của bạn: máy chủ ứng dụng, phiên bản JDK, JAXB impl form/để bắt đầu. –
@PatriceM - xin lỗi; quên bao gồm điều đó. Tôi đã chỉnh sửa câu hỏi orig để thêm nó vào. –
Tôi đã chỉnh sửa bài đăng gốc để thêm một số thông tin bổ sung để chỉ ra cách tôi thực hiện JAXB đang được sử dụng, cũng như liên kết cho biết cách ghi đè triển khai JAXB mặc định của JRE. đang làm việc. –