Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Building a jar file with exclusions.

Reply
Thread Tools

Building a jar file with exclusions.

 
 
Roedy Green
Guest
Posts: n/a
 
      06-06-2004
Sometimes you want to build a jar file and exclude a few files. Is
there a way to do that and still get a correct manifest?

Maintaining an explicit list of files to include is error prone since
you can't use wildcards, and you need to mention every internal class
explicitly.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Mickey Segal
Guest
Posts: n/a
 
      06-06-2004
"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sometimes you want to build a jar file and exclude a few files. Is
> there a way to do that and still get a correct manifest?
>
> Maintaining an explicit list of files to include is error prone since
> you can't use wildcards, and you need to mention every internal class
> explicitly.


I have a batch file that renames the files to exclude, makes the JAR and
CAB, and then re-renames the files.


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-06-2004
On Sun, 06 Jun 2004 21:23:44 GMT, Roedy Green
<(E-Mail Removed)> wrote or quoted :

>Sometimes you want to build a jar file and exclude a few files. Is
>there a way to do that and still get a correct manifest?
>
>Maintaining an explicit list of files to include is error prone since
>you can't use wildcards, and you need to mention every internal class
>explicitly.


The way I decided to handle this was to split the project in two so I
would not need exclusions, only inclusions from the other project.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-06-2004
On Sun, 6 Jun 2004 18:10:06 -0400, "Mickey Segal"
<(E-Mail Removed)> wrote or quoted :

>I have a batch file that renames the files to exclude, makes the JAR and
>CAB, and then re-renames the files.


How does renaming hide them? Do you move them to a different
directory?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      06-06-2004
Roedy Green wrote:
> Sometimes you want to build a jar file and exclude a few files. Is
> there a way to do that and still get a correct manifest?
>
> Maintaining an explicit list of files to include is error prone since
> you can't use wildcards, and you need to mention every internal class
> explicitly.


Strange, but I just ran into a variant of this same issue recently. I
needed to backup a source tree but not include object files, executables
or Java class files. I ended up using ant! Even though I actually use
the tar task (rather than jar), the approach is the same. Here's a
sample task:

<jar destfile="${dist}/lib/app.jar">
<fileset dir="${build}/classes">
<custom classname="net.sudsy.ant.util.FileFilter" />
</fileset>
</jar>

Here's part of my FileFilter.java source:

package net.sudsy.ant.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.DataInputStream;
import java.io.IOException;

public class FileFilter
implements org.apache.tools.ant.types.selectors.FileSelector {
public boolean isSelected( File baseDir, String fileName,
File f ) {
DataInputStream dis = null;
try {
if( ! f.exists() ) // should not happen
return( false );
if( f.isDirectory() ) // don't include directories
return( false );
dis = new DataInputStream( new FileInputStream( f ) );
int fileType = dis.readInt(); // get "magic" #
if( fileType == 0x7f454c46 ) // ELF format
return( false );
if( fileType == 0xcafebabe ) // Java class
return( false );
}
catch( IOException e ) {
}
finally {
if( dis != null ) {
try {
dis.close();
}
catch( IOException e ) {
}
}
}
return( true );
}
}

Easier to do it this way than try to come up with the correct
list of extensions/lack of extensions to include/exclude.
I thought it was quite neat!

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-07-2004
On 6 Jun 2004 19:16:44 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (Malcolm
Dew-Jones) wrote or quoted :

>You can use zip, but it doesn't create a manifest. A batch file or shell
>script could use zip, then list the zip contents as the basis to create a
>manifest file, and add the manifest back to the zip.


I think it is time that jar.exe were beefed up a little to allow
exclusion and inclusion list files with wildcards.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      06-07-2004
Roedy Green ((E-Mail Removed)) wrote:
: Sometimes you want to build a jar file and exclude a few files. Is
: there a way to do that and still get a correct manifest?

You can use zip, but it doesn't create a manifest. A batch file or shell
script could use zip, then list the zip contents as the basis to create a
manifest file, and add the manifest back to the zip.

--

(Paying) telecommute programming projects wanted. Simply reply to this.

 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      06-07-2004
> Sometimes you want to build a jar file and exclude a few files. Is
> there a way to do that and still get a correct manifest?
>
> Maintaining an explicit list of files to include is error prone since
> you can't use wildcards, and you need to mention every internal class
> explicitly.


http://ant.apache.org/

--
Tony Morris
(BInfTech, Cert 3 I.T.)
Software Engineer
(2003 VTR1000F)
Sun Certified Programmer for the Java 2 Platform (1.4)
Sun Certified Developer for the Java 2 Platform


 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-07-2004
Malcolm Dew-Jones wrote:
> You can use zip, but it doesn't create a manifest. A batch file or shell
> script could use zip, then list the zip contents as the basis to create a
> manifest file, and add the manifest back to the zip.


This is dangerous, since the manifest file must be the first file in the
archive, otherwise JarInputStream fails to find and read it. If you add
the manifest file manually later, chances are, that it will not be where
it is supposed to be.

/Thomas
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-07-2004
On Mon, 07 Jun 2004 08:36:22 +0200, Thomas Weidenfeller
<(E-Mail Removed)> wrote or quoted :

>This is dangerous, since the manifest file must be the first file in the
>archive, otherwise JarInputStream fails to find and read it. If you add
>the manifest file manually later, chances are, that it will not be where
>it is supposed to be.


The other thing you have to watch for is making sure Winzip/PkZip uses
none of the fancy compression algorithms that jar/ZipFile does not
understand.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
how to disassembly a .jar file? how to see what are the classes inside the .jar file? lucy Java 6 09-07-2004 09:54 PM



Advertisments