我有一个Spring + Maven项目,我想在Tomcat 7.0.69上运行。 当我通过脚本执行它一切正常。这是准备脚本:
#!/bin/bash
PROFILE=$1
CONFIG_REPO=../../configuration
DEPLOY_DIR=tomcat-deploy
WAR_PREFIX=ppp-web/
WAR_NAME=ppp$(echo $PROFILE | tr '[:upper:]' '[:lower:]').war
validate_profile() {
if [[ $PROFILE != 'AS' && $PROFILE != 'TN' && $PROFILE != 'HS' ]]; then
echo "Incorrect application profile chosen: $PROFILE. Use TN, AS or HS."
exit 1
fi
}
validate_environment_settings() {
if [[ -z "$CATALINA_HOME" ]]; then
echo -e "\e[1;31m"
echo -e "ERROR: ***************************************************************************************"
echo -e "ERROR: *** You must set CATALINA_HOME environment variable before trying to deploy Tomcat. ***"
echo -e "ERROR: ***************************************************************************************"
echo -e "\e[0m"
exit 1
fi
}
setup_deploy_dir () {
echo "Setting up deploy directory $DEPLOY_DIR ..."
rm -rf $DEPLOY_DIR
mkdir -p $DEPLOY_DIR/bin
mkdir -p $DEPLOY_DIR/conf
mkdir -p $DEPLOY_DIR/lib
mkdir -p $DEPLOY_DIR/logs
mkdir -p $DEPLOY_DIR/temp
mkdir -p $DEPLOY_DIR/webapps
mkdir -p $DEPLOY_DIR/webapps-conf
mkdir -p $DEPLOY_DIR/webapps-lib
mkdir -p $DEPLOY_DIR/work
cp $CATALINA_HOME/bin/tomcat-juli.jar $DEPLOY_DIR/bin/
}
copy_if_exists () {
local src=$1
local dest=$2
if [[ -e $src ]]; then
echo "-> Copying file $src to $dest ..."
cp -r $src $dest
else
echo "-> Directory or file $src does not exist. Skipped."
fi
}
copy_to_correct_directories () {
local src=$1
local f
for f in $src/*; do
if [[ $f == */conf ||\
$f == */webapps-conf ||\
$f == */bin ||\
$f == */install-additional-libs.xml ]]; then
copy_if_exists $f $DEPLOY_DIR
else
# any other file is copied to application configuration directory
copy_if_exists $f $DEPLOY_DIR/webapps-conf
fi
done
}
prepare_configuration () {
local app=$1
local env=$2
local box=$3
local instance=$4
echo "Preparing configuration ..."
copy_to_correct_directories $CONFIG_REPO/common $DEPLOY_DIR
copy_to_correct_directories $CONFIG_REPO/$app/common $DEPLOY_DIR
copy_to_correct_directories $CONFIG_REPO/$app/$env/common $DEPLOY_DIR
copy_to_correct_directories $CONFIG_REPO/$app/$env/$box/common $DEPLOY_DIR
copy_to_correct_directories $CONFIG_REPO/$app/$env/$box/$instance $DEPLOY_DIR
}
create_instance_name () {
local instance=$1
echo "Creating instance.name.properties file ..."
echo "instance.name = $instance" > $DEPLOY_DIR/webapps-conf/instance.name.properties
}
install_additional_libs () {
echo "Installing additional libs ..."
mvn -f $DEPLOY_DIR/install-additional-libs.xml dependency:copy
}
copy_war () {
echo "Copying $WAR_NAME ..."
cp ${WAR_PREFIX}target/$WAR_NAME $DEPLOY_DIR/webapps/
}
validate_profile
validate_environment_settings
setup_deploy_dir
prepare_configuration PPP-${PROFILE} LOCAL localhost PPP${PROFILE}-LOCAL
create_instance_name PPP${PROFILE}-LOCAL
install_additional_libs
copy_war
这是我的运行脚本:
#!/bin/bash
validate_environment_settings() {
if [[ -z "$CATALINA_HOME" ]]; then
echo -e "\e[1;31m"
echo -e "ERROR: ***************************************************************************************"
echo -e "ERROR: *** You must set CATALINA_HOME environment variable before trying to deploy Tomcat. ***"
echo -e "ERROR: ***************************************************************************************"
echo -e "\e[0m"
exit 1
fi
}
start_tomcat_windows() {
cmd /Q << EOF
set CATALINA_BASE=%cd%\\tomcat-deploy
%CATALINA_HOME%\\bin\\startup.bat
EOF
}
start_tomcat_unix() {
export CATALINA_BASE=$(pwd)/tomcat-deploy
$CATALINA_HOME/bin/startup.sh
}
start_tomcat() {
local system=$(uname -s)
case $system in
MINGW*)
start_tomcat_windows
;;
Linux|CYGWIN*)
start_tomcat_unix
;;
*)
echo "Unsupported system: $system"
exit 1
esac
}
validate_environment_settings
start_tomcat
正如我之前所说,当我从cmd做的时候一切正常。但是当我试图从IntelliJ Idea 2016.2运行它时,我收到了错误:
org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [eps.properties] cannot be opened because it does not exist
文件eps.properties位于PROJECT \ profiles-ppp \ tomcat-deploy \ webapps-conf。
对它的引用位于applicationContext.xml:
<context:property-placeholder location="classpath:eps.properties,classpath:ppp-mom.properties,classpath*:*instance.name.properties,classpath:ppp.db.properties"/>
VM选项包括:
-Xmx1024m
-XX:MaxPermSize=512m
有谁能告诉我,我做错了什么?提前谢谢。