Questions and solutions relating primarily to web page development. I have been developing web pages since 1994. I hope my articles will be helpful to you.
Tuesday, September 13, 2011
Interning String Literals In Java
Thursday, September 08, 2011
SOLUTION: "SQL driver not found org.apache.derby.jdbc.ClientDriver" When Using Oracle with Sonar and Maven
I am new to Sonar and Maven, and have been perplexed for several hours with the "SQL driver not found org.apache.derby.jdbc.ClientDriver" error I was getting when running mvn sonar:sonar
from the Windows command line after starting the Sonar server.
What is not clear in the instructions is that you must modify both <sonar path>\conf\sonar.properties
and <maven path>\conf\settings.xml
to get this to work. The Sonar properties tell the Sonar server what database driver to use in the Sonar server, and the Maven settings file tells Maven what database driver to use when it is running Sonar.
Here are the changes I made to connect to my local Oracle XE instance:
sonar.properties
sonar.jdbc.username: sonar
sonar.jdbc.password: sonar
...
# Comment the following lines to deactivate the default embedded database.
#sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true
#sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver
#sonar.jdbc.validationQuery: values(1)
...
sonar.jdbc.url: jdbc:oracle:thin:@localhost:1521:xe
sonar.jdbc.driverClassName: oracle.jdbc.driver.OracleDriver
sonar.jdbc.validationQuery: select 1 from dual
settings.xml
...
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>
jdbc:oracle:thin:@localhost:1521:xe</sonar.jdbc.url>
<sonar.jdbc.driver>
oracle.jdbc.driver.OracleDriver</sonar.jdbc.driver>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
</profiles>
Tuesday, September 06, 2011
SOLUTION: Modify PMD's ShortVariable Rule To Ignore ID Fields
Several people online have asked about the problem of not being able to add exceptions to PMD's ShortVariable rule. Most often, it has been the desire to get PMD to ignore the case where the variable name is 'id'. I was not able to find a solution online, but I worked with the XPath until I came up with a working solution.
- In Eclipse, go to Window » Preferences » PMD » Rules configuration » ShortVariable » Edit Rule...
- Change the XPath field to:
//VariableDeclaratorId[(string-length(@Image) < 3) and (not (@Image='id'))]
[not(ancestor::ForInit)]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))] - Click Apply » Confirm rebuild » Click Ok » Confirm rebuild
- Restart Eclipse
- Right-click on the project » PMD » Check code with PMD
You should then see the warning markers disappear on your id fields.