Duplicate Class Path Entries

本文记录了在升级Java版本过程中遇到的Class-Path重复警告问题,并详细描述了如何通过检查和修改JAR文件中的manifest文件来解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The problem

We’re considering upgrading to Java 1.4.2 from 1.4.0 on our production servers. Taking the bold step of trying this out in development first uncovered a weird issue: whenever running code with 1.4.2 (whether via Tomcat or junit tests w/ant) we got these errors:

    [junit] Oct 27, 2003 5:08:49 PM java.util.jar.Attributes read
    [junit] WARNING: Duplicate name in Manifest: Class-Path

How I fixed it

 


  • google search: nada.
  • Does this mean we have duplicate jars in the classpath? Use ant -verbose test to find out. (Oi, 77 entries. I hate classpath issues.) Nothing obvious, but this doesn’t stop me fiddling fruitlessly with build.xml to no effect.
  • What the hell is a manifest file again? Google provides. A manifest file is created whenever you create a JAR file. Hey, maybe we have a Manifest file in one of our JARs with a duplicate Class-Path entry. (It should be obvious at this point why I get paid the big bucks.)
  • So we have somewhere around 70 jar files that could have an extra Class-Path line. (I hate classpath issues.)
  • We need to: unpack each one, grep for Class-Path, repeat.
  • I copy all suspect JARs to a temp dir and start doing this. Eventually I remember that computers are good at automating repetitive tasks (who knew?) and write a quick shell script:

     

    #!/bin/tcsh
    
    jar xf $1
    chmod +x META-INF
    grep -i class META-INF/MANIFEST.MF
    echo "Finished looking at $1"
    rm $1
    rm -r META-INF/
    ls
    


  • Now I can quickly scan a particular jar with quick.sh foo.jar. (Full disclosure aside: this is just the final quick.sh; the chmod line is there because I was initially using unzip -l instead of jar xf and it would sometimes not have execute perms on the dirs. As it is now, I don’t think it’s necessary.)
  • Eventually, I find the cuplrit: struts.jar.

 

Great! Now I’ve identified the problem, I just need to fix it. This involves unpacking struts.jar, fixing the manifest file (instead of multiple Class-Path: lines with one jar per line, one Class-Path line with multiple jars separated by spaces), and repacking the jar ( jar cmf ../MANIFEST.MF struts.jar *). Test runs now have regular output. Joy.

What I’d do differently next time

  • Read the error message more carefully. Went a bit down the wrong road because of this.
  • I haven’t checked this, but I suspect if I read through the release notes for 1.4.2 (and maybe 1.4.1) I’ll find reference to this change.
  • I suspect if I’d stopped and thought a bit, I could have come up with an even cleaner solution to looking through all those jar files; it could even be that there’s a tool out there for doing just that. If I had greater facility with shell scripts, I could also have done it that way.

Update: Did some browsing of sun’s Java forums, which are unfortunately behind a registration wall, and therefore not indexed by search engines. [That this is stupid is fairly evident, so I won’t comment further upon it.] What I learned is:

  • The specification is clear that if there is more than one Class-Path entry, only the last will be used. Unfortunately, there is a tutorial somewhere on sun.com that says otherwise. This has resulted in many a bug.
  • There is also a 72 byte limit to manifest file lines. You can use SPACE + NEWLINE as a continuation marker (again, this is in the spec.)
  • There is a bug (registration required) that documents the change. This bug is still marked as in progress at this time, although the description indicates it’s a 1.4.2 change
  • Nothing in 1.4.2’s changes file or README document this change.
### 解决YOLOv5训练过程中重复标签被移除的问题 当遇到 `duplicate labels` 被移除的警告时,这通常意味着数据集中存在标注错误或冗余。为了有效处理这一问题并确保模型能够正常学习,可以采取以下措施: #### 数据清理与验证 确保数据集中的每张图像仅有一个唯一的标签文件,并且这些标签文件内不存在重复的对象标记。可以通过编写脚本来自动检测和修正这类问题。 对于已经存在的重复标签情况,建议先备份原始数据集以防意外丢失重要信息之后再执行去重操作。下面是一个Python代码片段用来查找可能含有重复标签的图片[^3]: ```python import os from collections import defaultdict def find_duplicate_labels(label_dir): duplicates = [] for filename in os.listdir(label_dir): if not filename.endswith('.txt'): continue with open(os.path.join(label_dir, filename), 'r') as f: lines = [line.strip() for line in f.readlines()] seen = set() dupes = [] for l in lines: class_id, *coords = map(float, l.split()) key = (class_id,) + tuple(coords) if key in seen: dupes.append(l) seen.add(key) if dupes: duplicates.append((filename, dupes)) return duplicates label_directory = "path/to/your/labels" duplicates_found = find_duplicate_labels(label_directory) for img_file, dups in duplicates_found: print(f"In {img_file}, found duplicate entries:") for dupe in dups: print(dupe) ``` 此段程序会遍历指定目录下的所有`.txt`格式的标签文件,检查其中是否存在完全相同的对象描述(即类别ID加上坐标),并将发现的结果打印出来以便进一步分析处理。 #### 修改配置文件 如果确认某些情况下确实需要保留看似“重复”的标签,则可以在YOLOv5项目的配置文件中调整参数来允许这种特殊情况的存在。不过一般而言,在大多数应用场景下保持单一实例化的物体更为合理。 #### 更新至最新版本 考虑到官方团队可能会针对此类常见问题做出改进优化,推荐定期查看是否有新的发布版本可用,并考虑升级到最新的稳定版以获得更好的支持和服务[^4]。 通过上述方法应该可以帮助缓解甚至彻底解决问题。当然具体实施还需要根据实际情况灵活应对。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值