I hope the answer will be stupidly simple, but I cannot get the following test program running due to a classnotfound exception:
import java.net.URL;
import net.sourceforge.spnego.SpnegoHttpURLConnection;
public class HelloKeytab {
public static void main(final String[] args) throws Exception {
System.setProperty("java.security.krb5.conf", "krb5.conf");
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("java.security.auth.login.config", "login.conf");
SpnegoHttpURLConnection spnego = null;
try {
spnego = new SpnegoHttpURLConnection("spnego-client");
spnego.connect(new URL("http://as1.test.local/hello_spnego.jsp"));
System.out.println("HTTP Status Code: "
+ spnego.getResponseCode());
System.out.println("HTTP Status Message: "
+ spnego.getResponseMessage());
} finally {
if (null != spnego) {
spnego.disconnect();
}
}
}
}
I installed JDK7 and set the JAVA_HOME environment variable as an Administrator.
I am working on a Windows XP machine as a regular domain user while compiling and running.
I have the spnego-r7.jar in the same directory as the HelloKeytab.java and I compiled with:
javac -cp .;spnego-r7.jar HelloKeytab.java
which succesfully creates the class.
When I run the program with:
java -cp .;spengo-r7.jar HelloKeytab
I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sourceforge/spneg
o/SpnegoHttpURLConnection
at HelloKeytab.main(HelloKeytab.java:15)
Caused by: java.lang.ClassNotFoundException: net.sourceforge.spnego.SpnegoHttpUR
LConnection
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
The spnego-r7.jar can be found here: http://sourceforge.net/projects/spnego/files/
What I am doing wrong that it doesn't find my class?
NoClassDefFoundError are always because of incorrect or incomplete builds, or errors in class path.
I always go through the following checklist when getting this error:
Clean project
Check files and directories
Check build path
Try again. Never fails. :)
Related
I would like to get the state machine from .uml file created by papyrus. I am parsing the model.uml file using the code below.
ResourceSet set = new ResourceSetImpl();
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
set.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap()
.put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
Resource res = set.getResource(URI.createFileURI("resources/model.uml"), true);
EcoreUtil.resolveAll(res);
System.out.println(res.getContents().get(0));
This code works fine and prints the content. But when I try to cast it to Model class using the code below
Model model = (Model) EcoreUtil.getObjectByType(res.getContents(),UMLPackage.Literals.MODEL);
It throws this exception,
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/uml2/types/TypesPackage
at org.eclipse.uml2.uml.internal.impl.UMLPackageImpl.init(UMLPackageImpl.java:1907)
at org.eclipse.uml2.uml.UMLPackage.<clinit>(UMLPackage.java:83)
at org.eclipse.uml2.uml.UMLPackage$Literals.<clinit>(UMLPackage.java:28779)
at mp.m2bt.BTGenerator.main(BTGenerator.java:49)
Caused by: java.lang.ClassNotFoundException: org.eclipse.uml2.types.TypesPackage
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
I am not sure if I am missing anything. I think the problem is in UMLPackage.Literals.MODEL. So, Can anybody help me to fix this issue and get the state machines from the model.
You need the jar org.eclipse.uml2.types in your classpath. This is why the type org.eclipse.uml2.types.TypesPackage cannot be found.
I am trying to run the Trusted Computing API JSR321 in Eclipse by following the tutorial provide at Getting Started with JSR321 in Windows 7.
After successfully enabling my TPM (manufacturer: STM & version: 1.2).
I tried to run the code given in the tutorial,
import javax.trustedcomputing.tpm.TPMContext;
public class HellowWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
TPMContext context = TPMContext.getInstance();
context.connect(null);
//Do somthing cool here
context.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}
I also added the external jar files as Classpaths in eclipse for the IAIK jTSS (jTSS 0.7.1a), they also mentioned that
It is necessary to set the jsr321.tpmcontextimpl property to the classname of your TPMContext implementation.
For example java -cp YourClasspath -Djsr321.tpmcontextimpl=iaik.tc.jsr321.tpm.TPMContextImpl yourjavaapplication.class
So I added the above code by right clicking on the project and going to the Run As -> Run Configuration and in the Arguments tab in the section provided for VM arguments I inserted the following command
-cp C:\Users\workspace\HelloWorld\bin -Djsr321.tpmcontextimpl=iaik.tc.jsr321.tpm.TPMContextImpl HellowWorld
But I am getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/trustedcomputing/tpm/TPMContext
at HellowWorld.main(HellowWorld.java:10)
Caused by: java.lang.ClassNotFoundException: javax.trustedcomputing.tpm.TPMContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I have already added all the mentioned dependencies in Java Build Paths inside Project Properties.
Kindly suggest a solution.
Thanks
I'm trying to create a InitialContext so I could ask the JNDI for some enterprise java beans.
The JBoss is running fine, but when I run the java code I get an exception.
I'm running JBoss 7.1
Here is my code:
public class Test {
public static void main(String[] args){
InitialContext ctx=getInitialContext();
Object ref=null;
try {
ref = ctx.lookup("ParamEJB/remote");
} catch (NamingException e) {
System.out.println("Lookup Failed");
e.printStackTrace();
}
Param stub=(Param)PortableRemoteObject.narrow(ref, Param.class);
int times=stub.getTimes();
for(int i=0;i<times;i++)
System.out.println(stub.getMessage());
}
public static InitialContext getInitialContext(){
Hashtable<String,String> h=new Hashtable<String,String>();
h.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
h.put("java.naming.provider.url","localhost");
try {
return new InitialContext(h);
} catch (NamingException e) {
System.out.println("Cannot generate InitialContext");
e.printStackTrace();
}
return null;
}
}
And after i start my JBoss server, I try to run the java code and I get this exception:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at client.Test.getInitialContext(Test.java:32)
at client.Test.main(Test.java:13)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
What might be the problem?
I had the same problem but I found how to fix it. All you have to do is add the jbossall-client.jar library to the clients project, and done!!! You can find the file inside the client folder. e.g jboss-6.1.0.Final_GPT\client I was using Jboss 6.1.0 You can also get help from this link https://community.oracle.com/thread/1157701?start=0
Hope it helps.
The InitialContext properties are not right for the JBoss version that you are using.
With JBoss 7, things have changed considerably when you call a ejb from a remote client.
This link can help you to instantiate correctly the InitialContex object and to determine the JNDI entry name. Also will tell you what are the necessary dependencies that need to be added to the client classpath.
I am using the Java RSS parser horrorss
I added horrorss-2.2.0.jar to my Build path in Eclipse.
I can't even get the Simplest bit of Code to run.
import org.horrabin.horrorss.*;
public class Test {
public static void main(String[] args) throws Exception {
RssParser rss = new RssParser();
try{
RssFeed feed = rss.load("http://rss.slashdot.org/Slashdot/slashdot");
// Gets the channel information of the feed and
// display its title
RssChannelBean channel = feed.getChannel();
System.out.println("Feed Title: " + channel.getTitle());
}catch(Exception e){
System.err.println(e);
}
}
}
The Console Output is always the following
Exception in thread "main" java.lang.NoClassDefFoundError: com/hp/hpl/sparta/Parser
at org.horrabin.horrorss.RssParser.parseFromReader(RssParser.java:431)
at org.horrabin.horrorss.RssParser.parseFromURL(RssParser.java:455)
at org.horrabin.horrorss.RssParser.load(RssParser.java:115)
at org.horrabin.horrorss.RssParser.load(RssParser.java:147)
at Test.main(Test.java:10)
Caused by: java.lang.ClassNotFoundException: com.hp.hpl.sparta.Parser
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
I hope you guys are able to help me out (or show me another nice method for Handling RSS Feeds in Java)
Did you read this on the homepage?
It requires Sparta-XML, a light-weight XML parser based on XPath.
You need to get the Sparta-XML jar and add that to the eclipse build path too.
I have read the questions on using Sqoop from within a Java program here, here and here.
I came up with the following, but I am stumped by a ClassNotFoundException:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import com.cloudera.sqoop.SqoopOptions;
import com.cloudera.sqoop.SqoopOptions.FileLayout;
import com.mysql.jdbc.*;
public class SqoopExample {
public static void main(String[] args) throws Exception {
String driver = "com.mysql.jdbc.driver";
Class.forName(driver);
Configuration config = new Configuration();
// note that this is HDFS path, rather than core path
config.addResource(new Path("./config/core-site.xml"));
config.addResource(new Path("./config/hdfs-site.xml"));
FileSystem dfs = FileSystem.get(config);
SqoopOptions options = new SqoopOptions();
options.setDriverClassName(driver);
options.setConnectString("jdbc:mysql://localhost:3306/dbname");
options.setTableName("v_webstats");
options.setUsername("root");
options.setNumMappers(1);
options.setTargetDir(dfs.getWorkingDirectory()+"/TestDirectory");
options.setFileLayout(FileLayout.TextFile);
new com.cloudera.sqoop.tool.ImportTool().run(options);
}
}
I am sure that all the jars are correctly included and I have tested the connection to my database server and that works as well.
The exact error is:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at SqoopExample.main(SqoopExample.java:14)
not sure what I am doing wrong.
I believe that proper name of the MySQL JDBC driver class is:
com.mysql.jdbc.Driver
(notice the capital "D" in the "Driver)