Skip to main content

Posts

How to upload an artifact to maven remote repository?

If you want to deploy artifacts that were not build using maven, or which were build using maven but their POMs did not contains the deployment detials, then you need to deploy them using the following: mvn -e deploy:deploy-file -DgroupId=com.test.jpa -DartifactId=jpa-demo -Dversion=1.0.0 -Dpackaging=jar -Dfile=jpa-demo-1.0.0.jar -Durl=http://localhost:8080/archiva/repository/internal/ -DrepositoryId=reppoI d url: specifies the remote maven repository to where the jar is to be uploaded repositoryId: Id repository is secured, repositoryId is used to specify the credentials that are to be used for uploading. Repositories are defined in settings.xml. e.g. <servers>     <server>       <id>deploymentRepo</id>       <username>repouser</username>       <password>repopwd</password>     </server> </servers> Mave...

Error validating server certificate / The certificate is not issued by a trusted authority

I was able to use SVN with ease (checkin, checkout, update code) until recently the SVN server went through some changes. I started to see the following on each SVN command: Error validating server certificate for 'https://svn.myserver.com:443':  - The certificate is not issued by a trusted authority. Use the    fingerprint to validate the certificate manually!  - The certificate hostname does not match. Certificate information:  - Hostname: de-v-svn  - Valid: from ...  - Issuer: I...  - Fingerprint: ... (R)eject, accept (t)emporarily or accept (p)ermanently? It worked fine when I selected  (p)ermanently but had to do it again next time I used  SVN command. Solution: Delete ~/.subversion folder. svn cleanup svn up

log4j - use logger instead of category

Do not use 'category'. In log4j 1.2, the Category class has marked as being deprecated and has been replaced by the Logger class. I am using log4j-1.2.14.jar and category didn't work for me. Example: <logger name="com.test.pkg1"><level value="INFO"/></logger> <logger name="com.test.pkg2"><level value="INFO"/></logger> Was: <category name="com.test.pkg1"><priority value="INFO"/></category> <category name="com.test.pkg2"><priority value="INFO"/></category>

svn credentials caching

SVN client has a built-in system for caching authentication credentials on disk. It saves the credentials in the user's private runtime configuration area ~/.subversion/auth/ (Unix-like systems) %APPDATA%/Subversion/auth/ (Windows) If you dont want to catch the credeitials for a commit, use --no-auth-cache. $ svn commit --no-auth-cache Here we are telling the svn client that dont cach authentication credentials. You can disable credential caching permanently by editing your runtime config file (located next to the auth/ directory). Set store-auth-creds to no. [auth] store-auth-creds = no

Comparable interface

Lists and Arrays of objects that implement Comparable interface can be sorted automatically by Collections.sort and Arrays.sort respectively. Implementation Comparable is easy. You just have to implement compareTo(Object o). It should return negative integer, zero, or a positive integer as this object is less than, equal to,or greater than the specified object. Here goes an example: public void testListSort(){ Calendar cal = Calendar.getInstance(); cal.set(2010, 10, 1); License msWindows7 = new License("Windows", "7",new Date(cal.getTimeInMillis())); cal.clear(); cal.set(2010, 11, 10); License msWindowsVista = new License("Windows", "Vista", new Date(cal.getTimeInMillis())); cal.clear(); cal.set(2010, 11, 5); License lotusNotes = new License("Notes", "1.1", new Date(cal.getTimeInMillis())); List list = new ArrayList (3); list.add(lotusNotes); ...

desending sort algo

... double []test = new double []{88.6,88.9,-1,25,88.6}; int size = test.length; System.out.println("*** un-sorted ***"); for (double d : test){ System.out.println(d); } // descending sort algo ************************************* int counter = 0; int indexOfMax = 0; // after each iteration of while, test[counter] should have the correct value while (counter indexOfMax = counter; // assuming that test[counter] has the max value // this loop finds the index of max value (stores in indexOfMax) from the test array starting from index counter+1 for(int i = counter+1; i if (test[i]>test[indexOfMax]){ indexOfMax = i; } } // end of for loop -- now indexOfMax should have the max value // swapping double tmp = test[counter]; test[counter] = test[indexOfMax]; ...

relocating/switching SVN repository

My SVN repository changed recently and I was worried about associating my Java workspace with the new repository . Checking out from the new repository was always an option but of course, I would have lost my non committed changes. After googling for half an hour, I found a way to switch my SVN repository. 1. Find the current repository's URL to which your files/folders are associated. svn info 2. Switch the repo. svn switch --relocate 3. Verify the current repo's URL. svn info Hope this helps.

Useful SVN commands

svn info Print information about paths in your working copy. svn status / svn st Print the status of working copy files and directories. svn update / svn up updates the working copy. svn commit -m "message goes here" / svn ci Send changes from your working copy to the repository svn log -l 10 Prints last 10 commits in reverse-chronological order by default.

SVN red book

I normally use Subclipse plugin for Eclipse for SVN operations. It really makes life easy. I am a novice when it comes to performing svn operations using SVN commands. I found a very useful resource for that: HTML version of SVN red book (for subversion 1.5) Hope you find this useful :)

Parameter vs Argument

The parameter is the local variable in the method and the argument is the caller-supplied value/reference. In the given example, the parameter for doSomething is 'a' and the argument is 22. public static void doSomething(int a) { System.out.println("The argument was " + a); } public static void main(String[] s) { doSomething(22); }

Autoboxing example

You can’t put a primitive value into a collection since collections can only hold object references. To do so, you need to box primitive values into the appropriate wrapper class. When retriving, you get an object out of the collection and you need to unbox the it. Java 5 provides autoboxing and unboxing feature that eliminates the pain. import java.util.ArrayList; public class Autoboxing { public static void main ( String [] args ) { ArrayList list = new ArrayList () ; for ( int i = 0 ; i 10 ; i++ ){ list.add ( i ) ; } int sum = 0 ; for ( Integer j : list ){ sum += j; } System.out.printf ( "The sum is %d." , sum ) ; } }

Anonymous Classes

Anonymous class is normally used to provide a simple implementation of an adapter class. Many developers don’t just wanna use these because they feel its not really required and is toocomplex. For sure you may do the required task without using anonymous classes but sometimes it is really wise to use these. Let me list features of anonymous classes for you: is a local class without a name is defined and instantiated in a single expression using the new operator anonymous class definition is an expression it can be included as part of a larger expression (method call) When to use it When a local class is used only once, consider using anonymous class syntax. It places the definition and use of the class in exactly the same place. Syntax We use new keyword for defining an anonymous class and creating an instance of that class. It is followed by the name of a class and a class body definition in curly braces. If you wish to subclass your anonymous class, then the name following the new k...

Getting warnings from JDBC Connection

Sometimes it is a wise decision to retrieve the first warning reported by calls on this Connection object. This can be done using getWarnings() method. The code sample below shows how to print all the warnings with their sates and messages. Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ; Connection conn = DriverManager.getConnection( "jdbc:odbc:Database" ) ; // Print all warnings for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() ) { System.out.println( "SQL Warning:" ) ; System.out.println( "State : " + warn.getSQLState() ) ; System.out.println( "Message: " + warn.getMessage() ) ; System.out.println( "Error : " + warn.getErrorCode() ) ; }