简体   繁体   English

“jar”命令何时拒绝将类添加到.jar文件中?

[英]When will the “jar” command refuse to add a class to a .jar file?

I have 204 total classes (most of the classes are inner classes). 我总共有204个班级(大多数班级都是班级班级)。 For months, I have been building fine with SCons (SCons just calls the jar command). 几个月来,我一直在使用SCons构建正常(SCons只调用jar命令)。

For some reason, it stopped adding the last inner class for a particular class. 出于某种原因,它停止为特定类添加最后一个内部类。 For example, suppose I have the following classes: 例如,假设我有以下类:

class1
class2
class3
class4
class5
class6
...
class79
class80

Before this last change, SCons would jar everything fine. 在最后一次改变之前,SCons会把一切都搞好。 But NOW... it specifically does not add class80 to it's jar command. 但是现在......它特别没有将class80添加到它的jar命令中。 (I see an omission of the class80 in the jar command). (我在jar命令中看到了class80的遗漏)。

Is there an instance where the jar command just ignores certain classes? 是否存在jar命令忽略某些类的实例?

----------- EDIT. -----------编辑。 I found the culprit. 我找到了罪魁祸首。 For some reason this inner class is not recognized my SCons! 出于某种原因,这个内部课程无法识别我的SCons!

vehicleFilter = new RowFilter<Object, Object>(){ 
public boolean include(Entry<? extends Object, ? extends Object> entry)                {                                                 
    {return false;}  
};

You need to add JAVAVERSION='1.6' as an argument to your env.Java() call: 你需要在你的env.Java()调用中添加JAVAVERSION='1.6'作为参数:

env.Java(target='classes', source='src', JAVAVERSION='1.6')

Without this, if you're compiling with a current javac , SCons won't determine the correct names for anonymous inner classes, so when those bad class file names get passed to jar , it will fail. 如果没有这个,如果您使用当前的javac ,SCons将无法确定匿名内部类的正确名称,因此当这些错误的类文件名传递给jar ,它将失败。

Rather than pass a whole list of class files to the Jar command, you can pass a directory. 您可以传递目录,而不是将完整的类文件列表传递给Jar命令。 This avoids problems with SCons's java parser as SCons will scan the directory for files and jar up anything it finds. 这避免了SCons的java解析器的问题,因为SCons将扫描目录中的文件并查找它找到的任何内容。

Something like the following will compile files in "src" to the directory "classes", then create a jar from the contents of "classes": 像下面这样的东西会将“src”中的文件编译到目录“classes”中,然后从“classes”的内容创建一个jar:

env = Environment(tools=['javac', 'jar'])
env.Java(target='classes', source='src')
env.Jar(target='foo.jar', source=['classes', 'Manifest.txt'],
        JARCHDIR='$SOURCE')

The manifest file "Manifest.txt" is in the root of your project here. 清单文件“Manifest.txt”位于项目的根目录中。 The only requirement is that it begins with the text "Manifest-Version". 唯一的要求是它以文本“Manifest-Version”开头。

SCons may construct a command line by listing all classes to jar on it and that may get too long (either a platform limitation or a heuristic inside SCons). SCons可以通过列出jar上的所有类来构造命令行,这可能会变得太长(平台限制或SCons内部的启发式)。

You need to peek inside the SCons package to see what goes on. 您需要查看SCons包内部以查看发生了什么。

Any particular reason you don't just use ant? 你不只是使用蚂蚁的任何特殊原因?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM