How to use JHlabs image filter in spring MVC project

First you have to create image filter class like this

public class ImageFilter {
public void applyFilter(MultipartFile multipartFile){
String destination = “/your/file/destination/folder/”;
try {
GaussianFilter filter = new GaussianFilter();
filter.setRadius(8.5f);
BufferedImage imBuff = ImageIO.read(multipartFile.getInputStream());
filter.filter(imBuff, imBuff);

File outputfile = new File(destination+”image.jpg”);
ImageIO.write(imBuff, “jpg”, outputfile);

} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

And then modify the request mapping method for file upload in your controller like this

@RequestMapping(method = RequestMethod.POST)
public String fileUploaded(Model model, @Validated File file,
BindingResult result) {

String returnVal = “successFile”;
if (result.hasErrors()) {
returnVal = “file”;
} else {
MultipartFile multipartFile = file.getFile();
SaveFileToFolder save = new SaveFileToFolder();
save.saveFile(multipartFile);
}
return returnVal;
}

After running the blurred image will be stored in the location you specified.

How to Set the Name of Your Maven Build File as That of Your Project Name

When you use Maven build tool, by default, the package file created will be named based on the artifactid and the version that you give. For example, lets say you added the following in your project’s pom.xml file :

<artifactId>myproject</artifactId>

<version>1.0.0-SNAPSHOP</version>

<packaging>war</packaging>

<name>Order</name>

Now your resultant package created will be something like this :

myproject-1.0.0-SNAPSHOP.war

Now, if you want to prevent this and make the package file created to have the name as that of the artifactid, then you will have to add the following inside your “build” tag.

<build>

<finalName>${project.artifactId}</finalName>

</build>

Now if you build the project, the resultant package file generated will be as follows :

myproject.war

Different Phases Involved in the Maven Site

Maven is a dependency management and build tool for Java projects. The site command will generate the documentation of the current project. This command can be executed in different phases.

– pre-site : This can be executed separately or when you execute site command.

– site : In this phase, the current project documentation will be generated.

– post-site : This will be executed after the execution of site phase.

– site-deploy : This phase will be used to deploy the documentation created.

Different Phases Involved in the Maven Clean

Maven is a dependency management and build tool for Java projects. The clean command will clean up the artifacts or packages created by prior builds. This command can be executed in different phases.

– pre-clean : This can be executed separately or when you execute clean command.

– clean : In this phase, the project’s target folder will be cleaned by removing all the artefacts and packages created by prior builds.

– post-clean : This will be executed after the execution of clean phase.

How to Locate the Builds Created in Maven Local Repository

Maven is a dependency management and build tool for Java projects. When you create the build of a package using the Maven tool, then a copy of the build will be copied to the local maven repository in your system as well. Here is how you can locate the the same on your local maven repository.

The location or placement of the build in your local maven repository will depend on the artifact id, group id and version that you gave for that build by default. For example, lets say you gave the group id, artifact id and version for your project like this :

<groupId>com.mycompany</groupId>

<artifactId>myproject</artifactId>

<version>1.0</version>

Now if you want to locate this build in your local maven repository follow these steps :

1. Go to your local maven repository folder. It will be the .m2 folder in your User’s root folder in your system.

2. Inside this folder, you will see another folder called repository. Go to that folder.

3. Now if you already built your project, there will be one folder with name “com”. Go to that folder.

4. Inside, you will see another folder named “mycompany”. Go to that folder.

5. Inside, you will see another folder named “myproject”, which is the value you gave as your artifactid. Go to that folder.

6. Inside, you will see another folder named “1.0”, which is the value you gave as your build version. Go to that folder.

7. Inside this folder, you will see the project build file you were looking for. The name of the file will be “myproject-1.0.war” if your packaging is “war” and it will be “myproject-1.0.jar” if your packaging is “jar”.

Please note that if this file will be created only if your Maven build for the project is successful.

Different Phases Involved in the Compilation of Package using Maven

Maven is a dependency management and build tool for Java projects. The compile command will execute the creation of a package in different phases. They are

– Validate : In this phase, Maven will validate and see whether the project is correct and all the necessary informations are available.

– generate-sources : In this phase, the source files will be created.

– process-sources : In this phase, the source code will be processed, like filter any value.

– generate-resources : In this phase, the resources will be generated.

– process-resources : In this phase, the generated resources will be processed.

– compile : In this phase, the actual compilation of the code based on the processed sources and processed resources will happen.

Additional Maven Lifecycle Phases

Maven is a dependency management and build tool for Java projects. Here are the additional lifecycle phases involved with Maven apart from the default ones : validate, compile, test, package, integration-test, verify, install, deploy.

– clean – In this phase, the artifacts or packages created by prior builds are cleaned up.

– site – In this phase, the site documentation for the current project is generated.

These are the additional phases involved with Maven.

Default Maven Lifecycle Phases

Maven is a dependency management and build tool for Java projects. There are various phases involved in Maven build tool, which are referred to as the lifecycle phases. Here are the default lifecycle phases involved with Maven.

– validate : In this phase, the project will be validated to be correct and will validate that all necessary informations are available.

– compile : In this phase, the source code of the project will be generated, processed and compiled.

– test : In this phase, the testing of compiled code will be done using configured until testing framework.

– package : In this phase, the compiled code will online slots be packaged into its distributable form.

– integration-test : In this phase, the package will be processed and deployed if necessary into an environment where the integration tests can be run.

– verify : In this phase, checks will be performed to verify whether the package is valid and meets quality criteria.

– install : In this phase, the package will be installed into local Maven repository, which in turn can be used as a repository.

– deploy : In this phase, the final package will be deployed to remote repository. This will be done in an integration or release environment.

These are the default phases involved with Maven.

How to Build a Java Project Using Maven Command Line

Maven is a dependency management and build tool for Java projects. It also provides command line tools to perform various operations.

The maven command for command line implementation is “mvn”. First you can try executing the following command to check whether Maven is setup correctly in your system.

> mvn —version

This will display the maven version installed on your system.

Once you confirm that maven is installed, you can execute the following command to build and package the java project you created.

> mvn package

This will package your project into the format specified in the pom.xml file.

Sample Code to Copy Contents of One File to Another in Java

Here is a java method to copy the contents of a file to another in java using byte streams.

public void CopyFile throws IOException

{

FileInputStream fin = null;

FileOutputStream fout = null;

try {

fin = new FileInputStream("inputfile.txt");

fout = new FileOutputStream("outputfile.txt");

 

int tempChar;

while ((tempChar = fin.read()) != -1) {

out.write(tempChar);

}

}finally {

if (fin != null) {

fin.close();

}

if (fout != null) {

fout.close();

}

}

}

This method will do. Here you should import java.io.* inorder to compile the code. This method uses byte streams for the file I/O operations. In this, when the tempChar value becomes -1, that means the end of file.