Quarkus, Log4J 1-2 Bridge, and Uber Jar

I have this code, which initializes a Log4J context in my application.
The application is being developed using Quarkus 2.16.7.Final. Log4j context is wrapped inside my generic “loggingContext” class, which exposes “initialize” method to use for logging context initialization inside a more generic application context:

public synchronized void initialize(ApplicationContext currentApplicationContext) throws LoggingContextException {
    if (!isInitialized()) {
        File configurationFile = null;
        configurationFile = new File(getConfigurationContext().getLog4jFilePath());
        if (!configurationFile.exists()) {
            throw new LoggingContextException("Could not find LOG4J configuration file: "" + getConfigurationContext().getLog4jFilePath() + "".");
        }
        this.loggingId = currentApplicationContext.getApplicationName();
        try (FileInputStream fis = new FileInputStream(configurationFile);) {
            this.loggerContext = LoggerContext.getContext(getConfigurationContext().getClassLoader(), false, null);
            loggerContextOwnership = initLoggerContext(this.loggerContext, configurationFile);
            if (loggerContextOwnership) {
                System.out.println(loggingId + " - Logging Context INITIALIZED (LOG4J File Path: "" + this.loggerContext.getConfiguration().getConfigurationSource().getFile() + ""). <<<");
            } else {
                File configFile = loggerContext.getConfiguration().getConfigurationSource().getFile();
                if (!configFile.getAbsolutePath().equals(configurationFile.getAbsolutePath())) {
                    throw new LoggingContextException("Could not acquire LOG4J context ownership.");
                }
            }
        } catch (IOException e) {
            throw new LoggingContextException("Could not read LOG4J configuration file", e);
        }
        this.initialized = true;
        super.initialize(currentApplicationContext);
    }
}
private boolean initLoggerContext(LoggerContext loggerContext, File log4jConfigurationFile) {
    boolean hasOwnership = false;
    Configuration xmlConfig = ConfigurationFactory.getInstance().getConfiguration(null, "Application Framework LOG4J configuration", log4jConfigurationFile.toURI());
    File configFile = loggerContext.getConfiguration().getConfigurationSource().getFile();
    String key = getConfigurationContext().getLog4jFilePath();
    if (configFile == null) {
        loggerContext.setConfiguration(xmlConfig);
        hasOwnership = true;
        synchronized (log4jContextMap) {
            List<LOG4JContext> list = log4jContextMap.get(getConfigurationContext().getClassLoader()).computeIfAbsent(key, k -> {
                return new LinkedList<>();
            });
            list.add(this);
        }
    } else {
        if (!configFile.getAbsolutePath().equals(log4jConfigurationFile.getAbsolutePath())) {
            System.out.println(loggingId + " - WARNING: LOG4J Context already initialized (file: "" + configFile.getAbsolutePath() + "").");
            LoggingOwnershipMode loggingOwnershipMode = getConfigurationContext().getLoggingOwnershipMode();
            switch (loggingOwnershipMode) {
                case DEFAULT:
                    break;
                case FORCE:
                    loggerContext.setConfiguration(xmlConfig);
                    hasOwnership = true;
                    System.out.println(loggingId + " - WARNING: LOG4j Context has been reconfigured.");
                    break;
                default:
                    break;
            }
        } else {
            hasOwnership = true;
            synchronized (log4jContextMap) {
                List<LOG4JContext> list = log4jContextMap.get(getConfigurationContext().getClassLoader()).computeIfAbsent(key, k -> {
                    return new LinkedList<>();
                });
                list.add(this);
            }
        }
    }
    return hasOwnership;
}

I have these dependencies (dependency hierarchy, Eclipse IDE view):

My Log4J context works (on Windows) only with FAST-JAR configuration. I would like to use a Uber-Jar instead. Using an Uber Jar I have the following SystemOut:

I do not want to use Jboss logging since this application is a porting from a J2EE application which heavily uses log4j. Using fast jar is not accepted as final solution. I am pretty sure the problem is related to classloading mechanisms, but I would like to overcome it. Any suggestions?

Note

I am not sure this is related with the proposed duplicate question. We are creating a Uber-Jar in Quarkus semantics. maven-shade-plugin is not used and the question is related to adding log4j1-2 bridge to Quarkus which works in fast-jar mode but not uber-jar/legacy-jar.

5

Problem was solved by removing from the final runner.jar the file “Log4j2Plugins.dat”. this file should be merged instead of removed but i just need log4j2-CORE plugins which should be annotated with @Plugin and they are enough for me.

The warning of Quarkus is enough to understand that the file is the problem (packaging uber-jar):

[WARNING] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Dependencies with duplicate files detected. The dependencies [org.apache.logging.log4j:log4j-1.2-api::jar:2.19.0[paths: H:Mavenorgapachelogginglog4jlog4j-1.2-api2.19.0log4j-1.2-api-2.19.0.jar;], org.apache.logging.log4j:log4j-core::jar:2.19.0[paths: H:Mavenorgapachelogginglog4jlog4j-core2.19.0log4j-core-2.19.0.jar;], org.apache.logging.log4j:log4j-web::jar:2.19.0[paths: H:Mavenorgapachelogginglog4jlog4j-web2.19.0log4j-web-2.19.0.jar;]] contain duplicate files, e.g. META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật