Java net url jar file

URL for jar file

The following code creates a URL that refers to a jar file in the file system.

import java.net.URL; /*from jav a2s . co m*/ public class Main < public static void main(String[] argv) throws Exception < URL url = new URL("jar:file:/c://my.jar!/"); System.out.println(url); > > 

The code above generates the following result.

URL for single file in a jar file

The following code creates a URL that refers to an entry in the jar file

import java.net.URL; /* jav a2 s . c o m*/ public class Main < public static void main(String[] argv) throws Exception < URL url = new URL("jar:file:/c://my.jar!/com/mycompany/MyClass.class"); System.out.println(url); > > 

The code above generates the following result.

Next chapter.

What you will learn in the next chapter:

Источник

Java net url jar file

for example: jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class Jar URLs should be used to refer to a JAR file or entries in a JAR file. The example above is a JAR URL which refers to a JAR entry. If the entry name is omitted, the URL refers to the whole JAR file: jar:http://www.foo.com/bar/baz.jar!/ Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL, and they need JAR-specific functionality. For example:

URL url = new URL("jar:file:/home/duke/duke.jar!/"); JarURLConnection jarConnection = (JarURLConnection)url.openConnection(); Manifest manifest = jarConnection.getManifest();
  • if there is no context URL and the specification passed to the URL constructor doesn’t contain a separator, the URL is considered to refer to a JarFile.
  • if there is a context URL, the context URL is assumed to refer to a JAR file or a Jar directory.
  • if the specification begins with a ‘/’, the Jar directory is ignored, and the spec is considered to be at the root of the Jar file. Examples: context: jar:http://www.foo.com/bar/jar.jar!/, spec:baz/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/entry.txt

Field Summary

Fields inherited from class java.net.URLConnection

Constructor Summary

Method Summary

Return the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.

Return the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise.

Methods inherited from class java.net.URLConnection

Methods inherited from class java.lang.Object

Field Detail

jarFileURLConnection

The connection to the JAR file URL, if the connection has been initiated. This should be set by connect.

Constructor Detail

JarURLConnection

protected JarURLConnection(URL url) throws MalformedURLException

Method Detail

getJarFileURL

getEntryName

Return the entry name for this connection. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

getJarFile

public abstract JarFile getJarFile() throws IOException

getManifest

public Manifest getManifest() throws IOException

getJarEntry

public JarEntry getJarEntry() throws IOException

Return the JAR entry object for this connection, if any. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

getAttributes

public Attributes getAttributes() throws IOException

Return the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.

getMainAttributes

public Attributes getMainAttributes() throws IOException

getCertificates

public Certificate[] getCertificates() throws IOException

Return the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise. This method can only be called once the connection has been completely verified by reading from the input stream until the end of the stream has been reached. Otherwise, this method will return null

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Источник

Java net url jar file

for example: jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class Jar URLs should be used to refer to a JAR file or entries in a JAR file. The example above is a JAR URL which refers to a JAR entry. If the entry name is omitted, the URL refers to the whole JAR file: jar:http://www.foo.com/bar/baz.jar!/ Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL, and they need JAR-specific functionality. For example:

URL url = new URL("jar:file:/home/duke/duke.jar!/"); JarURLConnection jarConnection = (JarURLConnection)url.openConnection(); Manifest manifest = jarConnection.getManifest();
  • if there is no context URL and the specification passed to the URL constructor doesn’t contain a separator, the URL is considered to refer to a JarFile.
  • if there is a context URL, the context URL is assumed to refer to a JAR file or a Jar directory.
  • if the specification begins with a ‘/’, the Jar directory is ignored, and the spec is considered to be at the root of the Jar file. Examples: context: jar:http://www.foo.com/bar/jar.jar!/, spec:baz/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/entry.txt

Field Summary

Fields declared in class java.net.URLConnection

Constructor Summary

Method Summary

Return the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.

Return the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise.

Methods declared in class java.net.URLConnection

Methods declared in class java.lang.Object

Field Detail

jarFileURLConnection

The connection to the JAR file URL, if the connection has been initiated. This should be set by connect.

Constructor Detail

JarURLConnection

protected JarURLConnection​(URL url) throws MalformedURLException

Method Detail

getJarFileURL

getEntryName

Return the entry name for this connection. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

getJarFile

public abstract JarFile getJarFile() throws IOException

getManifest

public Manifest getManifest() throws IOException

getJarEntry

public JarEntry getJarEntry() throws IOException

Return the JAR entry object for this connection, if any. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

getAttributes

public Attributes getAttributes() throws IOException

Return the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.

getMainAttributes

public Attributes getMainAttributes() throws IOException

getCertificates

public Certificate[] getCertificates() throws IOException

Return the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise. This method can only be called once the connection has been completely verified by reading from the input stream until the end of the stream has been reached. Otherwise, this method will return null

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Class JarURLConnection

Jar URLs should be used to refer to a JAR file or entries in a JAR file. The example above is a JAR URL which refers to a JAR entry. If the entry name is omitted, the URL refers to the whole JAR file: jar:http://www.foo.com/bar/baz.jar!/

Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL, and they need JAR-specific functionality. For example:

URL url = new URL("jar:file:/home/duke/duke.jar!/"); JarURLConnection jarConnection = (JarURLConnection)url.openConnection(); Manifest manifest = jarConnection.getManifest();

JarURLConnection instances can only be used to read from JAR files. It is not possible to get a OutputStream to modify or write to the underlying JAR file using this class.

Examples: A Jar entry jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class A Jar file jar:http://www.foo.com/bar/baz.jar!/ A Jar directory jar:http://www.foo.com/bar/baz.jar!/COM/foo/

!/ is referred to as the separator.

  • if there is no context URL and the specification passed to the URL constructor doesn’t contain a separator, the URL is considered to refer to a JarFile.
  • if there is a context URL, the context URL is assumed to refer to a JAR file or a Jar directory.
  • if the specification begins with a ‘/’, the Jar directory is ignored, and the spec is considered to be at the root of the Jar file. Examples: context: jar:http://www.foo.com/bar/jar.jar!/, spec:baz/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/entry.txt

Источник

Class JarURLConnection

Jar URLs should be used to refer to a JAR file or entries in a JAR file. The example above is a JAR URL which refers to a JAR entry. If the entry name is omitted, the URL refers to the whole JAR file: jar:http://www.foo.com/bar/baz.jar!/

Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL, and they need JAR-specific functionality. For example:

URL url = new URL("jar:file:/home/duke/duke.jar!/"); JarURLConnection jarConnection = (JarURLConnection)url.openConnection(); Manifest manifest = jarConnection.getManifest();

JarURLConnection instances can only be used to read from JAR files. It is not possible to get a OutputStream to modify or write to the underlying JAR file using this class.

Examples: A Jar entry jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class A Jar file jar:http://www.foo.com/bar/baz.jar!/ A Jar directory jar:http://www.foo.com/bar/baz.jar!/COM/foo/

!/ is referred to as the separator.

  • if there is no context URL and the specification passed to the URL constructor doesn’t contain a separator, the URL is considered to refer to a JarFile.
  • if there is a context URL, the context URL is assumed to refer to a JAR file or a Jar directory.
  • if the specification begins with a ‘/’, the Jar directory is ignored, and the spec is considered to be at the root of the Jar file. Examples: context: jar:http://www.foo.com/bar/jar.jar!/, spec:baz/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:entry.txt url:jar:http://www.foo.com/bar/jar.jar!/baz/entry.txt context: jar:http://www.foo.com/bar/jar.jar!/baz, spec:/entry.txt url:jar:http://www.foo.com/bar/jar.jar!/entry.txt

Источник

Читайте также:  Html css шаблон визитка
Оцените статью