Oct 27, 2015

tool.jar not found error, during maven clean build

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.4:compile (default-compile) on project springmvc: Fatal error compiling: tools.jar not found: C:\Program Files (x86)\Java\jre7\..\lib\tools.jar -> [Help 1]











We typically encounter this error when we have a JRE instead of JDK. Configuring JDK will eclipse will resolve this issue

Steps to configure JDK in eclipse:

1. Window -> Preferences -> Java-> Installed JREs
2. Click on [Add] button and select the JDK from the file-system
3. Select the newly added JDK and click on [Finish]

How to change the location of Maven repository



By default the maven repository is created in C:\Users\username\.m2\repository
Below are the steps to change the location of Maven repository.

1. Edit the settings.xml file in location C:\Users\<user-name>\.m2\settings.xml

2. Add the line highlighted below.

  <settings>
  <localRepository>D:/Softs/mvnrepo/repository</localRepository>
  <servers>
    <server>
      <id>maven.gtk.com</id>
      <username>domain\username</username>
      <password>pass1</password>     
    </server>
  </servers>
</settings>

Sep 30, 2015

SCJP 1.5 - Chapter 2(Part 1) - Object orientation

Encapsulation:
Hiding the implementation details behind interfaces is called Encapsulation. The ability to make changes to implementation without breaking the code of others is the key benefit of encapsulation.

To implement Encapsulation:
Make public accessor methods, and force calling code to use those methods rather than directly accessing the instance variable.

Association:
Association is a relationship between 2 objects. (defines the relationship between objects like one-to-one, one-to-many, many-to-one, many-to-many)
eg. Student and Teacher, Student is related to the teacher
UML notation:


Aggregation:
Aggregation is a special type of association between 2 objects, where one object has a "has-a" relationship on another object. ie. one object contains another object. (A directional association between 2 objects)
eg. Class and Student, Class has Student.
UML notation:


Composition:
Composition is a special type of Aggregation, where one object contains another object and the contained object cannot exist with the container object.
eg. Wheel and Car, Wheel cannot exist without the car.
UML notation:



Generalization:
Generalization uses a "is-a" relationship from a Specialization to a Generalization class.
UML notation:


Realization:
Relation between a Class and its object. The object is said to realize the class.
UML notation:

Dependency:
If changes in the structure or behavior in one class affects another related class, then there is a dependancy between those 2 class. The vice-versa need not be true.
UML notation:




Reasons to use Inheritance:
- To promote code reuse
- To use polymorphism

IS-A and HAS-A relationships:
- IS-A relationships can be implemented through inheritance or by interface implementation.
- HAS-A is implemented with Using/Usage (Composition).

Polymorphism:
A Java object that can pass more than one IS-A test can be considered polymorphic.


Aug 25, 2015

Error while generation javadoc in Eclipse


Error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (attach-javadocs) on project nzc-orch: MavenReportException: Error while creating archive:
[ERROR] Exit code: 1 - java.lang.IllegalArgumentException
[ERROR] com.sun.tools.doclets.internal.toolkit.util.DocletAbortException

Resolution:
The classpath variable set in the Environment variables at the system level should be removed.

Sep 13, 2012

Error: javax.servlet.jsp.JspException: Missing message for key "label.common.button.submit" in bundle "(default bundle)" for locale en_US

Description:

We get this error while using ApplicationResources.properties file and using the entry as below
<message-resources parameter="resources.ApplicationResources"/> (where the property file name is ApplicationResources.properties). The folder "resources" is in classpath, at the same level as the "src" folder in Eclipse IDE.

Solution:

The path mentioned in the struts-config file for the ResourceBundle should be in sync with where it is found within the /WEB-INF file in the classpath, in the ".war" file that was deployed (or) in the Eclipse IDE.

<message-resources parameter="ApplicationResources"/> 

Error: javax.servlet.jsp.JspException: Cannot find message resources under key org.apache.struts.action.MESSAGE

Description:

Struts is unable to find message resources. This issue occurs while using the Message Resources/Property files/Application Resources file

Solution:

Add the message-resources tag to the struts-config.xml file:
<message-resources parameter="resources.common.Common" />

Error: java.lang.IllegalArgumentException: The path of an ForwardConfig cannot be null

Description:

While using a Form with input fields, we get this error
<action path="/Login"
          name="userForm"
          type="com.dct.struts.learning.actions.UserAction">
          <forward name="success" path="/pages/login.jsp"></forward>
</action>

Solution:

This means after doing a validation, we need to specify where to be forwarded, incase of a failure. Hence the parameters "validate" and "input"(place from where it comes & to where it needs be forwarded) should be specified.
<action path="/Login"
           name="userForm"
           type="com.dct.struts.learning.actions.UserAction"
           validate="true"
           input="/login.jsp">
           <forward name="success" path="/pages/login.jsp"></forward>
</action>