问题
When i run karaf, i need to install some features into it. For that i give commands like:
install -s mvn:org.apache.derby/derby/10.8.2.2
feature:install jndi jpa transaction http
I want to automate this thing as i want to start karaf by itself on reboot. I have read that i can start it on reboot by using wrapper:service. But next question to my mind is how will i give these commands.
I have read that it can be done using etc/shell.init.script. But i am not able to understand examples given on scripting page of karaf site.
Last lines on shell.init.script file in my karaf is:
help = { *:help $args | more } ;
man = { help $args } ;
log:list = { log:get ALL } ;
Should i simply write these commands below these lines, or i need to write some functions like given on scripting page ( one is given below) of which i have no idea.
#
# Add a value at the end of a property in the given OSGi configuration
#
# For example:
# > config-add-to-list org.ops4j.pax.url.mvn org.ops4j.pax.url.mvn.repositories http://scala-tools.org/repo-releases
#
config-add-to-list = {
config:edit $1 ;
a = (config:property-list | grep --color never $2 | tac) ;
b = (echo $a | grep --color never "\b$3\b" | tac) ;
if { ($b trim) isEmpty } {
if { $a isEmpty } {
config:property-set $2 $3
} {
config:property-append $2 ", $3"
} ;
config:update
} {
config:cancel
}
}
回答1:
After studying some more concepts and doing some hit and trail i found these commands can be written in the script but, it has to be specified with its package( i dont know what to call it a package or a bundle)
These commands can be given in this form:
bundle:install -s mvn:org.apache.derby/derby/10.8.2.2
feature:install jndi jpa transaction http
shell:echo "in script"
回答2:
You can add features (and feature repos) to install at startup in 'org.apache.karaf.features.cfg' under the featuresRepositories and featuresBoot sections.
来源:https://stackoverflow.com/questions/29599037/script-to-run-commands-at-start-of-apache-karaf