In this post I’ll show you how to use a Maven archetype - or more specifically the TrueVFS Archetype Access - to generate a bunch of sample applications for TrueVFS. I’m using NetBeans 7.2 for this post, but similar actions apply to Eclipse, IntelliJ IDEA or whatever, so please read on.
Fire up NetBeans and select File -> New Project...
:
In the upcoming dialog, select Maven -> Project from Archetype
and click Next
:
On the next tab, enter the group-id net.java.truevfs
, the artifact-id truevfs-archetype-access
, the version 0.9.1
and click Next
:
On the next tab, accept the default property values and click Finish
.
In the output window, you should see something like this:
cd C:\Users\christian\Documents\NetBeansProjects; JAVA_HOME=C:\\Program Files\\Java\\jdk1.7.0_07 M2_HOME=C:\\Program Files\\Apache Software Foundation\\apache-maven-3.0.4 \C:\\Program Files\\Apache Software Foundation\\apache-maven-3.0.4\\bin\\mvn.bat\ -DarchetypeGroupId=net.java.truevfs -DarchetypeArtifactId=truevfs-archetype-access -DarchetypeVersion=0.9.1 -DarchetypeRepository=local -DgroupId=com.company -DartifactId=mavenproject1 -Dversion=1.0-SNAPSHOT -Dpackage=com.company.mavenproject1 -Dbasedir=C:\\Users\\christian\\Documents\\NetBeansProjects -Dtruevfs-version=0.9.1 -Dscala-version=2.9.2 -Darchetype.interactive=false --batch-mode archetype:generate<br />Scanning for projects...
------------------------------------------------------------------------
Building Maven Stub Project (No POM) 1
------------------------------------------------------------------------
>>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>>
<<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<<
[[archetype:generate]]
Generating project in Batch mode
Archetype defined by properties
----------------------------------------------------------------------------
Using following parameters for creating project from Archetype: truevfs-archetype-access:0.9.1
----------------------------------------------------------------------------
Parameter: groupId, Value: com.company
Parameter: artifactId, Value: mavenproject1
Parameter: version, Value: 1.0-SNAPSHOT
Parameter: package, Value: com.company.mavenproject1
Parameter: packageInPathFormat, Value: com/company/mavenproject1
Parameter: package, Value: com.company.mavenproject1
Parameter: version, Value: 1.0-SNAPSHOT
Parameter: truevfs-version, Value: 0.9.1
Parameter: scala-version, Value: 2.9.2
Parameter: groupId, Value: com.company
Parameter: artifactId, Value: mavenproject1
project created from Archetype in dir: C:\Users\christian\Documents\NetBeansProjects\mavenproject1
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 3.103s
Finished at: Wed Sep 05 19:35:57 CEST 2012
Final Memory: 8M/21M
------------------------------------------------------------------------
Next, right click on the generated project and select Set as Main Project
.
Right click again and select Properties -> Run
.
In the upcoming dialog, click Browse
next to the text field for the main class and select
com.company.mavenproject1.java.diagnostics.DriverMap2Html
:
Now simply press Run Main Project
(F6 on Windows).
In the output window, you should see something like this:
cd C:\Users\christian\Documents\NetBeansProjects\mavenproject1; JAVA_HOME=C:\\Program Files\\Java\\jdk1.7.0_07 M2_HOME=C:\\Program Files\\Apache Software Foundation\\apache-maven-3.0.4 \C:\\Program Files\\Apache Software Foundation\\apache-maven-3.0.4\\bin\\mvn.bat\ -Dexec.args=-classpath %classpath com.company.mavenproject1.java.diagnostics.DriverMap2Html -Dexec.executable=C:\\Program Files\\Java\\jdk1.7.0_07\\bin\\java.exe -Dexec.classpathScope=runtime process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec
Scanning for projects...
------------------------------------------------------------------------
Building mavenproject1 1.0-SNAPSHOT
------------------------------------------------------------------------
[[resources:resources]]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\christian\Documents\NetBeansProjects\mavenproject1\src\main\resources
[[scala:add-source]]
Add Source directory: C:\Users\christian\Documents\NetBeansProjects\mavenproject1\src\main\scala
Add Test Source directory: C:\Users\christian\Documents\NetBeansProjects\mavenproject1\src\test\scala
[[scala:compile]]
C:\Users\christian\Documents\NetBeansProjects\mavenproject1\src\main\java:-1: info: compiling
C:\Users\christian\Documents\NetBeansProjects\mavenproject1\src\main\scala:-1: info: compiling
Compiling 15 source files to C:\Users\christian\Documents\NetBeansProjects\mavenproject1\target\classes at 1346867208355
prepare-compile in 0 s
compile in 3 s
[[compiler:compile]]
Compiling 12 source files to C:\Users\christian\Documents\NetBeansProjects\mavenproject1\target\classes
[[exec:exec]]
SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
<?xml version=1.0 encoding=UTF-8?>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en>
<head>
<title>File System Driver Map</title>
</head>
<body>
<table border=2 cellpadding=4>
<thead>
<tr>
<th>URI Schemes</th>
<th>File System Driver</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>tar</code></td>
<td><code>net.java.truevfs.comp.tardriver.TarDriver@770d2e[archiveDriver=true, charset=windows-1252, redundantContentSupport=true, redundantMetaDataSupport=false, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>ear</code>, <code>jar</code>, <code>war</code></td>
<td><code>net.java.truevfs.comp.zipdriver.JarDriver@cd43ce[archiveDriver=true, charset=UTF-8, redundantContentSupport=true, redundantMetaDataSupport=true, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>zip</code></td>
<td><code>net.java.truevfs.comp.zipdriver.ZipDriver@1eb0c6[archiveDriver=true, charset=IBM437, redundantContentSupport=true, redundantMetaDataSupport=true, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>file</code></td>
<td><code>net.java.truevfs.driver.file.FileDriver@e7b3f2[archiveDriver=false]</code></td>
</tr>
<tr>
<td><code>http</code>, <code>https</code></td>
<td><code>net.java.truevfs.driver.http.HttpDriver@1d709a5[archiveDriver=false]</code></td>
</tr>
<tr>
<td><code>odb</code>, <code>odc</code>, <code>odf</code>, <code>odg</code>, <code>odi</code>, <code>odm</code>, <code>odp</code>, <code>ods</code>, <code>odt</code>, <code>otc</code>, <code>otf</code>, <code>otg</code>, <code>oth</code>, <code>oti</code>, <code>otp</code>, <code>ots</code>, <code>ott</code></td>
<td><code>net.java.truevfs.driver.odf.OdfDriver@ba6c13[archiveDriver=true, charset=UTF-8, redundantContentSupport=true, redundantMetaDataSupport=true, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>tar.bz2</code>, <code>tar.bzip2</code>, <code>tb2</code>, <code>tbz</code>, <code>tbz2</code></td>
<td><code>net.java.truevfs.driver.tar.bzip2.TarBZip2Driver@10d9151[archiveDriver=true, charset=windows-1252, redundantContentSupport=true, redundantMetaDataSupport=false, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>tar.gz</code>, <code>tar.gzip</code>, <code>tgz</code></td>
<td><code>net.java.truevfs.driver.tar.gzip.TarGZipDriver@1bf68a9[archiveDriver=true, charset=windows-1252, redundantContentSupport=true, redundantMetaDataSupport=false, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>tar.xz</code>, <code>txz</code></td>
<td><code>net.java.truevfs.driver.tar.xz.TarXZDriver@1706eb7[archiveDriver=true, charset=windows-1252, redundantContentSupport=true, redundantMetaDataSupport=false, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
<tr>
<td><code>tzp</code>, <code>zip.rae</code>, <code>zip.raes</code></td>
<td><code>net.java.truevfs.driver.zip.raes.SafeZipRaesDriver@74db2c[archiveDriver=true, charset=UTF-8, redundantContentSupport=true, redundantMetaDataSupport=true, pool=net.java.truevfs.driver.file.FileBufferPool@126c6ea]</code></td>
</tr>
</tbody>
</table>
</body>
</html>
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 6.966s
Finished at: Wed Sep 05 19:46:53 CEST 2012
Final Memory: 12M/31M
------------------------------------------------------------------------
What happened is that the DriverMap2Html
class scans the class path for all file system driver modules and prints the
resulting mapping to HTML.
This may come in handy for diagnosing the “Heck, why wasn’t my archive file recognized by TrueVFS?” sort of issues.
That’s it for now. Next time we’ll take a look at some statistics provided by the TrueVFS Kernel. Meanwhile you may want to explore the generated archetype.
Enjoy!