Having problem with compiling XMLGreeting.java

Dear whom it may concern,

I have following set up…
1)Tamino Database called “myDB” is created and running
2)jdom.jar, log4j.jar, TaminoAPI4J.jar, TaminoJCA.jar, JavaTaminoAPIExamples.jar, xercesImpl.jar, xmlParserAPIs.jar, are included
3)Tamino 4.1.4.1
4)j2sdk1.4.1_03

I have tried to compile source code by using command:
javac XMLGreeting.java,
Unfortunately I got the following message warning:

------------------------------------------------
Note: ProcessXMLGreeting.java uses or overrides a deprecated API.

Note: Recompile with -deprecation for details
------------------------------------------------

However I got XMLGreeting.class so I have tried to execute this file by executing command:

java XMLGreeting

Unfortunately, I got the following error message exception:

-----------------------------------------------
Exception in thread “main” java.lang.NoClassDefFoundError: XMLGreeting (wrong name: com/softwareag/tamino/db/API/examples/greeting/XMLGreeting)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:306)
at sun.misc.Laucher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
-----------------------------------------------

Then I commented out the “package” line in the sample code and recompiled, but still got the same error messages…
Could you help me what I should do?
Thank you very much in advance,

/****Sample Code/
/
|| Example for the Tamino API for Java.
||
|| Assumes that there is a Tamino database called “myDB”.
|| The example simply uses the default collection ino:etc.
|| This collection should only be used for examples/test code.
|| It shouldn’t generally be used for real applications.
||
|| The example does the following:
||
|| establishes a connection to the Tamino database
|| obtains an XML accessor
|| inserts a new document of … into ino:etc
|| queries for the inserted document
|| closes the connection
/

//package com.softwareag.tamino.db.API.examples.greeting;

import com.softwareag.tamino.db.API.accessor.;
import com.softwareag.tamino.db.API.common.
;
import com.softwareag.tamino.db.API.connection.;
import com.softwareag.tamino.db.API.objectModel.
;
import com.softwareag.tamino.db.API.objectModel.dom.;
import com.softwareag.tamino.db.API.response.
;
import org.jdom.;
import org.jdom.input.
;
import java.io.*;

public class XMLGreeting {

public static void main(String args) throws Exception {

// Put the XML content into a StringReader
StringReader stringReader = new StringReader(XML);

// Instantiate an empty TXMLObject instance related to the DOM object model.
TXMLObject xmlObject =
TXMLObject.newInstance(TDOMObjectModel.getInstance());

// Establish the DOM representation by reading the content
// from the character input stream.
xmlObject.readFrom(stringReader);

// Establish the Tamino connection.
TConnection connection =
TConnectionFactory.getInstance().newConnection(DATABASE_URI);

// Obtain a TXMLObjectAccessor with a DOM object model.
TXMLObjectAccessor xmlObjectAccessor =
connection.newXMLObjectAccessor(
TAccessLocation.newInstance(“ino:etc”),
TDOMObjectModel.getInstance());

try {
// Invoke the insert operation.
xmlObjectAccessor.insert(xmlObject);

// Show the ino:id of the newly inserted document.
System.out.println(“Insert succeeded, ino:id=” + xmlObject.getId());

} catch (TInsertException insertException) {
// Tell about the reason for the failure.
System.out.println(“Insert failed!”);
if (insertException.hasAccessFailureMessage())
System.out.println(“Insert rejected by Tamino. Reason:”
+ insertException.getAccessFailureMessage());
else
System.out.println(“Insert failed due to following reason:”
+ insertException.getDeepestException().getMessage());
}

// Prepare to read the instance.
TQuery query = TQuery.newInstance( xmlObject.getDoctype()
+ “[@ino:id=” + xmlObject.getId() + “]” );

try {
// Invoke the query operation.
TResponse response = xmlObjectAccessor.query( query );
if ( response.hasFirstXMLObject() ) {
StringWriter stringWriter = new StringWriter();
response.getFirstXMLObject().writeTo( stringWriter );
System.out.println(“Retrieved following instance:” + stringWriter);
} else
System.out.println(“No instance found!”);

} catch (TQueryException queryException) {
// Tell about the reason for the failure.
System.out.println(“Query failed!”);
if (queryException.hasAccessFailureMessage())
System.out.println(“Query rejected by Tamino. Reason:”
+ queryException.getAccessFailureMessage());
else
System.out.println(“Insert failed due to following reason:”
+ queryException.getDeepestException().getMessage());
}
// OK, everything is done. Let’s close the connection.
connection.close();
}

// Constant for the database URI. Please edit to use your uri of interest.
public final static String DATABASE_URI = “http://localhost/tamino/myDB”;

// Constant for the applications XML message that shall be written to the
// connected database.
public final static String XML =
“Hello World”;
}

Hi,
You raise three issues in your post.

First, the compiler messages about deprecation. These can be ignored. The most recent API has some changes to the way exceptions are handled. The examples use an older API which is now deprecated. You can read about the deprecated methods in the API documentation, but you don’t need to make any changes for the example code to work.

Next the package issue. You can either put the code into a directory structure that matches the package structure, or (as you have already done) comment out the package statement.

Finally, you still get an error when you run your non-packaged version of the example. I can’t reproduce that problem so could you please delete the example class file and recompile the source to rebuild the class. Then run the example and post the error to this forum.

Many thanks.

Thanks for answering my questions…

yeah… when I commented out the “package line” :
//package com.softwareag.tamino.db.API.examples.greeting;

I was able to compile XMLGreeting.java with following message…
------------------------------------------------------------------
Note: ProcessXMLGreeting.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details
------------------------------------------------------------------

then, when I ran the XMLGreeting.class, I got the different error message than before…
------------------------------------------------------------------
C:>java XMLGreeting
Exception in thread “main” java.lang.NoClassDefFoundError: com/softwareag/tamino/db/API/accessor/TQueryException
------------------------------------------------------------------

The code is the same as above. Could you help me figuring out how to fix this problem?

Thank you very much!
-Myong

Hello Myong,

this looks like a CLASSPATH problem.

Generally you will need at least the TaminoAPI4J.jar, jdom.jar and log4j.jar files in your classpath to run a Tamino API for Java application.
(A parser is also required, but there is one included in JRE 1.4.1, so you probably do not need the Xerces Jar files in your classpath.)

You can find these Jar files in the SDK\TaminoAPI4J\lib directory of your Tamino installation.

I hope that helps,
Trevor.