Results 1 to 8 of 8
- 06-07-2010, 02:50 AM #1
Why seal a JAR File or why seal packages with a JAR file?
A friend told me it is good practice to seal JAR files. I asked him why and he didn't know why. Pretty fatuous if you ask me. Anyhow, three questions arise:
1. Is it good practice to seal JAR files?
2. If so, why?
3. When would one seal packages within a JAR file?
I did some reading ( Sealing Packages within a JAR File (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files) )
This is the tutorial's explanation of question #3:Isn't the bold text always true? Is it saying that it is possible for some classes of a package can be in a different JAR file? If so, wouldn't one always seal a package then?Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software.
This is the tutorial's explanation of question #2:When will it not be in the same source? Is it talking about a package being in a different JAR file? If someone can explain, I would be grateful.If you want to guarantee that all classes in a package come from the same code source, use JAR sealing. A sealed JAR specifies that all packages defined by that JAR are sealed unless overridden on a per-package basis.
Finally, is there any other reason why one should seal a JAR file or packages within it? Is it good practice to do so? Thanks in advance!
Best Regards,
Lil_Aziz1"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-07-2010, 03:02 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Study to read PMB, pal :)
- 06-07-2010, 03:21 AM #3
What's PMB?
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-07-2010, 03:25 AM #4
To test if all class in a package must be in the same jar file. Do a test: Create a project with >1 classes and put the class files into different jar files, put the jar files on the classpath and see if java can find them.
- 06-07-2010, 08:10 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Suppose you have package scope class that contains some 'secret' information so the information also has package scope (other classes in the same package can reach that information but nothing outside the package can see it).
Suppose the information isn't sealed: that allows me to define a public class in the same pacakge as where that information is stored; my class can reach that information. I jar my class in another .jar file (or I don't jar the class at all) and presto: I'm in.
Sealing a package (or the entire .jar file effectively sealing all packages) prohibits that type of peeking. OTOH: not sealing a package (or entire jar file) allows for the addition or modification of functionality.
kind regards,
Jos
- 06-07-2010, 11:35 PM #6
Oh I think I got it. Let me try putting what you said in my own words and tell me if it's correct:
So there is a package called "com.test" in a JAR file called "test.jar". The package and the JAR file are not sealed. A mischievous person does the following:
Then he extracts w/e is in "test.jar" test and makes his own JAR file called "testx.jar" and adds all the files extracted from test.jar and the class Z. Sealing the package "com.test" will prevent him from doing that right? So when someone seals a JAR file, does that prevent him/her from updating the JAR file? (something like this: jar uf com.test Z.class)Java Code:package com.test; public class Z { ... }
Another question: Let's say a JAR file has 1 file, A.class. Class A writes/reads to a file somewhere in the C:\ directory. If the JAR file is sealed, will it let it read/write to that file (without the security manager)?
Last question: Let's say a JAR file (test.jar) has 1 package (test1). If you seal test.jar, is test1 implicitly sealed? What if you seal test1. Is test.jar implicitly sealed then? Thank you very much!
Best Regards,
Aziz JavedLast edited by Lil_Aziz1; 06-07-2010 at 11:41 PM.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-09-2010, 10:14 PM #7
Thought I'd bump because it's been two days.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-09-2010, 10:19 PM #8
Similar Threads
-
how to change the layout of an input file and write to an output file
By renu in forum New To JavaReplies: 8Last Post: 05-12-2010, 07:19 PM -
How to show or open a file download or file save dialog box
By java_bond in forum New To JavaReplies: 0Last Post: 03-05-2010, 04:21 AM -
Sending a File from Server to Client and saving the file to Clients computer
By al_Marshy_1981 in forum NetworkingReplies: 8Last Post: 02-18-2010, 12:54 PM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM -
How to parse the CSV(Comma separation values)file and validate the file using java
By padmajap13 in forum Advanced JavaReplies: 7Last Post: 05-23-2008, 03:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks