Source Code Cross Referenced for JarBuilder.java in  » XML-UI » XUI » net » xoetrope » builder » editor » ant » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » XUI » net.xoetrope.builder.editor.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 01-Dec-2003
003:         *
004:         * To change the template for this generated file go to
005:         * Window>Preferences>Java>Code Generation>Code and Comments
006:         */
007:        package net.xoetrope.builder.editor.ant;
008:
009:        import java.io.File;
010:        import java.io.FileInputStream;
011:        import java.io.FileOutputStream;
012:        import java.io.IOException;
013:        import java.util.jar.JarEntry;
014:        import java.util.jar.JarOutputStream;
015:
016:        import net.xoetrope.builder.editor.ant.taskdefs.Jar;
017:
018:        /**
019:         * Class to generate a jar file for distribution. Includes class files, screens
020:         * and resources. Uses Ant to build so the Ant jar file needs to be included in
021:         * the classpath. The version of Ant used for initial development was 1.5.
022:         */
023:        public class JarBuilder {
024:
025:            public JarBuilder() {
026:            }
027:
028:            /**
029:             * Build the jar for the project including classes, screens and resources
030:             * @param fileName The name of the jar file to be built
031:             * @param rootDir the root directory of the project
032:             */
033:            public void buildJar(String fileName, String rootDir) {
034:                createBuildDir(rootDir);
035:                Jar jar = new Jar();
036:                try {
037:                    JarOutputStream jos = new JarOutputStream(
038:                            new FileOutputStream(rootDir + "\\build\\"
039:                                    + fileName));
040:                    jos.setLevel(0);
041:                    //      jar.initZipOutputStream( jos );
042:                    zipDir(jos, jar, rootDir + "\\classes", "");
043:                    zipDir(jos, jar, rootDir + "\\pages", "");
044:                    zipDir(jos, jar, rootDir + "\\resources", "");
045:                    jos.flush();
046:                    jos.close();
047:                } catch (Exception ex) {
048:                    ex.printStackTrace();
049:                }
050:            }
051:
052:            /**
053:             * recursive function which builds up the directory based on the new directory
054:             * name found
055:             * @param zos ZippedOutputStream for the jar file
056:             * @param jar the Ant Jar object used for writing out the file streams
057:             * @param rootDir the root directory for the files (the project root)
058:             * @param dir the offset dir being build up (as in the case of packages)
059:             */
060:            public void zipDir(JarOutputStream jos, Jar jar, String rootDir,
061:                    String dir) {
062:                try {
063:                    File folder = new File(rootDir + File.separatorChar);
064:                    File[] files = folder.listFiles();
065:                    for (int i = 0; i < files.length; i++) {
066:                        if (files[i].isDirectory()) {
067:                            zipDir(jos, jar, files[i].getAbsolutePath(), dir
068:                                    + files[i].getName() + "\\");
069:                        } else {
070:                            putJarEntry(jos, files[i], dir + files[i].getName());
071:                        }
072:                    }
073:                } catch (Exception ex) {
074:                    ex.printStackTrace();
075:                }
076:            }
077:
078:            private void putJarEntry(JarOutputStream jos, File f, String dir) {
079:                try {
080:                    JarEntry je = new JarEntry(dir);
081:                    jos.putNextEntry(je);
082:                    FileInputStream bais = new FileInputStream(f);
083:
084:                    byte b[] = new byte[1024];
085:                    byte fileBytes[];
086:                    int len = bais.read(b);
087:                    while (len > -1) {
088:                        fileBytes = new byte[len];
089:                        System.arraycopy(b, 0, fileBytes, 0, len);
090:                        jos.write(fileBytes, 0, len);
091:                        b = new byte[1024];
092:                        len = bais.read(b);
093:                    }
094:                    jos.closeEntry();
095:                } catch (IOException ex) {
096:                    ex.printStackTrace();
097:                }
098:            }
099:
100:            /**
101:             * Create the build directory
102:             * @param rootDir The project root directory
103:             */
104:            private void createBuildDir(String rootDir) {
105:                File file = new File(rootDir + "\\build");
106:                try {
107:                    file.mkdir();
108:                } catch (Exception ex) {
109:                    ex.printStackTrace();
110:                }
111:            }
112:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.