Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Date;
- import java.io.FileWriter;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.lang.SecurityException;
- public class CreateMavenDirs{
- public boolean createMavenDirs(String filename) throws IOException, SecurityException{
- File newFile = null;
- FileWriter newFileWriter = null;
- BufferedWriter newBufferedWriter = null;
- Long timestamp = new Date().getTime();
- boolean status = true;
- String[] listOfFiles = {"LICENSE.txt", "NOTICE.txt", "README.txt", "pom.xml"};
- String[] listOfDirs = {"src/main/assembly","src/main/config","src/main/filters","src/main/java","src/main/resources/META-INF","src/main/webapp/WEB-INF","src/site","src/test/filters","src/test/java","src/test/resources",};
- String projectName = filename + "_" + timestamp;
- String groupID="com.hostname";
- String projectVersion="1.0";
- String pomFill="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n\t<modelVersion>4.0.0</modelVersion>\n\t<groupId>" + groupID + "." + projectName + "</groupId>\n\t<artifactId>" + projectName + "</artifactId>\n\t<name>${artifactId}</name>\n\t<version>" + projectVersion + "</version>\n</project>";
- // Create the main project directory
- newFile = new File(projectName);
- status = newFile.mkdir();
- // Create all of the subdirectories
- for(String dir : listOfDirs){
- newFile = new File(projectName + "/" + dir);
- status = newFile.mkdirs();
- }
- // Create all of the files
- for(String file : listOfFiles){
- newFile = new File(projectName + "/" + file);
- status = newFile.createNewFile();
- }
- // Populate the pom.xml file
- newFileWriter = new FileWriter(projectName + "/pom.xml");
- newBufferedWriter = new BufferedWriter(newFileWriter);
- newBufferedWriter.write(pomFill);
- newBufferedWriter.flush();
- newBufferedWriter.close();
- return status;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement