Welcome to the Java UTIL project site. This is the central place for general information about the project itself, the different libraries
that are being developed as well as documentation, examples and other helpful resources. Below is an overview of a few of the common
libraries provided.
This provides common API's and frameworks used by most if not all of the other libraries. One of the main apects of this library is the
VirtualArtifact framework. This attempts to provide an abstract layer over the normal
File framework provided by the JVM. All the other libraries attempt to avoid dealing with
File framework, and rather use the virtual one, which allows any type of implementation to be
used with the other libraries when dealing with I/O operations or files and directories in general.
Some of the benefits of using this virtual I/O framework are as follows:
- File and directory abstraction allows file system, memory, archives, remote systems among others to be interacted with interchangeably
- The virtual I/O framework allows for adapters to be added to for providing custom output/input, for instance encryption
- Most file and directory related operations are greatly facilitated
- Generally all Virtual Artifact objects are not tied to a static internal directory
- Option to create one or more Virtual Artifact System's in order to allow valid internal URL's
- The VirtualDirectory extension supports the visitor pattern
For example, there is a network library that currently has support for easy SSH based interaction
(using the JSCH library) but integrated with the virtual I/O framework thus making any
operations with remote files using SFTP a sinch, as the example below shows:
SFTP with Virtual I/O FrameworkToggle Line Numbers | 1
package net.sourceforge.javautil.site.example; 2
3
import java.io.IOException; 4
import java.net.URL; 5
6
import net.sourceforge.javautil.common.URLStreamHandlerFactoryComposite; 7
import net.sourceforge.javautil.common.io.VirtualDirectory; 8
import net.sourceforge.javautil.common.io.impl.SystemDirectory; 9
import net.sourceforge.javautil.common.io.remote.RemoteLocation; 10
import net.sourceforge.javautil.common.password.Password; 11
import net.sourceforge.javautil.common.password.impl.UnencryptedPassword; 12
import net.sourceforge.javautil.network.ssh.SecureShell; 13
14
15
@link 16
17
@author 18
@author 19
@version 20
21
public class SFTPVirtualIOExample { 22
23
public static void main (String[] args) throws IOException { 24
25
26
27
28
29
30
31
32
33
34
35
36
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactoryComposite()); 37
38
SecureShell ssh = new SecureShell(); 39
Password password = new UnencryptedPassword("password"); 40
RemoteLocation remote = ssh.createLocation("some.host", 22, "user", password, "/home/user"); 41
42
VirtualDirectory target = new SystemDirectory("target"); 43
target.makeDirectories(); 44
45
46
47
remote.getRootDirectory().copy(target, true); 48
49
} 50
51
}
|
A class loader library was made for two reasons. One to work with the above Virtual I/O framework and another to allow an abstract class package
based loader with an extensible API. Also the logic for class loader heiarchy is separated from the class loader implementation, which means that
you can easily manipulate the class loader heiarchy logic without the need to write or develop another class loader implementation.
The library comes with two different types of class source API's. One is called ClassSource and the other is called
ClassDependencyPool. Both can be used with the ClassLoader implementation called
ClassContext.
Along with the same library there is a Maven integration library which allows for using pom.xml's to boot an application without any dependency on the
Maven libraries.
Along side the above mentioned ClassLoader API is a Boot strapping API. The main class is called EntryPoint. It
comes with a Maven implementation to look for a pom.xml and use it to create an application specific class loader after which a main class can be
specified. EntryPoint's can be chained allowing various levels of boot strapping.
The only library that this class loader library relies on is the commons library. Which means with both these libraries in your class path you can
boot an application with a single application jar and all it's dependencies declared in a pom.xml. If the dependencies are not currently in the
local maven repository they are searched for and the user is given the option to authorize their download. On the command line you could do the
following (assuming you are using the 0.0.5 versions of these libraries):
C:\Dev\Java\apps\myapp>java -cp '.;commons-0.0.5.jar;classloader-0.0.5.jar;myappjar.jar' -Dnet.sf.javautil.main=some.application.Main net.sourceforge.javautil.classloader.boot.EntryPoint
The above will look for a pom.xml, which you can place in the same directory, and it will use that to create an application class loader from which
it will attempt to load the some.application.Main and invoke the appropriate method, which is normally the
static void main (String[] args) {} method.
But what about setting up your own class loader, and integration with the Virtual I/O framework? The following example can illustrate this:
Class Loader Configuration ExampleToggle Line Numbers | 1
package net.sourceforge.javautil.site.example; 2
3
import net.sourceforge.javautil.classloader.impl.ClassContext; 4
import net.sourceforge.javautil.classloader.impl.StandardClassLoaderHeiarchy; 5
import net.sourceforge.javautil.classloader.resolver.ClassDependencyPool; 6
import net.sourceforge.javautil.classloader.resolver.ClassPackageResolver; 7
import net.sourceforge.javautil.classloader.resolver.ClassPackageUtil; 8
import net.sourceforge.javautil.classloader.resolver.impl.ClassPackageDependencyReferenceImpl; 9
import net.sourceforge.javautil.classloader.resolver.impl.ClassPackageReferenceImpl; 10
import net.sourceforge.javautil.classloader.resolver.impl.maven.MavenRepositoryUtil; 11
import net.sourceforge.javautil.classloader.source.VirtualDirectoryClassSource; 12
import net.sourceforge.javautil.common.ClassNameUtil; 13
import net.sourceforge.javautil.common.io.VirtualArtifact; 14
import net.sourceforge.javautil.common.io.VirtualArtifactUtil; 15
import net.sourceforge.javautil.common.io.VirtualDirectory; 16
import net.sourceforge.javautil.common.io.impl.Directory; 17
import net.sourceforge.javautil.common.io.impl.DirectoryRoot; 18
import net.sourceforge.javautil.common.io.impl.SimplePath; 19
import net.sourceforge.javautil.common.io.impl.SystemDirectory; 20
21
22
23
24
@author 25
@author 26
@version 27
28
public class ClassContextExample { 29
30
public static void main (String[] args) { 31
32
33
34
35
36
ClassDependencyPool pool = ClassPackageUtil.createStandardDependencyPool("main", true); 37
38
39
ClassPackageResolver resolver = MavenRepositoryUtil.createStandardResolver(); 40
41
42
43
44
ClassPackageUtil.append(pool, resolver, true, new ClassPackageDependencyReferenceImpl("some.group.id", "some.artifact.id", "version", null)); 45
46
47
ClassContext cl = new ClassContext(new StandardClassLoaderHeiarchy(), pool); 48
49
50
51
52
Directory linkable = new DirectoryRoot(); 53
54
55
linkable.link(new SystemDirectory("some/path/to/classes")); 56
linkable.link(new SystemDirectory("some/other/path/to/classes")); 57
58
59
Directory pkg = (Directory) linkable.getDirectory("net/sourceforge/javautil/site/example"); 60
61
62
pkg.link(VirtualArtifactUtil.getResource(ClassContextExample.class, ClassNameUtil.toRelativeClassPath(ClassContextExample.class.getName()))); 63
64
65
66
ClassContext acl = new ClassContext(new StandardClassLoaderHeiarchy(), pool, new VirtualDirectoryClassSource(linkable)); 67
68
} 69
70
}
| |