Wednesday 30 July 2014

Configuration steps for multi-core SOLR in Tomcat

This short tutorial will show you how to configure SOLR to have multiple cores. Technologies I am using:
The steps to do this are as follows:
  1. Edit Tomcat's conf/server.xml file and put URIEncoding="UTF-8" this attribute to the main Connector element.
  2. Create directory where you will keep your Solr cores configurations. For e.g. D:\Solr
  3. Create directories which will be your Solr cores inside the directory you've just created in step nr. 2. For e.g. I'll have two cores: D:\Solr\solr-core-1D:\Solr\solr-core-2
  4. Copy the file solr.xml from the directory example\multicore of downloaed and unzipped Solr archive and paste it to your Solr root directory. For e.g. : D:\Solr
  5. Edit solr.xml file depending on your core names. For e.g. in my case: <core name="solr-core-1" instanceDir="solr-core-1" />, <core name="solr-core-2" instanceDir="solr-core-2" />.
  6. Copy solr.x.x.x.war from the dist directory of the unzipped Solr archive to the Tomcat's webapps folder and rename it to solr.war.
  7. Create file called: setenv.bat in the Tomcat's bin folder. Open that file and paste this line into it: set JAVA_OPTS="-Dsolr.solr.home=D:\Solr"
  8. Open conf\solrconfig.xml files in each of the cores you have created and change the dataDir element to point to your cores' data directories. For e.g.: data directory for solr-core-1: <dataDir>D:\\Solr\\solr-core-1\\data</dataDir>
  9. Copy all the jar files from the unzipped Solr archive's directory example\lib\ext to the Tomcat's lib directory.
  10. Copy the file: example\resources\log4j.properties from Solr unzipped archive into the same Tomcat's lib directory. Just make sure you change these properties according to your needs.
  11. Start the Tomcat and your Solr cores will be listed if you access this URL: http://localhost:8080/solr/#/~cores

Sunday 6 April 2014

WSDL2Java using CXF and Maven

This short post will show how to generate client classes for java web service client using Apache CXF and Apache Maven. Lets assume that you have your project set up and your WSDL file ready so all you need to do is to add the below plugin into your pom.xml maven configuration into plugins section.

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-bindings-soap</artifactId>
            <version>${cxf.version}</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>generate-jaxb</id>
            <phase>generate-sources</phase>
            <configuration>
                <additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>src/main/resources/wsdl/YourWsdlFile.wsdl</wsdl>
                        <extraargs>
                            <extraarg>-wsdlLocation</extraarg>
                            <extraarg></extraarg>
                            <extraarg>-client</extraarg>
                            <extraarg>-p</extraarg>
                            <extraarg>com.yourcompany.types</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

That's it. Your java classes from WSDL file will be generated into: ${project.home}\target\generated-sources\cxf directory.