Monday, June 19, 2017

Angular Js


Angular js is mainly used to build single page application . It is based on MVC architecture.
  1. model The form fields act as model , we need to use ng-model attribute to specify the model name.
  2. view The HTML page is the view , which is being displayed to the user
  3. controller We can create a JavaScript function which will be the controller


There are 3 most important components of angular js.
  1. application
  2. controller
  3. service

Common Errors:
Error: [$injector:unpr] Unknown provider: myServiceProvider
 When you see this error you need to check if have my service defined for your application.
Click on the buttons inside the tabbed menu:
angular.module("home",home); var home=function (){ }

Wednesday, June 14, 2017

Gradle

Hi Guys,
I have started learning cradle and this blog will help you getting familiar with gradle.

Gradle is a build tool where in you can have a project comprising of tasks.
Your build related details will be mentioned in build.gradle file .
By default the folder name is the rootProject  name if you want to configure it change in settings.gradle file.
End.

rootProject=org.myProject

The project inside the root project will be the subProject .
You can specify the dependency in build.gradle as

If you want to use a repository you can use the repository to define it.
repository {
maven{
url "http://testRepo.org"
}
}

Saturday, June 10, 2017

Wildfly 10


Hi Guys, I have started using Wildfly 10 sometime back and here is my guide on how to successfully configure wildfly 10. First of all download it from site.
http://wildfly.org/downloads/
Now, check if you have JAVA in the environment variables .Make sure it is pointed to Java 8.
echo %JAVA%
C:\Program Files\Java\jdk1.8.0_91\jre\bin\java.exe
open command prompt ,goto Wildfly\bin and type the following command
standalone.bat -Djboss.home.dir=\softwares\wildfly_10\wildfly-10.1.0.Final -Djboss.server.config.dir=\softwares\wildfly_10\wildfly-10.1.0.Final\standalone\configuration
If you are using powershell type the following command
.\standalone.bat -Djboss.home.dir=\softwares\wildfly_10\wildfly-10.1.0.Final -Djboss.server.config.dir=\softwares\wildfly_10\wildfly-10.1.0.Final\standalone\configuration
Note : you need to change the path to the path where wildfly installation is.
If you face the following error while starting

Unable to read the logging configuration from 'file:F:\shahbaz\softwares\wildfly_10\wildfly-10.1.0.Final\standalone/logging.properties' (java.io.FileNotFoundException: F:\shahbaz\softwares\wildfly_10\wildfly-10.1.0.Final\standalone\logging.properties (The system cannot find the file specified))
change the -Djboss.server.config.dir to the proper config path.
To find out which port number the http server is running , open standalone.xml and check the following attribute.
<socket-binding name="http" port="${jboss.http.port:8090}"/>
Once you start wildfly hit the following URL http://localhost:8090

Click on admin console and then you might see the following screen.
Run add-user.bat and set the username and password for application as well as management realm

Goto the home page after adding the users

Done with the server configuration . Now you can start playing with the server. So,Lets create a simple application and deploy .We will have a index page which will display a message on load.
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <display-name>My App </display-name>
</web-app>
<html>
<body>
Hi ,
This is my app.
</body>
</html>
Now build the war file which will be deployed . Type the following command in the console.
"C:\Program Files\Java\jdk1.8.0_91\bin\jar" -cvf myApp.war *
Once you have the war file ready you can deploy it using wildfly admin console.Follow the steps to deploy a war file.
Deploy the selected war file
Lets create servlet jsp project and deploy it.
package org.myApp;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.myApp.TempConvertor;

public class Converter extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
try{
String farenhiet=request.getParameter("farenhiet");
if(farenhiet != null ){
String celcius=TempConvertor.farenhietToCelcius(Float.parseFloat(farenhiet));
request.setAttribute("celcius",celcius);
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/conv/result.jsp");
requestDispatcher.forward(request,response);
}
}catch(Exception e){
e.printStackTrace();
RequestDispatcher requestDispatcher=request.getRequestDispatcher("/conv/error.jsp");
requestDispatcher.forward(request,response);
}

}
public void doPost(HttpServletRequest request,HttpServletResponse response){
}
}
public class TempConvertor
{
public static String farenhietToCelcius(float farenhiet){
float celcius =(farenhiet -32 )*5/9;
return String.valueOf(celcius);
}
}
Your code here.
you can start it using eclipse, if you face the following error you need to change the Java installations.
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jboss/modules/Main : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

ec2-user@ec2 Permission denied