Fork me on GitHub

JCR Shell

Introduction

JCR Shell provides a command-line tool to get access to a remote JCR Webdav Server which provides JCR API access over WebDAV/HTTP(S).

JCR Shell is a pure JCR/Jackrabbit based client tool. Therefore, this tool should work against any Apache Jackrabbit based JCR system.

If you want to use JCR Shell against Hippo CMS, enable JCR Webdav Server in the system. See Hippo Repository JCR/WebDAV Support forge project homepage for detail.

Download

You can download an executable JAR file of JCR Shell from Bloomreach Forge Maven repository: https://maven.onehippo.com/maven2-forge/org/onehippo/forge/jcrshell/jcrshell/. Move to the latest version directory and download jcrshell-x.x.x.jar from there.

Run

You can run JCR Shell like the following:

$ java -jar jcrshell-2.0.0.jar --server="http://localhost:8080/cms/server" --user="admin:admin"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

JCR Shell 2.0.0

exit or quit leaves program.
help lists commands.
jcr-shell:> 

        

Available Commands

You can execute help to see all the available commands with descriptions.

jcr-shell:> help
----------------------------------------------------------------------------------------------------------------
Command             Usage                                                                           
----------------------------------------------------------------------------------------------------------------
aliases             aliases                                                                         
cd                  cd [<path>|<reference property>]                                                
cdprev              cdprev                                                                          
cduuid              cduuid <uuid>                                                                   
credentials         credentials <username>                                                          
exit                exit                                                                            
filecd              filecd <path>                                                                   
filelist            filelist [<directory>]                                                          
filepwd             filepwd <path>                                                                  
findreferences      findreferences                                                                  
finduuid            finduuid <uuid>                                                                 
help                help [<command>]                                                                
jexl                jexl <path> [<argument> [..]]                                                   
login               login                                                                           
logout              logout                                                                          
ls                  ls [<path>]                                                                     
mixinadd            mixinadd <mixin type>                                                           
mixinlist           mixinlist                                                                       
mixinremove         mixinremove <mixin type>                                                        
namespaceadd        namespaceadd <prefix> <uri>                                                     
namespacelist       namespacelist                                                                   
namespaceremove     namespaceremove <prefix>                                                        
nodeadd             nodeadd <nodename> [<type>]                                                     
nodeallowed         nodeallowed                                                                     
nodecheckin         checkin                                                                         
nodecheckout        checkout                                                                        
nodecopy            nodecopy <nodename> <target parent>/[name]                                      
nodediff            nodediff <nodeame> [<path>/]<base>                                              
nodeexport          nodeexport <nodename> <xml file> [<skipBinaries>]                               
nodeimport          nodeimport <xml file> [<uuidBehavior> [<referenceBehavior> [<mergeBehavior>]]]  
nodemove            nodemove <nnodeame> [<path>/]<new nodename>                                     
noderemove          noderemove <nodename>                                                           
nodetree            nodetree [<levels>]                                                             
nodetypeget         nodetypeget <name>                                                              
nodetypelist        nodetypelist [<primary|mixin>]                                                  
order               order <child node> (before|after|up|down|first|last) [<child node>]             
propadd             propadd <property> [<type>]                                                     
propallowed         propallowed                                                                     
propdelete          propdelete <property> [<property> [..]]                                         
propget             propget <property> [<property> [..]]                                            
proplist            proplist [<node>]                                                               
propload            propload <binary property> <file>                                               
propset             propset <property> <value> [<type>]                                             
propstore           propstore <binary property> <file>                                              
pwd                 pwd                                                                             
query               query <sql|xpath> <statement> [limit <count>]                                   
refresh             refresh                                                                         
reset               reset                                                                           
save                save                                                                            
server              server [<http(s)_url>]                                                          
sessionsave         sessionsave                                                                     
status              status                                                                          
syspropget          syspropget [<property>]                                                         
syspropset          syspropset <property> <value>                                                   
valueadd            valueadd <propertyname> <value> [<type>]                                        
valueremove         valueremove <property> <value> [<type>]                                         
versioncd           versioncd <uuid>                                                                
versioncreate       versioncreate [<label>]                                                         
versiondiff         versiondiff [version [<otherversion>]]                                          
versioninfo         versioninfo [<version>]                                                         
versionlabeladd     versionslabeladd <version> <label> [<true|false>]                               
versionlabelremove  versionslabelremove <label>                                                     
versionlist         versionlist                                                                     
versionremove       versionremove <version>|<label>                                                 
versionremoveall    versionremoveall                                                                
versionrestore      versionrestore <version>|<label> [<true|false>]                                 
versiontree         versiontree [<levels>]                                                          
----------------------------------------------------------------------------------------------------------------
Command completed in 27 msecs.
jcr-shell:> 

        

You can execute help <command> to see the detail of the specific command like the following example:

jcr-shell:> help pwd
Usage: pwd
   Show path to current node
Command completed in 0 msecs.

        

Example Usage Session - Setting a property

In this section, let's try to change a property value and save it, as an example.

jcr-shell:> cd /webfiles/site

done.
Command completed in 879 msecs.

admin:/webfiles/site> proplist
----------------------------------------------------------------------------------------------------------------
Name                Type    Value            
----------------------------------------------------------------------------------------------------------------
jcr:primaryType     Name    webfiles:bundle  
webfiles:anticache  String  1538775596692    
----------------------------------------------------------------------------------------------------------------
Command completed in 55 msecs.

admin:/webfiles/site> propset webfiles:anticache 1538775596694
Command completed in 0 msecs.

admin:/webfiles/site> propget webfiles:anticache 
1538775596694
Command completed in 25 msecs.

admin:/webfiles/site> save
Node saved.
Command completed in 31 msecs.

jcr-shell:> quit
Bye bye!

        

jexl command

The jexl command allows you to execute a JEXL script file for more advanced use cases.

The following variables are provided to JEXL script files:

Variable Description
arguments The command line arguments passed to the JEXL script. The first argument is the file path of the JEXL script, followed by other arguments for the JEXL script. For example, if you run > jexl test.jexl 1 2 3, then the arguments variable will look like [ "test.jexl", "1", "2", "3" ].
out The output console, providing #println(CharSequence) method for JEXL scripts
node The JCR node you are currently based on in the shell.

Here's a very simple JEXL script file example:

// ~/temp/test.jexl
var nu = new("org.apache.commons.lang3.math.NumberUtils");
var sum = 0;
for (arg : arguments) {
  // 0 on parsing error as the first arg item is actually the jexl script file name.
  sum += nu.toInt(arg, 0);
}
out.println("sum = " + sum);
out.println("You're currently on " + node.path + ".");
return "Optional return value to show after execution: Hello!";
        

Then you can execute the JEXL script file like this:

admin:/> cd content/documents
admin:...nt/documents> jexl ~/temp/test.jexl 1 2 3 4 5 6 7 8 9
sum = 45
You're currently on /content/documents.
JEXL script executed. Return: Optional return value to show after execution: Hello!
Command completed in 3 msecs.

        

For more information about the JEXL syntax, see JEXL Syntax page.

Extra JARs for your JEXL scripts or others

If you need to depend on any additional JAR files, not included in the jcrshell-x.x.x.jar by default, you can use Spring Boot's loader.path system property to add any extra JARs to the classpath.

For example, the following will add all the JAR files found in lib/ directory when executing the JCR Shell:

$ java -Dloader.path="lib/" \
       -jar jcrshell-2.0.0.jar \
       --server="http://localhost:8080/cms/server" \
       --user="admin:admin"

        

Run Batch Commands

You can execute a batch file containing one or multiple lines of each command explained above as well by specifying --batch argument like the following example:

$ java -jar jcrshell-2.0.0.jar --server="http://localhost:8080/cms/server" --user="admin:admin" --batch="test.sh"

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.4.RELEASE)

JCR Shell 2.0.0
...
        

If you specify a batch file by --batch argument, then JCR Shell will read all the non-blank lines from the file except of comment lines.

If a line in a batch file starts with "#", the line is regarded as a comment.