Archive for March, 2013

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