Friday, 19 February 2016

maven

1. surefire-plugin vs. failsafe-plugin
  • surefire-plugin is for running unit test, if any test fail it will fail the build immediately
  • surefire-plugin can use <testFailureIgnore>true</testFailureIgnore>  to run all test
  • failsafe-plugin is for running integration test, it will run all tests and fail at verify stage
  • surefire-plugin use "mvn test" and failsafe-plugin use "mvn verify"

2. mvn eclipse:eclipse (obsolete)
  • this command will read pom.xml and generate metadata for eclipse
  • run 'mvn eclipse:eclipse' to update eclipse project, then refresh project
  • afterwards you can use eclipse 'import existing project' to import a maven project
  • this command is no longer needed with latest version of eclipse, where you can import 'exisitng maven project'

3. add oracle jdbc driver to maven
  • due to oracle license restriction, there is NO public maven repository provides oracle jdbc driver
  • you have to install it manually into your maven local repository

4. groupid, artifactid, version, packaging
  • groupid is domain name, e.g. com.example.foo
  • artifactid is name of artifact (jar or war or other executable file)
  • when no packaging is declared, maven assume default is 'jar'

5. standard alone maven and maven in eclipse
  • they will use same repo in ~/.m2 folder, if artifact is download by one, it will not be downloaded by the other
  • if seeing 'could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved' error, run 'mvn compile', if it works, it's maven setting issue in eclipse

6. settings.xml
  • global settings: ${maven.home}/conf/settings.xml
  • user settings: ${user.home}/.m2/settings.xml
  • by default user settings is not created
  • if both exist, a merge of global and user will be used by standalone maven
  • in both m2eclipse plugin and intellij maven plugin, user can specify the setting to use

7. dependency vs. module
  • dependency is library need to build the project
  • module means when you build main project, sub module project will be built too

8. project lombok
  • reduce boilerplate code for model/data object
  • generate getter/setter automatically by adding annotations

9. parent tag in pom.xml
  • maven read parent pom content and concatenate with current pom

10. access maven command line argument from java class
  • -Dexec.args
  • you can use System.getProperty("exec.args") to get any environment variable set on command line with the flag -D

11. plugin
  • define an 'action'
  • has 'groupId', 'artifactId' and 'version'

12. intellij
  • intellij has maven plugin bundled by default
  • in run/debug configuration, can set maven command line parameter
  • maven option on the right hand side of intellij
  • open settings.xml in intellij by right click in the pom.xml file -> maven ->  open 'settings.xml'
  • note that brew install maven's settings.xml location is different from default intellij' settings.xml location (~/.m2/settings.xml)
  • sometimes after mvn clean install, it is still showing package missing, and in 'project structure -> project settings -> modules', the dependency modules are missing too. then you can click the refresh button in maven tab to 'reimport all maven projects'

13. mvn -v    //show maven home details


reference

Friday, 5 February 2016

Database

1. connect to local sql server from DBVisualizer
  • find host name for sql server
  1. localhost or under cmd window type host to find out
  • find port number for sql server
  1. open sql server configuration manager
  2. sql server network configuration -> protocols for (dbinstance) -> enable tcp/ip -> properties -> ipall (can see the port number, change to default 1433)
  3. restart server

references:
1. solving sql server connection problem