java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错

本文详细记录了解决java.lang.NoClassDefFoundError:Lorg/apache/log4j/Logger错误的过程,通过调整Eclipse的JRE设置,正确安装依赖项目,最终使项目运行正常。

java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错

 

错误提示:

java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger报错(lib包没有导入)

第一步、检查maven的配置:

maven管理的项目,里面已经引入了log4j的包

maven引入如下:

<dependency>

      <groupId>log4j</groupId>

      <artifactId>log4j</artifactId>

      <version>1.2.16</version>

      <scope>compile</scope>

 </dependency>

确定引入了log4j的包。

第二步、检查builder的项目

在编译的过程中,已经包括了log4j的包。

 

第三步、检查部署

错误的项目是没有maven dependencies这一项的,需要add,选择add按钮,

 

添加以后,然后,从新部署下项目。成功运行!

 

========================================

上面这些是网上找的,但是我并没有用到

但是另一个同事却是用到了上文的 第三步 解决了同样的问题,故在这里标记下。

 

我的问题是:

从svn检出一个项目,运行就报错,  by cause :java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger

 

问题处理方法:

但是检查项目,发现  jar 包都在,项目名上有个小红叉号,但是项目里面代码中又没有问题,在 problems 窗口 显示 是项目 编译错误

检查该项目的 pom 文件,发现 其依赖了两个本地的其他maven项目,于是想着把 其依赖的另外两个项目  maven install 一下,结果发现 install 居然报错,无法安装到 仓库,

经过一番折腾,发现是 Eclipse的  preference中的 Java—— Installd JREs 中的 路径配置成了 jre的目录,将其改为 jdk 的目录 后,再 install 就可以了。

将两个被 依赖的 项目 install 完成后,再次 启动原来报错的目标项目,就不报错了

 

转载于:https://www.cnblogs.com/libin6505/p/9883128.html

package com.sintay.sink; import com.sintay.utils.LocalFileConfigParam; import org.apache.flink.api.java.tuple.Tuple2; import org.apache.flink.configuration.Configuration; import org.apache.flink.runtime.state.FunctionInitializationContext; import org.apache.flink.runtime.state.FunctionSnapshotContext; import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction; import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; import org.apache.flink.table.sinks.TableSink; import org.apache.paimon.catalog.*; import org.apache.paimon.data.GenericRow; import org.apache.paimon.flink.sink.StoreSinkWrite; import org.apache.paimon.options.Options; import org.apache.paimon.table.sink.*; import java.util.List; import java.util.Map; import org.apache.paimon.catalog.Catalog; import org.apache.paimon.catalog.CatalogContext; import org.apache.paimon.catalog.Identifier; import org.apache.paimon.table.Table; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; /** * 一条 DataStream 写多张 Paimon 表(Paimon 1.2.0) * 输入:Tuple2<表名, RowData> */ public class MultiTablePaimonSink extends RichSinkFunction<Tuple2<String, GenericRow>> implements CheckpointedFunction { private static final Logger LOG = LoggerFactory.getLogger(MultiTablePaimonSink.class); /** 表名 -> 写入器 */ private final Map<String, StreamTableWrite> writers = new HashMap<>(); /** 表名 -> 未提交数据条数(仅做示例,可不要) */ private final Map<String, Long> rowCounts = new HashMap<>(); private final Map<String, StreamTableCommit> commits = new HashMap<>(); private Catalog catalog; // private final Map<String, TableSink> tableSinkMap; // public MultiTablePaimonSink(Map<String, TableSink> tableSinkMap) { // this.tableSinkMap = tableSinkMap; // } @Override public void open(Configuration parameters) throws Exception { Options opts = new Options(); opts.set ("warehouse", LocalFileConfigParam.getPropertiesString("paimon.warehouse","")); opts.set ("metastore", LocalFileConfigParam.getPropertiesString("paimon.metastore","")); opts.set ("uri", LocalFileConfigParam.getPropertiesString("paimon.uri","")); catalog = CatalogFactory.createCatalog(CatalogContext.create(opts)); } @Override public void invoke(Tuple2<String, GenericRow> value, Context context) throws Exception { String tableName = value.f0; GenericRow row = value.f1; System.out.println("=== 表名: " + tableName + " ==="); Table table = catalog.getTable(Identifier.create("dim", tableName)); System.out.println("表 schema: " + table.rowType()); System.out.println("写入 row: " + row); StreamTableWrite write = writers.computeIfAbsent(tableName, this::createWriter); write.write(row); rowCounts.merge(tableName, 1L, Long::sum); } // key = 表名 @Override public void snapshotState(FunctionSnapshotContext context) throws Exception { long checkpointId = context.getCheckpointId(); for (Map.Entry<String, StreamTableWrite> e : writers.entrySet()) { String tableName = e.getKey(); StreamTableWrite write = e.getValue(); // 注意第一个参数 endOfInput 传 false List<CommitMessage> committables = write.prepareCommit(false, checkpointId); if (!committables.isEmpty()) { StreamTableCommit commit = commits.computeIfAbsent( tableName, this::createCommitter); commit.commit(checkpointId, committables); } } } /** 创建 StreamTableCommit */ private StreamTableCommit createCommitter(String tableName) { try { Table table = catalog.getTable(Identifier.create("dim", tableName)); return table.newStreamWriteBuilder().newCommit(); } catch (Exception ex) { throw new RuntimeException("Failed to create committer for " + tableName, ex); } } @Override public void initializeState(FunctionInitializationContext context) { // 不做恢复,直接空实现即可 } /** 关闭所有 writer */ @Override public void close() throws Exception { for (StreamTableWrite write : writers.values()) { write.close(); } if (catalog != null) { catalog.close(); } } /* -------------------------------------------------- */ /* 工具方法 */ /* -------------------------------------------------- */ private StreamTableWrite createWriter(String tableName) { try { Table table = catalog.getTable(Identifier.create("dim", tableName)); StreamWriteBuilder builder = table.newStreamWriteBuilder(); return builder.newWrite(); // 每次返回新的 writer } catch (Exception ex) { throw new RuntimeException("Cannot create writer for " + tableName, ex); } } } 这是我写的sink代码,但是运行中报错,帮我分析一下,如何改
最新发布
08-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值