知识大全 用shell和java实现自动部署

Posted 文件

篇首语:对所学知识内容的兴趣可能成为学习动机。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 用shell和java实现自动部署相关的知识,希望对你有一定的参考价值。

  公司用到了rackspace的cloudserver 做为压力测试的服务器 但是一旦启动就开始收费 一个小时 刀 因此要求用的时候打开 不用的时候关掉

  但是遇到一个问题就是 这样的话在上边部署应用程序和软件就比较麻烦了 不能每次都重新部署吧 那样效率太低了 因此想到写一些脚本进行自动的部署 其他的都好办 但是有些需要修改xml文件和properties文件的 用shell实现起来就费力了

  既然是java的应用就用java来实现吧 用了一下午写好了 下边我把修改properties和xml的代码贴出来 希望对大家有所帮助

   修改properties文件

  package util xml;

  import java io File;

  import java io FileInputStream;

  import java io FileOutputStream;

  import java io IOException;

  import java util List;

  import java util Properties;

  import java util Date;

  import java text SimpleDateFormat;

  import java util ArrayList;

  import java util List;

  public class ModifyPropertiesFile

  public String propertyFilePath= remoting_client properties ;

  public String stagingIp= ;

  public String messageIp= ;

  public void modifyPropertiesFile()

  

  try

  Properties p = new Properties();

  File f = new File(propertyFilePath);

  List<String> list = new ArrayList<String>();

  list add(stagingIp);

  list add(messageIp);

  if(f exists() && f isFile())

  

  FileInputStream fis;

  fis = new FileInputStream(f);

  p load(fis);

  p setProperty( service online url socket:// +list get( )+ : );

  p setProperty( ssage url socket:// +list get( )+ : );

  p setProperty( service account url socket:// +list get( )+ : );

  p setProperty( service order url socket:// +list get( )+ : );

  p setProperty( service party url socket:// +list get( )+ : );

  p setProperty( service product url socket:// +list get( )+ : );

  p setProperty( service webimgateway url socket:// +list get( )+ : );

  p setProperty( service dirtyword url socket:// +list get( )+ : );

  FileOutputStream   oFile   =   new   FileOutputStream(f);

  p store(oFile );

  fis close();

  oFile close();

  

  

  catch (Exception e)

  

  e printStackTrace();

  e getMessage();

  System out println( Can t modify this properties file please check your program again!!!! );

  

  

  public   static   void   main(String   args[])

  

  ModifyPropertiesFile  t=new  ModifyPropertiesFile();

  t modifyPropertiesFile();

  

  

   修改xml文件

  package util xml;

  import java io File;

  import java io FileInputStream;

  import java io FileOutputStream;

  import java io IOException;

  import java util List;

  import java util Properties;

  import java util Date;

  import java text SimpleDateFormat;

  import jdom Document;

  import jdom Element;

  import jdom JDOMException;

  import jdom input SAXBuilder;

  import jdom output XMLOutputter;

  import jdom output Format;

  import jdom xpath XPath;

  import apache log j Logger;

  import xml sax EntityResolver;

  import xml sax InputSource;

  import xml sax SAXException;

  import java util HashMap;

  import java util Iterator;

  public class ModifyHibernateXml

  private String dataBaseInfo;

  private String userName;

  private String userPass;

  private String deploymentTitle;

  private String c p max_size;

  private String fileName;

  //defind propertis file name

  public String propertyFilePath= ModifyXml properties ;

  public  void  modifyXml()

  

  try

  

  Properties p = new Properties();

  HashMap<String String> map=new HashMap<String String>();

  map put( xmlFileName propertyFilePath);

  File f = new File(map get( xmlFileName ));

  // load properties value from properties file

  if(f exists() && f isFile())

  

  FileInputStream fis;

  fis = new FileInputStream(f);

  p load(fis);

  dataBaseInfo   =p getProperty( nnection url );

  userName       =p getProperty( nnection username );

  userPass       =p getProperty( nnection password );

  deploymentTitle=p getProperty( deployment title );

  c p max_size  =p getProperty( hibernate c p max_size );

  fileName       =p getProperty( nfigrtion path );

  fis close();

  

  SAXBuilder builder = new SAXBuilder();

  Document doc = builder build(fileName);

  Element root = doc getRootElement();

  XMLOutputter xmlOutputer = new XMLOutputter();

  builder setValidation(false);

  builder setEntityResolver(new EntityResolver()

  public InputSource resolveEntity(String publicId

  String systemId) throws SAXException IOException

  return new InputSource( /hibernate configuration dt

  d );

  

  );

  // use XPath search your need node

  List list = XPath selectNodes(root /hibernate configuration/session factory/property );

  for(int i = ;i<list size();i++)

  

  Element disk_element = (Element) list get(i);

  String name= disk_element getAttributue( name );

  if  (name equals( connection url ))

  

  System out println( database connection info + +name);

  disk_element setText(dataBaseInfo);

  

  else if (name equals( connection username ))

  

  System out println( database connection username + +name);

  disk_element setText(userName);

  

  else if (name equals( connection password ))

  

  System out println( database connection password + +name);

  disk_element setText(userPass);

  

  else if (name equals( c p max_size ))

  

  System out println( database max connnection is  +c p max_size);

  disk_element setText(c p max_size);

  

  

  //      If you want to take out blank line you can unment format mect

  //      Format format = Format getPrettyFormat();

  //      format setEncoding( UTF );

  //      xmlOutputer setFormat(format);

  xmlOutputer output(doc new FileOutputStream(fileName));

  catch (Exception e)

  

  e printStackTrace();

  e getMessage();

  System out println( Can t modify xml file please check your program again!!!! );

  

  

  public static void main(String[] args)

  

  ModifyHibernateXml  hibernate =new ModifyHibernateXml();

  hibernate modifyXml();

  

  

   最后可以写一个总的类 来调用以上两个类 实现模块话 厉害吧就几个文件还来了一个模块化

  package util xml;

  public class CloudServer

  

  public   static   void   main(String   args[])

  

  ModifyPropertiesFile  t=new  ModifyPropertiesFile();

  t modifyPropertiesFile();

  ModifyHibernateXml  hibernate =new ModifyHibernateXml();

  hibernate modifyXml();

  

cha138/Article/program/Java/hx/201311/26690

相关参考

知识大全 启动Java应用的Shell脚本

启动Java应用的Shell脚本  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  对于Java应用

知识大全 Java执行Shell&Command

Java执行Shell&Command  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  主要使用R

知识大全 防止同一个Java应用重复启动的shell脚本

防止同一个Java应用重复启动的shell脚本  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  通

知识大全 tomcat中部署java项目

  在Tomcat中部署JavaWeb应用程序有两种方式静态部署和动态部署在下文中$CATALINA_HOME指的是Tomcat根目录  一静态部署  静态部署指的是我们在服务器启动之前部署我们的程序

知识大全 .NET应用自动部署窗体技术详解(2)

.NET应用自动部署窗体技术详解(2)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  五NET和

知识大全 用自动ftp提高工作效率

  自动FTP的SHELL脚本结合数据库的系统管理它有很多用途可以提高你的工作效率    用途:把数据库的逻辑备份或者其它关键的文件传到另一个地区实现远端备份    (例如从北京机房的传到上海机房) 

知识大全 如何使用Java网络启动部署软件

如何使用Java网络启动部署软件  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  Java网络启动

知识大全 Java环境变量定制应用部署

Java环境变量定制应用部署  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  有时当我们编写JEE

知识大全 .NET应用自动部署窗体技术详解(4)

.NET应用自动部署窗体技术详解(4)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  七部署NE

知识大全 用PHP+java实现自动新闻滚动窗口

用PHP+java实现自动新闻滚动窗口  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  showp