phaneendra

This user hasn't shared any biographical information

Failed to load Main-Class manifest attribute from….


Problem: “Failed to load Main-Class manifest attribute from” error while trying to call main class bundled in a jar file.

Below is the documentation from oracle related to the above error, but i will also show you how do to do this in case if you are using build tool like maven to bundle your jar file.

Setting an Application’s Entry Point

If you have an application bundled in a JAR file, you need some way to indicate which class within the JAR file is your application’s entry point. You provide this information with the Main-Class header in the manifest, which has the general form:

Main-Class: classname

The value classname is the name of the class that is your application’s entry point.

Recall that the entry point is a class having a method with signature public static void main(String[] args).

After you have set the Main-Class header in the manifest, you then run the JAR file using the following form of the java command:

java -jar JAR-name

The main method of the class specified in the Main-Class header is executed.

An Example

We want to execute the main method in the class MyClass in the package MyPackage when we run the JAR file.

We first create a text file named Manifest.txt with the following contents:

Main-Class: MyPackage.MyClass

Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.


We then create a JAR file named MyJar.jar by entering the following command:

jar cfm MyJar.jar Manifest.txt MyPackage/*.class

This creates the JAR file with a manifest with the following contents:

Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
Main-Class: MyPackage.MyClass

When you run the JAR file with the following command, the main method of MyClass executes:

java -jar MyJar.jar

Setting an Entry Point with the JAR Tool

The ‘e’ flag (for ‘entrypoint’), introduced in JDK 6, creates or overrides the manifest’s Main-Class attribute. It can be used while creating or updating a JAR file. Use it to specify the application entry point without editing or creating the manifest file.
For example, this command creates app.jar where the Main-Class attribute value in the manifest is set to MyApp:

jar cfe app.jar MyApp MyApp.class

You can directly invoke this application by running the following command:

java -jar app.jar

If the entrypoint class name is in a package it may use a ‘.’ (dot) character as the delimiter. For example, if Main.class is in a package called foo the entry point can be specified in the following ways:

jar cfe Main.jar foo.Main foo/Main.class

Pom.xml

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<classpathPrefix>target/lib/</classpathPrefix>
<addClasspath>true</addClasspath>
<mainClass>com.MyPackage.MyClass</mainClass>

</manifest>
</archive>
</configuration>
</plugin>

where com.MyPackage.MyClass is the file where the main method exists and classpathPrefix is something where i am expecting some dependant jars to be available. We are interested in mainClass element at this time.

This is how Manifest.MF looks like in META-INF folder inside the jar file
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: username
Build-Jdk: 1.6.0_33
Main-Class: com.MyPackage.MyClass
Class-Path: target/lib/json-20090211.jar

Main-Class described above will help to load the main method.

 

,

Leave a comment

Axis2 contract-first web service


Installing Axis2 WAR Distribution

  1. Download the Axis2  WAR distribution from here: http://axis.apache.org/axis2/java/core/download.cgi
  2. Deploy it as an exploded directory in your preferred Servlet Container (JBoss, Tomcat, etc).
  3. axis2.war will be the container to hold multiple aar files, which independently are axis projects themselves
  4. Go to the axis2.war/WEB-INF/conf/axis2.xml file, and set the hotupdate parameter to true, as follows:
…<parameter name=”hotupdate”>true</parameter>Check that the Axis2 webapp was successfully deployed by going to this link http://localhost:8080/axis2/ and clicking on ‘Validate’.

Developing a contract-first web service

  1. Create a Maven project in eclipse.
  2. Copy your wsdl and xsd files to src/main/resourcesNote: This process assumes you already have an existing WSDL file with external xsd files for the messages definition (Contract-first approach)
  3. Copy the following to your pom.xml file:
<build><plugins>

<plugin>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-aar-maven-plugin</artifactId>

<version>1.4.1</version>

<extensions>true</extensions>

<configuration>

<servicesXmlFile>src/main/resources/services.xml</servicesXmlFile>

<wsdlFile>src/main/resources/<your-wsdl-file></wsdlFile>

<fileSets>

<fileSet>

<directory>src/main/resources</directory>

<outputDirectory>META-INF</outputDirectory>

<includes>

<include>**/*.xsd</include>

</includes>

</fileSet>

</fileSets>

</configuration>

</plugin>

</plugins>

</build>

<profiles>

<profile>

<id>codegen</id>

<build>

<plugins>

<plugin>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-wsdl2code-maven-plugin</artifactId>

<version>1.6.2</version>

<executions>

<execution>

<phase>generate-sources</phase>

<goals>

<goal>wsdl2code</goal>

</goals>

</execution>

</executions>

<configuration>

<classpathElements>${project.build.outputDirectory}</classpathElements>

<wsdlFile>src/main/resources/<your-wsdl-file></wsdlFile>

<databindingName>adb</databindingName>

<packageName><package-name></packageName>

<generateServerSide>true</generateServerSide>

<generateServerSideInterface>true</generateServerSideInterface>

<generateServicesXml>true</generateServicesXml>

</configuration>

</plugin>

</plugins>

</build>

</profile>

</profiles>

<dependencies>

<dependency>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-transport-http</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-transport-local</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.json</groupId>

<artifactId>json</artifactId>

<version>20090211</version>

</dependency>

</dependencies>

  1. To generate the java sources from the wsdl, run: mvn clean generate-sources -Pcodegen. This will create the input and output objects of every service, as well as the skeleton files and the services.xml file.
  2. Copy the files from target/generated-sources/axis2/wsdl2code/src to your src folder.
  3. Copy the services.xml file from target/generated-sources/axis2/wsdl2code/src to src/main/resources
  4. Edit the Skeleton class to include the logic you want.
  5. To generate the .aar file, run: mvn clean compile axis2-aar:aar
  6. Copy the generated .aar file from target to testws.war/WEB-INF/services
  7.  WSDL URLhttp://host:port/axis2/services/test-services?wsdl

Leave a comment

Bulk convert Office 2003 files to Office 2007


If you would like to convert all your 2003 office documents to 2007, but would like to do all of them in a single shot, here you go.

1. Download Migration Manager from microsoft and install it, which is a free tool

http://www.microsoft.com/en-us/download/details.aspx?id=21888#filelist

2. Download Office compatibility pack

http://www.microsoft.com/en-us/download/details.aspx?id=3

 

Once step 1 is done, open the folder where it is installed and look for tools\ofc.ini

Below ofc.ini is complete file and we are interested in one part, the path to provide the source folder under [FoldersToConvert], make sure you have this fldr=C:\localfolder (without a ; before fldr and where localfolder is name of your folder)

 

[FoldersToConvert]
; The Converter will attempt to convert all supported files in the specified folders
; (do not include if specifying FileListFolder)
fldr=C:\localfolder
;fldr=\\server\share\docs

Also you can update DestinationPathTemplate to the path where your converted files need to be available

SourcePathTemplate=*\*\*\
DestinationPathTemplate=C:\Converted

4. Now open cm.exe and navigate to folder where migration manager is installed and simply run the cmd as ofc.exe

all your files will be converted and available in destination provided above without original files getting affected.

Leave a comment

Shell Tips


Specific to CShell……….

1. How to comment multiple lines in shell scripts

:<<COMMENT

Line 1 to be commented

Line 2 to be commented

and so on….

COMMENT

2. How to loop through files in a directory

if (-d $dirpath) then

foreach file (-d $dirpath)

echo $file

end

endif

3. How to get filename from filepath

use basename

basename $dirpath

Leave a comment

org.apache.cxf.interceptor.Fault: Unmarshalling Error: Unable to create an instance of scala.collection.immutable.List


Problem: Trying to call CXF Service, which is calling scala functions utilizing scala List object and getting the error org.apache.cxf.interceptor.Fault: Unmarshalling Error: Unable to create an instance of scala.collection.immutable.List when calling the CXF service

 

Solution:

Basically CXF unable to marshall the request to cala List object. Check for the scala function where you are using Scala List object, change it to java.util.List object by explicitly mentioning the List  object as java.util.List. Also, in the files where you are doing this,

import scala.collection.JavaConversions._

which works in scala 2.8 and above

,

Leave a comment

How to convert reference cursor to oracle pipelined table data results


Problem: Converting from reference cursor to oracle pipelined results

Solution: Package body declaration is shown here, it is assumed that the specification is already taken care to declare the pipelined record datastructure, if not please look into my other posts on how to declare the specification part of it at

https://javatoj2ee.wordpress.com/2012/08/30/oracle-pipelined-table-functions/

function get_customer_data

(firstName IN VARCHAR2 DEFAULT NULL, lastName in VARCHAR2 DEFAULT NULL)

return customerpipelineddata PIPELINED AS

output_record                 customerpipelineddata;

v_customerdetails           ref_cursor_type;

–select statement goes here

open v_customerdetails for (select statement query)

–Below is the part needed to have reference cursor data into pipelined data

loop
fetch v_customerdetails_cursor bulk collect into output_record limit batchsize;
for i in 1 .. output_record.count() loop
pipe row (output_record(i));
end loop;
exit when output_record.count < batchsize;
end loop;

end get_customer_data;

here customerpipelineddata  is the actual pipelined data record, a set of records of a particular data structure like

TYPE customerpipelinedrecord  IS RECORD (id varchar2(100),firstname CUSTOMER.FIRST_NAME%type);

TYPE customerpipelineddata  IS TABLE OF customerpipelinedrecord;

Hope this helps….Please do not forget to like or post your comments 🙂

Leave a comment

Convert oracle result set to XML using


The OracleXMLQuery class generates XML given an SQL query.

getXMLSchema()

Description

This methods generates the XML Schema(s) corresponding to the specified query; returns the XML Schema(s).

Syntax

public org.w3c.dom.Document[] getXMLSchema();

getXMLString()

Description

Transforms the object-relational data, specified in the constructor, into a XML document. Returns the string representation of the XML document. The options are described in the following table.

Syntax Description
public String getXMLString(); Takes no arguments.
public String getXMLString(int metaType); The metaType argument is used to specify the type of XML metadata the XSU is to generate along with the XML.
public String getXMLString(org.w3c.dom.Node root); If not NULL, the root argument, is considered the root element of the XML doc.
public String getXMLString(org.w3c.dom.Node root,int metaType); If not NULL, the root argument is considered the root element of the XML doc. The metaType argument is used to specify the type of XML metadata the XSU is to generate along with the XML.

Following snippet converts oracle result set to XML WHERE cs is a valid callable statement object and rs is the jdbc result set object

import oracle.xml.sql.query.OracleXMLQuery;

OracleXMLQuery qry = new OracleXMLQuery(cs.getConnection(),rs); // prepare Query class

qry.useLowerCaseTagNames();
qry.setRowsetTag(“students”);
qry.setRowTag(“student”);
qry.setRaiseNoRowsException(true);
qry.setRaiseException(true);
str = qry.getXMLString();

Above snippet will create XML in the following format

<students>

<student>

<firstname>John</firstName>

<id>2323</id>

</student>

<student>

<firstname>Mary</firstName>

<id>343</id>

</student>

</students>

we will see in the next tutorial on how to transform this generated XML to user defined XML schema definition using XSLT

Leave a comment