jmsktm
James' weblog
7 posts
@jmsktm
Don't wanna be here? Send us removal request.
jmsktm · 11 years ago
Text
List of Java EE 7 annotations
These annotations are taken from the book 'Beginning Java EE 7' by Antonio Goncalves (APress book).
cat <filename> | grep -o -P "[@][a-zA-Z0-9]+" | sort | uniq > annotations.txt
@Access @AccessTimeout @ActivationConfigProperty @Added @After @AfterClass @agoncal @all @Alternative @ApplicationException @ApplicationPath @ApplicationScoped @apress @archiveDate @AroundConstruct @AroundInvoke @AroundTimeout @AssertTrue @Asynchronous @AttributeOverride @AttributeOverrides @Basic @Before @BeforeClass @Cacheable @ChronologicalDates @CollectionTable @Column @ConcurrencyManagement @Constraint @Consumes @Context @ConversationScoped @CookieParam @CreditCard @DataSourceDefinition @DecimalMin @DeclareRoles @Decorator @Default @DefaultValue @Delegate @DELETE @DenyAll @Dependent @DependsOn @DiscriminatorColumn @DiscriminatorValue @Disposes @Documented @EightDigits @EightOddDigits @EJB @ElementCollection @Email @Embeddable @Embedded @EmbeddedId @Entity @EntityListeners @Enumerated @Even @ExcludeClassInterceptors @ExcludeDefaultListeners @ExcludeSuperclassListeners @FacesConverter @FacesValidator @FlowScoped @form @FormParam @Future @Generated @GeneratedValue @GET @gmail @GreaterThanZero @HEAD @HeaderParam @Id @IdClass @Ignore @Inheritance @Inherited @Inject @Interceptor @InterceptorBinding @Interceptors @interface @item @javax @JMSConnectionFactory @JMSConnectionFactoryDefinition @JMSDestinationDefinition @JMSPasswordCredential @JMSSessionMode @JoinColumn @JoinTable @Lob @Local @LocalBean @Lock @Loggable @mail @ManyToMany @ManyToOne @MapKeyColumn @MappedSuperclass @MatrixParam @Max @me @MessageDriven @Min @Model @MusicGenre @Named @NamedNativeQuery @NamedQueries @NamedQuery @NamedStoredProcedureQuery @New @none @NotNull @NumberOfDigits @Observes @Odd @OneToMany @OneToOne @OneWay @OPTIONS @OrderBy @OrderColumn @Override @Past @Path @PathParam @Pattern @PermitAll @PersistenceContext @PersistenceUnit @PersistentUnit @POST @PostActivate @PostConstruct @PostContruct @PostLoad @PostPersist @PostRemove @PostUpdate @PreDestroy @PreLoad @PrePassivate @PrePersist @PreRemove @PreUpdate @Price @Priority @Produces @Provider @PUT @Qualifier @quantity @QueryParam @Random @Remote @Remove @Removed @ReportAsSingleViolation @RequestScoped @Resource @Retention @RolesAllowed @RunAs @Schedule @Schedules @Scope @SecondaryTable @SecondaryTables @SessionScoped @Singleton @Size @SOAPBinding @SOAPMessageHandler @springer @Startup @Stateful @StatefulTimeout @Stateless @StaticMetamodel @Stereotype @StoredProcedureParameter @Table @Target @Temporal @TenDigits @Test @ThirteenDigits @this @Timeout @Transactional @TransactionAttribute @TransactionManagement @TransactionScope @Transient @TwoDigits @TwoEvenDigits @TwoOddDigits @UniqueConstraint @URL @USA @Version @Vetoed @ViewScoped @warehouseCode @WebFault @WebMethod @WebParam @WebResult @WebService @WebServiceRef @WithAnnotations @XmlAccessorType @XmlAttribute @XmlElement @XmlElements @XmlEnum @XmlEnumValue @XmlID @XmlIDREF @XmlList @XmlMimeType @XmlNs @XmlRootElement @XmlSchema @XmlSeeAlso @XmlTransient @XmlType @XmlValue @ZipCode
0 notes
jmsktm · 11 years ago
Text
Install Oracle Java8 on Ubuntu 12.04
If installing on a remote instance, connect using SSH.
To add the repository:
sudo apt-add-repository ppa:webupd8team/java
To bring in the changes to repository, perform an update.
sudo apt-get update
Install Oracle Java 8.
sudo apt-get install oracle-java8-installer
To install, you will be taken through several screens, and agree to Java terms and conditions etc.
Java 8 is now installed on the instance. To verify, check for java version.
java - version
That's it. Done! Java installation folder is at: /usr/lib/jvm/java-8-oracle
0 notes
jmsktm · 11 years ago
Text
Auto-Deploy JSF Maven Project on Amazon EC2 using Jenkins
To start with, we have a JavaServer Faces (JSF) project set up on Apache Maven. A git repo has also been set up for the project on Github.
Firstly, we need to setup an Amazon EC2 instance on AWS, and then install Jenkins on the instance. However, there's an easy way around that. We can directly install an Amazon EC2 instance consisting of Jenkins from Amazon marketplace.
Link: https://aws.amazon.com/marketplace/pp/B008ASDQO6
Navigate to the above webpage and login with AWS credentials. Click the Continue button.
Tumblr media
Select EC2 Instance Type as Standard Micro (t1.micro; which is free tier eligible). In the key-pair section, select the key pair that you created earlier (More on key-pair in another post). Click on Launch with One Click button to launch the instance.
The instance was assigned an existing Elastic IP 54.83.62.123 so that the IP does not change on server/instance restart. More on Elastic IP in another post.
Once the instance is running, open the site (IP: 54.83.62.123) which will display Jenkins by default. Click Access My Application button.
Tumblr media
Login to Jenkins Administrative console. After logging in, navigate to Manage Jenkins > Configure System.
Under JDK section, provide JDK name and JAVA_HOME path. If Java was installed as per the instruction provided in the next post, set the values to java-8-oracle and /usr/lib/jvm/java-8-oracle respectively. If not installed already, install, and fill up the text fields.
In the Git section, select the Install Automatically checkbox.
In Maven section, select the Install Automatically checkbox. Click on Save button to save the configuration.
Tumblr media
On the homepage (after login), click the New Job link, and select Build a maven2/3 project in the page displayed next. Provide jsf-maven as job name.
Tumblr media
In the resulting project page, click on 'Configure' to configure the job/project.
Under Source Code Management section, select Git checkbox and provide git repository URL (Eg. https://github.com/james-singh/jsf-maven-project.git in http://jmsktm.tumblr.com/post/84060336059/how-to-setup-code-repository-in-github)
Under Build Triggers, check the Build whenever a SNAPSHOT dependency is built checkbox.
Again, under Build Triggers, check Poll SCM Schedule and type * * * * * in the textarea to indicate Jenkins to poll the git repository every minute. Whenever Jenkins finds any changes in the repository, it will then build, test and deploy the application.
Click the Save button.
Tumblr media
To build the project manually for the first time, click Build now under the job/project page. Build will now start, and the progress can be seen as a progress bar on the left side of the page.
Tumblr media
Click the progress bar / Build item on the Build History box. This will lead you to another page.
On the build page, click on Console Output link.
Tumblr media
The resulting page gives console output for the build. The very first that a Maven project is built, it download all required maven dependencies and other resources, and takes a while to complete. That might take from a couple of minutes to an hour depending upon internet speed available to the instance.
Tumblr media
We can understand a few things from the build result: Building in workspace /opt/bitnami/apps/jenkins/jenkins_home/jobs/jsf-maven/workspace -> This shows the path to your workspace. Fetching upstream changes from https://github.com/james-singh/jsf-maven.git -> This gives the path to Git repository. Checking out Revision 16909b600daeadf354435613a02bce686b8db69b (origin/master) -> This shows the branch that was built (origin/master) Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -> The status of test cases. Here, both the test cases passed successfully. [INFO] BUILD SUCCESS -> Build was successful. Finished: SUCCESS -> All the things that was expected to run during this build completed successfully.
Now we need to deploy this built project on Glassfish, which I will cover later.
0 notes
jmsktm · 11 years ago
Text
Connect to Amazon EC2 instance from Linux command prompt
To connect to Amazon EC2 instance from Linux command prompt, you need to have the URI of the EC2 instance (possibly the Elastic IP assigned to the instance), and the keypair. Connection is made with SSH command.
Through Terminal (Linux command line), navigate to the folder where where the .pem file resides. Make sure that the file has permission set to 600 (or rw- --- ---). If it's not, use chmod to set it using: chmod 600 jsf-maven-project.pem
Tumblr media
Connect to the server using the below command:
ssh -i jsf-maven-project.pem [email protected]
Where, 54.83.62.123 is the IP of the server, and ubuntu is the username.
Tumblr media
If you want to install new updates, use the command:
sudo apt-get update
And you're done! :)
0 notes
jmsktm · 11 years ago
Text
Setting up an EC2 instance on Amazon Web Services
As per Wikipedia -
Amazon Web Services (abbreviated AWS) is a collection of remote computing services (also called web services) that together make up a cloud computing platform, offered over the Internet by Amazon.com.
As for Amazon EC2,
Amazon Elastic Compute Cloud (EC2) is a central part of Amazon.com's cloud computing platform, Amazon Web Services (AWS). EC2 allows users to rent virtual computers on which to run their own computer applications. EC2 allows scalable deployment of applications by providing a Web service through which a user can boot an Amazon Machine Image to create a virtual machine, which Amazon calls an "instance", containing any software desired. A user can create, launch, and terminate server instances as needed, paying by the hour for active servers, hence the term "elastic".
If you want to use AWS, it offers one year of free limited (but sufficient) usage of EC2 services to new users. You would require Credit/Debit card and a mobile phone number (Doesn't need to be a US number) to activate it.
After you have created the account, arrive at the AWS Management console.
Tumblr media
Then navigate to EC2 > Instances to arrive at this screen. I already have few EC2 instances setup up.
Tumblr media
Prior to launching an EC2 instance, let's create a Key Pair. A key pair is a certificate for us to connect to the EC2 instance later once it is created. Navigate to NETWORK & SECURITY > Key Pairs. Click on Create Key Pair button, and provide a keypair name of your choice. In this case, let's call it jsf-maven-project. Click the Create button. The key file will be downloaded as jsf-maven-project.pem. Keep this in a safe place. We will require it later.
Tumblr media
To create a new instance now, click on the Launch Instance button in Instances page. In the next screen (Step 1: Choose an Amazon Machine Image), select Ubuntu Server 14.04 LTS for Amazon Machine Image (AMI). This is the OS that the instance/server we're going to create will have once it is up and running. Not that this is Free Tier Eligible. This means that if you are a new user, and are free tier eligible, you will not need to pay for the resources created/used during this period. There are some limitations as to how much is free, and can be seen here. For the said instance, select the 64-bit option, and click on Select.  
In the next page (Step 2: Choose an Instance Type), select Micro Instances for family (Type: t1.micro), and click on Next: Configure Instance Details.
Tumblr media
In this step (Step 3: Configure Instance Details), change nothing and click on Next: Add Storage.
Tumblr media
The next page (Step 4: Add Storage) will allow you to change volume related parameters. Since it is a t1.micro instance, it's volume capacity will be set to 8GB by default, and can be changed if required. Click on Next: Tag Instance.
Tumblr media
In this page (Step 5: Tag Instance), provide your server/instance name and Next: Security Group.
Tumblr media
This page (Step 6: Configure Security Group) asks you to either use an existing security group, or create a new one. In security groups, you can list all the port related accesses. By default, only port number 22 is open. If you need to add access to other ports, say port 80 for HTTP requests, you can add that here using Add Rule button.
Tumblr media
Click on the Review and Launch button.
This page (Step 7: Review Instance Launch) allows you to review all your settings for this instance.
Tumblr media
Click on Launch.
You will be asked to either choose and existing key pair, or to create a new one. Choose the key pair that we created earlier, acknowledge the term, and click on Launch Instance.
Tumblr media
The site will now display you a page telling that your server is now launching.
Tumblr media
On going to Services > EC2 > Instances, you will see the status of your instance. If it is up and running, it will show both Instance state and Status checks as Running.
Tumblr media
Clicking on the instance will show you the properties of the created server. In this case, the server has the below public DNS using which the server can be accessed.
ec2-54-87-161-47.compute-1.amazonaws.com or 54.87.161.47
This dynamically allocated IP changes every time the server is stopped and started again. So, let's create a new Elastic IP, and associate it with this instance. To do so, navigate to NETWORK & SECURITY > Elastic IPs, and click on Allocate New Address. In the next screen, select EC2 from the drop down and click Yes, Allocate.
Tumblr media
Then select the generated Elastic IP (54.83.62.123) and click on Associate Address button. Select the server by name (JSF Maven EC2) and click on Associate.
Tumblr media Tumblr media
Go back to Instances page. And check for Instance properties. You will see that the instance now has the newly generated Elastic IP assigned to it.
Tumblr media
That's it. Done! :)
0 notes
jmsktm · 11 years ago
Text
How to setup code repository in GitHub?
Git is a distributed Revision Control and Source Code Management (SCM) system. GitHub is a web-based hosting service for software development projects that use the Git revision control system. You can create open source repositories on Github for free, but private repositories are only offered as paid service. If you have your own server machine, you can also use Gitolite or Gitosis for hosting your repository privately. In this example, the scope is limited to hosting your repository on Github using Ubuntu (Linux) command line interface.
One can learn how to use Git (and GitHub) from http://try.github.com
This post is in reference to my other post (link below), and we'll setup a new GitHub project for the same:
http://jmsktm.tumblr.com/post/84053040137/setting-up-java-server-faces-jsf-application-on
After you have signed up on GitHub, create a new repository on the website.
Tumblr media
Provide project details in the next screen, and click on the 'Create Project' button.
Tumblr media
The next page will be something like below:
Tumblr media
This page gives you the link to your project repository (selected), and the procedure to set this repository as your remote repository. This is still a blank repository, and our project code is yet to be pushed here.
Now, on your laptop (Only Linux OS covered here), navigate to the project folder and initialize it as a git project using
git init
Tumblr media
Doing git status will show the list of all untracked files. These need to be added and committed to the repository, and pushed to the remote repository.
Add the untracked files to the repository
git add .
Commit the changes to the repository
git commit -m "Initial commit comment"
Now since we haven't linked this local repository to the remote Github repository yet, we will do that now.
git remote add origin https://github.com/james-singh/jsf-maven-project.git
To confirm that the remote repository url has been set, use: 
git remote -v
Once, done, we are ready to push the code from local repository to remote repository on Github. It will ask you for your github username and password for authentication.
git push origin master
On refreshing the GitHub project page, you will now see your project files there.
Tumblr media
Good Luck!
0 notes
jmsktm · 11 years ago
Text
Setting up Java Server Faces (JSF) application on Apache Maven
Apache Maven makes managing Java projects easy. It is particularly very useful when an application is using external libraries, and needs to take care of dependencies.
In this case, we are going to setup JSF application Apache Maven using NetBeans IDE.
Select 'Maven' for category, and 'Projects from Archetype' in right column for projects while creating a new project.
Tumblr media
On the next dialog, it will show you a list of archetypes. From the list, choose 'weld-jsf-jee'
Tumblr media
Click Next. On the next screen, provide your project name, group id and package name and click on Finish.
Tumblr media
NetBeans will now create your project.
To simplify it's structure, I have removed unwanted code from the project, and have removed most of the generated code, and created one JSF CDI Bean, a simple Test Case, and a JSP to the project. You can find this code from Github page here.
Some code snippet below:
TestBean.java
package net.mum.cs545;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
/**
* @author jSingh
*/
@Named("test")
@SessionScoped
public class TestBean implements Serializable {
         private String name;
    private String email;
    public TestBean() {
        name = "James";
        email = "[email protected]";
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
}
MyTest.java
package net.mum.test;
import junit.framework.Assert;
import net.mum.cs545.TestBean;
import org.testng.annotations.Test;
public class MyTest {
    @Test
    public void testName() {
        TestBean test = new TestBean();
        Assert.assertEquals("James", test.getName());
    }
    @Test
    public void testEmail() {
        TestBean test = new TestBean();
        Assert.assertEquals("[email protected]", test.getEmail());
    }
}
start.jsp
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        Name: ${test.name}<br/>
        Email: ${test.email}
    </h:body>
</html>
The pom.xml file in the project will have the below repository detail by default:
<repository>
<id>repository.jboss.org</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/maven2</url>
</repository>
Replace it with:
<repository>
<id>JBoss Repo</id>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<name>JBoss Repo</name>
</repository>
During runtime, this project simply initializes name and email, and displays them. The use of test case helps us ensure that no cases are failing at the time of deployment. In this case, the test case requires name to be 'James' and email to be '[email protected]'. This will come in handy when we auto deploy this JSF application.
0 notes