Import Issue Java TTest - java

I am trying to run a TTest in my program and importing the class necessary for importing it isn't working.
This is where I heard of the class
http://commons.apache.org/proper/commons-math/apidocs/index.html?org/apache/commons/math3/stat/inference/TTest.html
I tried:
import java.lang.Object.org.apache.commons.math3.stat.inference.TTest;
and
import org.apache.commons.math3.stat.inference.TTest;
and a few combinations of those that didn't work either.
If you know how to do it please let me know!
Inside I am constructing using
TTest test = new TTest();
so if that is the error just let me know!

import org.apache.commons.math3.stat.inference.TTest; is the correct way to import the TTest class from commons-math.
Since TTest belongs to an external library (commons-math), you have to download it and tell Java where to find it to build and run your program, this is the classpath and it should be defined if you are using a class which does not belong to the default standard Java classes. If you are not aware of classpath and external libraries in Java, you should definitively read and google about the subject.

Related

Running Java class with JMeter (Bean Shell)

I have written a Java Class for use in JMeter, packaged the project as a .jar file and moved that file into the lib/ext folder in the jmeter directory. I have seen documentation on how to proceed but they give contradictory answers.
The first way is to use the BeanShell Sampler to import my package and class, create an object of the class and run the methods that way. I have used this method using example classes with more simple file structures than that of class I want to run. The example classes work with the following BeanShell script.
import tools.JmeterTools;
JmeterTools jt = new JmeterTools();
jt.foo();
When I try to use this method for the class I want to run, it states that the variable declaration is an error and the Class cannot be found. I assume this is because I do not understand what to import exactly, as the file structure in my project is a little odd.
The second uses the BeanShell PreProcessor to add the jar to the class path. This method I have not been able to get to work at all, but have read many accounts of others finding success. It works as follows:
addClassPath("directory path to jar\lib\ext\foo.jar");
JMeterTest jtm = new JMeterTest();
jmt.test();
Would anyone have any knowledge of which way would work better or any ideas on how to fix the import?
The import I have been using in the BeanShell script is the following:
import client.JMeterTest;
The package line at the top of my class is the following
import com.x.foo.client;
You need to have your jar file in JMETER_HOME/lib folder.
lib/ext is for JMeter extensions/plugins etc.
Once you have placed your jar, you might have to restart JMeter.
Running external classes from Beanshell should work fine given the following preconditions met
Your test with dependencies is located in JMeter classpath.
JMeter restart is required to pick new libraries up
You need to provide full package name plus full class name (or wildcard) for import.
Either
import com.x.foo.client.JMeterTest;
or
import com.x.foo.client.*;
And finally it is recommended to use JSR223 Sampler and use "groovy" as a language. Beanshell interpreter has severe performance issues so use it for something very "light" like variable amendment, converting variable to property, etc. For generating the real load use JSR223 and groovy as it implements Compilable interface and hence you can achieve performance similar to native Java code. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for detailed explanation, benchmarking and instructions on installation of groovy scripting engine support.
For anyone who has this issue in the future. The answers given by others are correct. It wasn't working for me because I had forgotten that Maven does not package files in the test directory when a jar is made.
This link may help if anyone ever does this in the future.
Generate test-jar along with jar file in test package

Why cannot use weka.classifiers.functions.PLSClassifier

I am trying to use weka's PLSClassifier using java, but when I tried to import weka.classifiers.functions.PLSClassifier into eclipse, it gives me error(The error is import weka.classifiers.functions.PLSClassifier cannot be resolved). The weka I use is the latest version3.7, but I found no class PLSClass under weka.classifiers.functions.
The documentation for this class is: http://weka.sourceforge.net/doc.stable/weka/classifiers/functions/PLSClassifier.html
I would like to know do I need addition package to support this?
I found an external PLSClass package and solve the problem. It seems that in the original weka library, there is no PLSClass under weka.classifiers.functions package.

Java library import difficulty

I'm trying to compile a small test program I have written for a raspberry pi.
The program makes use of the Pi4J library to control the piface add-on board.
What I have done so far is based on the following tutorial: http://www.savagehomeautomation.com/piface
While I can get the above example program to compile within my IDE after setting up the class paths I get compile errors with the one I have made and as far as I can tell the imports are set up in the same way.
It says that each of the following packages does not exist:
import java.io.IOException;
import com.pi4j.component.switches.SwitchListener;
import com.pi4j.component.switches.SwitchState;
import com.pi4j.component.switches.SwitchStateChangeEvent;
import com.pi4j.device.piface.PiFace;
import com.pi4j.device.piface.PiFaceLed;
import com.pi4j.device.piface.PiFaceRelay;
import com.pi4j.device.piface.PiFaceSwitch;
import com.pi4j.device.piface.impl.PiFaceDevice;
import com.pi4j.wiringpi.Spi;
I'm assuming that my problem is relatively simple but I don't really understand how import statements work and it's quite vague topic to search about. I have included some file paths if that helps.
This is where my project resides:
/home/pi/JBerries/relay
and this is where the pi4j library is:
/opt/pi4j
I hope the following image provides some of the information requested, note that the class paths are already set up:
You need to set the CLASSPATH environment variable to /opt/pi4j or the jar file therein. WIthout this the compiler is unable to know where your libary is located and will give you the errors you describe.
If you're using a project in JBerries you need to configure the classpath for the project - the screenshot shows the classpath for single-file compilations only. To edit the project config right-click the root node in the project window and select properties.

Java library class not recognized?

I am importing this following :
import org.apache.lucene.analysis.PorterStemmer
in Java program. The whole package is available in refrenced library.
I tried importing
import org.apache.lucene.analysis.PorterStemFilter
and
import org.apache.lucene.analysis.Analyzer;
both are working fine except the first one mentioned
Can anybody point out why ?!
Package org.apache.lucene.analysis.PorterStemmer is not a public package which is why you cannot import it. If you look at this package inside the library, you'll notice that it begins with class PorterStemmer instead of public class PorterStemmer.
My guess is that you have a different version of the Lucene JAR that doesn't contain the class that's failing to work. Open the JAR with WinZip, 7Zip, or some other tool and see if that class is indeed missing. If it is, you either need to find a version of the JAR that has it or rewrite your code to use an alternative.

Com.Google.Common.*.*... import failure

I'm working on a project and need to use the Predicate interface of google's common.base
I tried importing the google-collect jar at http://code.google.com/p/gdata-java-client/source/browse/#svn/trunk/java/deps
I got the jar, imported it in my library but nothing's there...
Can anyone tell help me to be able to work with this interface?
If you are using eclipse, you need to add the library jar to your build path, as described here.
If you are compiling from the command line, use the -classpath option to add the jar to the path.
Also make sure the case is correct in your import declaration. The import should look like
import com.google.common.base.Predicate;
not
import Com.Google.Common.Base.Predicate;
Also you probably know this already, but the import com.google.common.*.* suggested by your question title is invalid - you can only have one *. (import com.google.common.base.* is OK.)

Categories

Resources