I can't import fixture into my fitnesse page - java

I wanted to begin test my Java Apps with Fitnesse, but I have a big problems right at beginning.
My fitnesse page to test my very simple class is:
!contents -R2 -g -p -f -h
!define TEST_SYSTEM {slim}
!path /home/user/NetBeansProjects/dotestow/build/classes/dotestow/
!|dodawanie|
|l1|l2|add?|
|10|2|12|
|10|35|45|
|60|4|33|
My class is just normal Java class created by NetBeans, here is the code:
package dotestow;
public class Dotestow {
private int l1, l2;
public void setL1(int l1) {this.l1 = l1;}
public void setL2(int l2) {this.l2 = l2;}
public int add()
{
return l1+l2;
}
}
When I click test, it just shows:
Exception in thread "main" java.lang.NoClassDefFoundError: fitnesse/slim/SlimService
Caused by: java.lang.ClassNotFoundException: fitnesse.slim.SlimService
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: fitnesse.slim.SlimService. Program will exit.
What am I doing wrong??
##EDIT
When I run
java Dotestow
in my /Dotestow/build/classes directory, i got output:
Exception in thread "main" java.lang.NoClassDefFoundError: Dotestow (wrong name: dotestow/Dotestow)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Dotestow. Program will exit.

Answer Updated
Looks like FitNesse.jar is missing from the classpath or JRE missmatch with the FitNesse jar version. Please check if Fitnesse.jar is added to classpath in netbeans.
Regards,

Explicitly add fitnesse.jar to your classpath using !path, giving the full absolute path to the .jar

Change this
!path /home/user/NetBeansProjects/dotestow/build/classes/dotestow/
for this
!path /home/user/NetBeansProjects/dotestow/build/classes/
|Import|
|dotestow|
or
remove (from your Class)
package dotestow;
and use javac to complile :D

Related

Error when starting example code in JPVM

I am trying to run the example code provided with the JPVM,the java version of PVM.
I am able to start the JPVM daemon without any errors but when I try to run the example provided I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: jpvm/jpvmException
Caused by: java.lang.ClassNotFoundException: jpvm.jpvmException
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: hello. Program will exit.
I was running the examples from the examples directory, I copied the .class files into the JPVM root directory and ran them from there and it worked.
apparently the jPVM root directory is the working directory and examples need to be ran from there.

How to compile a java program with imported classes?

I am trying to get started with the API of the java software weka. I wrote the following code for testing:
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
public class hello_weka {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("/home/aljoscha/Masterarbeit/weka_examples/iris.arff"));
Instances data = new Instances(reader);
reader.close();
// setting class attribute
data.setClassIndex(data.numAttributes() -1);
System.out.println(data);
System.exit(0);
}
}
It works fine when I execute it in Eclipse.
However I can't get it to run in the Terminal.
I tried to provide the .jar path during compilation and then execute the program from the directory of the compiled class.
javac -cp /usr/share/java/weka.jar hello_weka.java
java hello_weka
This approach does not work, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: weka/core/Instances
at hello_weka.main(hello_weka.java:8)
Caused by: java.lang.ClassNotFoundException: weka.core.Instances
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 1 more
What am I doing wrong?
I guess I am doing just some completely stupid stuff since I just start to code in Java. If so, please excuse me and try to tell me how I can do better.
Edit:
when I try the thing proposed in the answers I get the following Error:
Exception in thread "main" java.lang.NoClassDefFoundError: hello_weka
Caused by: java.lang.ClassNotFoundException: hello_weka
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: hello_weka. Program will exit.
Try this out:
java -cp /usr/share/java/weka.jar hello_weka
You need to provide the classpath to your JAR also when executing the program:
java -cp /usr/share/java/weka.jar hello_weka
You need to add also the current directory (where your own classes are stored) to the classpath:
java -cp .;/usr/share/java/weka.jar hello_weka
I finally found the answer: The answer of dunni is nearly correct. For me it works if I provide the classpath of both, the jar file and the classfile, but separated by a :.
java -cp /usr/share/java/weka.jar:/home/aldorado/myjavascripts/ hello_weka
Is it possible that this differs depending on the OS / JDK you are using?

Running TestCases in JUnit on Ubuntu

I am coming from Python world, so please forgive my ignorance. I am trying to learn TDD with JUnit framework in Java. I am following the method described by daniel kullmann in following thread: [How to install Junit][1].
The steps I am following are:
Writing Test Cases
Running command javac -cp /usr/share/java/junit4.jar Test.java
then java -cp /usr/share/java/junit4.jar:. org.junit.runner.JUnitCore Test
So far So good. But my question is:
Do I need to run both full line of command when I have to test my class ? I mean can't it be javac Test.java and java Test ? I have exported the path in .bashrc as below:
export JUNIT_HOME=/usr/share/java
export PATH=$JUNIT_HOME/junit4.jar:org.junit.runner.JUnitCore:${PATH}
I have downloaded latest junit framework 4-11 and kept at location /usr/local/JUNIT. But when I am running command java -cp /usr/local/JUNIT/junit-4.11.jar:. org.junit.runner.JUnitCore Test, its giving the error below:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.junit.runner.Computer.getSuite(Computer.java:28)
at org.junit.runner.Request.classes(Request.java:75)
at org.junit.runner.JUnitCore.run(JUnitCore.java:117)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:96)
at org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47)
at org.junit.runner.JUnitCore.main(JUnitCore.java:40)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLC
Can someone please guide me.
[1]: https://askubuntu.com/questions/64213/how-to-install-use-junit

Java Error, java.lang.NoClassDefFoundError: org/myorg/WordCount in Hadoop

I'm very new to Hadoop. I followed the basic tutorial about how to create word count program in hadoop. Everything was fine. I than tried to create my own map reduce, and put it in a separate jar file. When I tried to run the program, it gives me that error:
shean#ubuntu-PC:~/hadoop/bin$ hadoop jar ../weather.jar weather.Weather /user/hadoop/weather_log_sample.txt /user/hadoop/output
Warning: $HADOOP_HOME is deprecated.
Exception in thread "main" java.lang.NoClassDefFoundError: org/myorg/WordCount
at weather.Weather.main(Weather.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.ClassNotFoundException: org.myorg.WordCount
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 6 more
But the problem is , it's looking for WordCount class...
If I am not wrong you are missing the jar wordcount.jar.Please add it to build path.
My advice: you put "package" path first removed. This makes it easier not reported NoClassDefFoundError errors. javac compile time: javac-classpath "$ HADOOP_HOME/hadoop-core-1.2.0.jar: $ HADOOP_HOME/lib/commons-cli-1.2.jar"-d. / weather
litianmin#gmail.com

java runs fine with 'absolute' path, doesn't run with CLASSPATH specified

my program is in package pl.edu.uj.tcs.crazySocket; due to some requirements. I work in the crazySocket directory. In order to compile the program I use command
CLASSPATH=~/prog/colosseum/data javac tictactoe.java
and that succeeds. I want to run the program. I change javac to java and get rid of the '.java'. I get
Exception in thread "main" java.lang.NoClassDefFoundError: tictactoe
Caused by: java.lang.ClassNotFoundException: tictactoe
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
when I get up in the tree directory to the ~/prog/colosseum/data and run java pl/edu/uj/tcs/crazySocket/tictactoe all works fine.
What's wrong with the CLASSPATH? Shouldn't it work both with javac and java?
There's nothing wrong with your classpath, it's your call to java that's wrong.
You need to specify the full qualified class name pl.edu.uj.tcs.crazySocket.tictactoe.

Categories

Resources