美丽涵涵童装店--说我博客名字,给你们打折!
随笔 - 82  文章 - 266  trackbacks - 0
<2007年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234


点击这里给杨爱友发消息
美丽涵涵童装店
说我博客名字,给你们打折!

常用链接

留言簿(6)

随笔分类

随笔档案

文章档案

好友的BLOG

搜索

  •  

最新评论

阅读排行榜

评论排行榜

一、安装ANT工具
       所谓安装其实就是下载下来解压,最后解压到C盘。当然要配置环境变量。如解压到C:/ant,那么ANT_HOME="c:/ant",path="c:/ant/bin"。

二、配置biuld.xml
      讲究很多,属性很多,介绍它的文章也非常多,这里我举出一个最简单的例子,也是我第一次使用ANT时的配置。
       <project name="mySite" basedir="." default="compile">
             <path id="lib">
                  <fileset dir="G:/docfiles/mySite/WEB-INF/lib/">
                       <include name="**/*.jar"/>
                  </fileset>
             </path>
      
             <target name="compile" depends="">
                  <javac srcdir="G:/docfiles/mySite/src" destdir="G:/docfiles/mySite/WEB-INF/classes" classpathref="lib"/>
               </target>
     </project>
   
         参数说明:
                    <project/>为根目录,里面的name="mySite"为要编译项目的名字;default属性定义ANT默认要执行的
            任务,在这里就是javac,编译。
            <fileset/>里的 dir值为项目中用到的jar根目录;<include name="**/*.jar"/>包含里面所有.jar包。
            <javac/>里的srcdir为要进行编译的java文件的根目录,destdir为编译好后的class文件放的位置。

三、运行
            在dos窗口找到ant/bin,直接输入ant运行。

----------------------------------------------------------------------------------------------
fileUpload组件实现图象上传
FormFile file = imageForm.getFilePath();//取得上传的文件
  try {
      InputStream stream = file.getInputStream();//把文件读入输入流
      java.awt.Image image = ImageIO.read(stream);//创建image对象,这样就可以对图象进行各种处理
      //计算长宽
      int toWidth =500;//默认值
      int toHeigh = 500;
      String tempWidth = request.getParameter("width");//接受前台指定图象的大小值
      String tempHeight = request.getParameter("height");
      if(!"".equals(tempWidth) && tempWidth != null){
          toWidth = Integer.valueOf(tempWidth);
      }
      if(!"".equals(tempHeight) && tempHeight != null){
          toHeigh = Integer.valueOf(tempHeight);
      }
      int old_w = image.getWidth(null); //得到源图像的宽
      int old_h = image.getHeight(null);
      int new_w = 0;//缩略后的图象宽
      int new_h = 0; 
      float ratioWidth = old_w/toWidth;//宽的缩放比例
      float ratioHeight = old_h/toHeigh;//高的缩放比例
      if(ratioWidth > ratioHeight){//要保证缩放后的图象长宽都不能大于目标长宽,所以除以比例大的数值
       new_w = Math.round(old_w / ratioWidth);
       new_h = Math.round(old_h / ratioWidth);
      }else{
       new_w = Math.round(old_w / ratioHeight);
       new_h = Math.round(old_h / ratioHeight);
      }
      //长宽处理结束
      BufferedImage tag = new BufferedImage(new_w, new_h,BufferedImage.TYPE_INT_RGB);
      tag.getGraphics().drawImage(image, 0, 0, new_w, new_h, null); //绘制缩放后的图
      String currentDirPath = request.getSession().getServletContext().getRealPath("/Upload/Image");//要上传到服务器上的
      位置,即当前路径+Upload/Image
      String oldeName = imageForm.getFilePath().getFileName();//带扩展名的鸭图象的名字
      String newName = getFileName(oldeName);//新图象名,由系统当前年+月+日+小时+分+秒+毫秒+四为随机数
      +原扩展名组成,保证大部分情况下不会出现重名问题
      String savePath = currentDirPath + "/" + newName;
      OutputStream bos = new FileOutputStream(savePath);//创建输出流
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
      encoder.encode(tag); //近JPEG编码
      int bytesRead = 0;
      byte[] buffer = new byte[8192];
      while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
       bos.write(buffer, 0, bytesRead);//将文件写入服务器
      }
      bos.close();
      stream.close();
     }catch(Exception e){
      System.err.print(e);
  }
posted on 2007-07-13 17:11 杨爱友 阅读(2495) 评论(5)  编辑  收藏 所属分类: java相关技术

FeedBack:
# re: 迄今为止,最简单的ANT编译实例 2007-07-24 11:45 飘摇
......飘过
......飘过
.......飘过
........飘过
........飘过
........飘过
.......飘过
......飘过
.....飘过
....飘过
...飘过
..飘过
.飘过
.飘过
.飘过
..飘过
...飘过
....飘过
.....飘过
......飘过
.......飘过
........飘过
........飘过
........飘过
.......飘过
......飘过
.....飘过
....飘过
...飘过
..飘过
.飘过
.飘过
.飘过
..飘过
...飘过
....飘过
.....飘过
......飘过
.......飘过
........飘过
........飘过
........飘过
.......飘过
......飘过
.....飘过
....飘过
...飘过
..飘过
.飘过
.飘过
.飘过
..飘过
...飘过
....飘过
.....飘过
......飘过
.......飘过
........飘过
........飘过
........飘过
.......飘过
......飘过
.....飘过
....飘过
...飘过
..飘过
.飘过
.飘过
.飘过
..飘过
...飘过
....飘过
.....飘过
......飘过
.......飘过
........飘过
........飘过
........飘过
.......飘过
......飘过
.....飘过
  回复  更多评论
  
# re: 迄今为止,最简单的ANT编译实例 2007-07-25 12:26 杨爱友
太酷了  回复  更多评论
  
# re: 迄今为止,最简单的ANT编译实例 2007-07-27 13:34 小祝
可真够飘的。。。
爱友,要更新了啊,天天记到打球。  回复  更多评论
  
# re: 迄今为止,最简单的ANT编译实例[未登录] 2007-07-28 10:40 小祝
生活平淡,没学新东西,没得写
  回复  更多评论
  
# re: 迄今为止,最简单的ANT编译实例 2007-08-09 15:11 cresposhi
漂的够有曲线。。。
更新啊更新啊  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
美丽涵涵童装店
亲,说我博客名字,给你们打折!