1.what
i need write cross domain profile in my java server with spring.
2.how
after spring web 4.2.2,can simple write below code in spring-mvc.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd>
<!-- other code -->
<mvc:cors>
<mvc:mapping path="/**" allowed-origins="*"
allowed-methods="*"
allowed-headers="*"
exposed-headers="X-Requested-With, X-PKRSS-Token" allow-credentials="true"
max-age="36000" />
</mvc:cors>
</beans>
x.Last
Thanks readed~_~
Monday, September 12, 2016
tomcat manager with eclipse maven deploy profile
1. what
my java web server is tomcat 9 m9,with tomcat manager,i can deploy web app war with eclipse maven menu,or by tomcat manager web,or by script.
2. how
2.1 install tomcat 9
# yum install -y java wget
# mkdir ~/download
# cd ~/download
# wget -c http://mirrors.cnnic.cn/apache/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz
# tar -zxvf apache-tomcat-9.0.0.M9.tar.gz
# mv apache-tomcat-9.0.0.M9 /usr/local/tomcat9
# vi /etc/profile
export TOMCAT_HOME=/usr/local/tomcat9
export CATALINA_HOME=/usr/local/tomcat9
# source /etc/profile
(6)
# vi /usr/local/tomcat9/conf/tomcat-users.xml
<role rolename="tomcat"/>
<role rolename="manager-script"/>
<user username="manager" password="123456" roles="manager-gui"/>
<user username="script" password="123456" roles="manager-script"/>
# mkdir -p /usr/local/tomcat9/conf/Catalina/localhost/
# vi /usr/local/tomcat9/conf/Catalina/localhost/manager.xml
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow=".*" />
</Context>
# only for my project profile, every can skip this.
# vi /usr/local/tomcat9/conf/server.xml
replace:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
with:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000" useBodyEncodingForURI="true" URIEncoding="UTF-8"
# vi /usr/local/tomcat9/conf/catalina.properties
shared.loader=${catalina.base}/shared/*.jar
# vi /usr/local/tomcat9/conf/logging.properties
1catalina.org.apache.juli.AsyncFileHandler.level = OFF
2localhost.org.apache.juli.AsyncFileHandler.level = OFF
java.util.logging.ConsoleHandler.level = OFF
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = WARN
# mkdir /usr/local/tomcat9/shared/
upload our project's lib to this folder.
# only for my project lib, every can skip this.
copy mapper-x.x.x.jar mysql-connector-java-x.x.x.jar /usr/local/tomcat9/lib/
# vi /etc/init.d/tomcat
#!/bin/bash
#
# ldl 120449427@qq.com
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "/atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
CATALINA_HOME="/usr/local/tomcat9"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
restart)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
# chmod 755 /etc/init.d/tomcat
chkconfig tomcat on
# chkconfig --add tomcat
# chown -R ec2-user /usr/local/tomcat9/webapps
== crontab -e
0 0 * * * rm -rf /usr/local/tomcat9/logs/*20*
# by new version cent os firewall,not for iptables firewall-cmd --permanent --add-port=80-80/tcp
firewall-cmd --permanent --add-port=843-843/tcp
firewall-cmd --permanent --add-port=8080-8081/tcp
2.2 setting for maven profile pom.xml
<project>
<!-- ... -->
<profiles>
<profile>
<id>b</id>
<build>
<finalName>ROOT</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>log4j.properties</exclude>
<exclude>local.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/profile/b</directory>
<includes>
<include>log4j.properties</include>
<include>local.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7-maven-plugin.version}</version>
<configuration>
<url>http://my server ip/manager/text</url>
<path>/ROOT</path><!-- ##${maven.build.timestamp} --><!-- Tip: your can deploy multiple version with same app by tomcat support with timestamp version. -->
<username>script</username>
<password>123456</password>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
2.3 run as maven right menus:
Eclipse > project explorer > Run as > Run configurations > Maven build > new:
Name: clean install b
Base directory: your project directory
Goals: clean install
Profiles: b
It means shell: $ mvn clean install -P b
Eclipse > project explorer > Run as > Run configurations > Maven build > new:
Name: tomcat7 redeploy
Base directory: your project directory
Goals: tomcat7:redeploy
Profiles: b
It means shell: $ mvn tomcat7:redeploy -P b
2.4 run
Eclipse > project explorer > Run as > Maven build > clean install b
Eclipse > project explorer > Run as > Maven build > tomcat7 redeploy
or
Eclipse > project explorer > Run as > Maven build > clean install b
web browser access: http://my server ip/manager/html/ ,type with username: manager password: 123456
Select WAR file to upload: your project directory/target/ROOT.war
Click Depoly.
X Last
Thanks~_~
my java web server is tomcat 9 m9,with tomcat manager,i can deploy web app war with eclipse maven menu,or by tomcat manager web,or by script.
2. how
2.1 install tomcat 9
# yum install -y java wget
# mkdir ~/download
# cd ~/download
# wget -c http://mirrors.cnnic.cn/apache/tomcat/tomcat-9/v9.0.0.M9/bin/apache-tomcat-9.0.0.M9.tar.gz
# tar -zxvf apache-tomcat-9.0.0.M9.tar.gz
# mv apache-tomcat-9.0.0.M9 /usr/local/tomcat9
# vi /etc/profile
export TOMCAT_HOME=/usr/local/tomcat9
export CATALINA_HOME=/usr/local/tomcat9
# source /etc/profile
(6)
# vi /usr/local/tomcat9/conf/tomcat-users.xml
<role rolename="tomcat"/>
<role rolename="manager-script"/>
<user username="manager" password="123456" roles="manager-gui"/>
<user username="script" password="123456" roles="manager-script"/>
# mkdir -p /usr/local/tomcat9/conf/Catalina/localhost/
# vi /usr/local/tomcat9/conf/Catalina/localhost/manager.xml
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow=".*" />
</Context>
# only for my project profile, every can skip this.
# vi /usr/local/tomcat9/conf/server.xml
replace:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
with:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000" useBodyEncodingForURI="true" URIEncoding="UTF-8"
# vi /usr/local/tomcat9/conf/catalina.properties
shared.loader=${catalina.base}/shared/*.jar
# vi /usr/local/tomcat9/conf/logging.properties
1catalina.org.apache.juli.AsyncFileHandler.level = OFF
2localhost.org.apache.juli.AsyncFileHandler.level = OFF
java.util.logging.ConsoleHandler.level = OFF
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = WARN
# mkdir /usr/local/tomcat9/shared/
upload our project's lib to this folder.
# only for my project lib, every can skip this.
copy mapper-x.x.x.jar mysql-connector-java-x.x.x.jar /usr/local/tomcat9/lib/
# vi /etc/init.d/tomcat
#!/bin/bash
#
# ldl 120449427@qq.com
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "/atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
CATALINA_HOME="/usr/local/tomcat9"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
restart)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
# chmod 755 /etc/init.d/tomcat
chkconfig tomcat on
# chkconfig --add tomcat
# chown -R ec2-user /usr/local/tomcat9/webapps
== crontab -e
0 0 * * * rm -rf /usr/local/tomcat9/logs/*20*
# by new version cent os firewall,not for iptables firewall-cmd --permanent --add-port=80-80/tcp
firewall-cmd --permanent --add-port=843-843/tcp
firewall-cmd --permanent --add-port=8080-8081/tcp
2.2 setting for maven profile pom.xml
<project>
<!-- ... -->
<profiles>
<profile>
<id>b</id>
<build>
<finalName>ROOT</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>log4j.properties</exclude>
<exclude>local.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/profile/b</directory>
<includes>
<include>log4j.properties</include>
<include>local.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${tomcat7-maven-plugin.version}</version>
<configuration>
<url>http://my server ip/manager/text</url>
<path>/ROOT</path><!-- ##${maven.build.timestamp} --><!-- Tip: your can deploy multiple version with same app by tomcat support with timestamp version. -->
<username>script</username>
<password>123456</password>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
2.3 run as maven right menus:
Eclipse > project explorer > Run as > Run configurations > Maven build > new:
Name: clean install b
Base directory: your project directory
Goals: clean install
Profiles: b
It means shell: $ mvn clean install -P b
Eclipse > project explorer > Run as > Run configurations > Maven build > new:
Name: tomcat7 redeploy
Base directory: your project directory
Goals: tomcat7:redeploy
Profiles: b
It means shell: $ mvn tomcat7:redeploy -P b
2.4 run
Eclipse > project explorer > Run as > Maven build > clean install b
Eclipse > project explorer > Run as > Maven build > tomcat7 redeploy
or
Eclipse > project explorer > Run as > Maven build > clean install b
web browser access: http://my server ip/manager/html/ ,type with username: manager password: 123456
Select WAR file to upload: your project directory/target/ROOT.war
Click Depoly.
X Last
Thanks~_~
Subscribe to:
Posts (Atom)