简体   繁体   中英

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). For months, I have been building fine with SCons (SCons just calls the jar command).

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. But NOW... it specifically does not add class80 to it's jar command. (I see an omission of the class80 in the jar command).

Is there an instance where the jar command just ignores certain classes?

----------- EDIT. I found the culprit. For some reason this inner class is not recognized my 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(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.

Rather than pass a whole list of class files to the Jar command, you can pass a directory. This avoids problems with SCons's java parser as SCons will scan the directory for files and jar up anything it finds.

Something like the following will compile files in "src" to the directory "classes", then create a jar from the contents of "classes":

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. The only requirement is that it begins with the text "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).

You need to peek inside the SCons package to see what goes on.

Any particular reason you don't just use ant?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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