Eclipse No Class def found - Loadrunner lr.class - java

We wanted to run Junit Test in Loadrunner and below is the code written in eclipse:
When i run the code in eclipse i get NoClassDefFoundError Exception. From Loadrunner Vugen Folder I zipped the "lr.class" file and imported it in the eclipse Jar libraries.
import classes.lrapi.lr;
import org.junit.Test;
public class Jtst {
#Test
public void tst() {
System.out.println("Tst method");
try{
lr.start_transaction("T11");
//lr.start_transaction("T1");
System.out.print("Executing...");
lr.end_transaction("T1",lr.PASS);
}catch (Exception e){
e.printStackTrace();
}
}
public static void main(String args[]) throws ClassNotFoundException
{
System.out.println("Main");
Jtst j1 = new Jtst();
j1.tst();
}
}
When i run the program I get the Exception NoClassDefFoundError Please find below the error message.
java.lang.NoClassDefFoundError: lrapi/lr
at Jtst.tst(Jtst.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run

The easyest way to add a references to LoadRunner API is by using LoadRunner developer's add-in.
To use it (from LoadRunner user guide):
Make sure you have JDK 1.7 (JRE 7) on your machine. Go to oracle.com to check your version or download the required version. After you install it, open Eclipse and select Window > Preferences. Navigate to the Java > Installed JREs node. If jre7 is not in the Installed JREs list, click Add and use the wizard to add its folder (for example c:\Program Files\Java\jre7). In the Installed JREs list, click the check box by jre7 to instruct Eclipse to use this version.
Run the Eclipse Dev add-in, LREclipseIDEAddInDevSetup.exe, from the download/DVD folder: Additional Components\IDE Add-Ins Dev. After installing the Eclipse add-in, rebuild the plugin cache by running the following command line string: Eclipse.exe -clean.
In Eclipse, open your Selenium or JUnit test.
Code the test as you normally would in Eclipse.
Build your java classes.
Select Devops Vuser > Add LoadRunner API Reference to add the desired LoadRunner functions to your script as well as transactions, rendezvous points, and messages.

Related

Java Sample with Freetts is not Working After Upgrade Eclipse and Java

I wanted to upgrade my eclipse version to the latest and it require me to upgrade also the java version.
After upgrade(java 15/eclipse 12-2020) I've notice that simple code that I had with freetts is not working with the new configuration.
I still have the old eclipse version that uses java 8, so I did the same steps in the old and the new version: create java project, add all the relevant jars files and set simple demo class.
In the old version it is working fine, while in the new it throws exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/VoiceManager
at demoPackage.TextSpecchClass.<init>(TextSpecchClass.java:13)
at demoPackage.TextSpecchClass.main(TextSpecchClass.java:8)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.VoiceManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more
It seems basically that it cannot find the jars file but I'm not sure why, and if it related to the new eclipse version or the java upgrade.
*Also note that it in other sample I used external jar of sqllite and it worked, therefore it doesn't seems to happened with any jar, but something specific with the freetts
jars: (possible some are redundant...):
cmu_time_awb.jar
cmu_us_kal.jar
cmudict04.jar
cmulex.jar
cmutimelex.jar
en_us.jar
freetts.jar
freetts-jsapi10.jar
jsapi.jar
mbrola.jar
package demoPackage;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TextSpecchClass {
public static void main(String[] args) {
new TextSpecchClass("Hello worlds");
}
public TextSpecchClass(String words) {
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Voice voice = VoiceManager.getInstance().getVoice("kevin16");
if (voice != null) {
voice.allocate();// Allocating Voice
try {
voice.setRate(190);// Setting the rate of the voice
voice.setPitch(150);// Setting the Pitch of the voice
voice.setVolume(3);// Setting the volume of the voice
voice.speak(words);// Calling speak() method
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
throw new IllegalStateException("Cannot find voice: kevin16");
}
}
}
Recent versions of Eclipse require at least a Java 11 JDK to run Eclipse, but you can compile/run the projects in Eclipse with older versions of the JDK. Ensure that you have both your Java 15 and Java 8 JDKs. Set Eclipse to run with the Java 15 JDK, and configure your project to use the "JavaSE-1.8" execution environment, and make sure that the Java 8 JDK is in the list of installed JDKs for that execution environment.

How to use other python modules with jep?

I've set up a jep project within IntelliJ-IDEA, and keep getting this error when I run my code:
Exception in thread "main" jep.JepException: <class 'ModuleNotFoundError'>: No module named 'spacy'
at src/main/python\nlq_wrapper.<module>(nlq_wrapper.py:2)
at <string>.<module>(<string>:1)
at jep.Jep.exec(Native Method)
at jep.Jep.exec(Jep.java:478)
at com.siemens.nlqwrapper.NLQWrapper.load(NLQWrapper.java:37)
at com.siemens.nlqwrapper.Main.main(Main.java:9)
Even though spacy is included in my interpreter SDK packages.
Another weird thing is that the Python terminal within IntelliJ-IDEA can find and use spacy.
But when I try and run the program from the terminal or from my system's CLI, it can't find the modules and I get the same error.
Is there some extra configuration for jep that I need to do to be able to use other python modules with it? or is jep just not compatible with other modules?
EDIT
For further clarification here are the run configurations for Java and Python.
Java run configuration:
Python run configuration:
I fixed it thru this code you call before JEP interpreter:
PyConfig pyConfig = new PyConfig();
pyConfig.setPythonHome("/home/user/[NEW_PYTHON_HOME]/");
try {
MainInterpreter.setInitParams(pyConfig);
} catch (JepException e) {
e.printStackTrace();
}
Ali

NetBeans cannot connect to repository at (gitlab repository)

Yesterday I installed a new version of Netbeans (NetBeans IDE 8.2 (Build 201705191307)) and since then I can't connect to my gitlab repo (fails on trying to clone project). Credentials are fine, work on other computers and systems and I logged in over the browser(my first thought was that I tried a wrong password and banned my IP).
I use Windows 10, Java 1.8.0_31.
EDIT: Access to gitlab worked on an older version of NetBeans (not sure which one was it but above 8.0)
Updated JDK to 1.8.0_171 - still no success.
Also this was found in IDE log
INFO [org.netbeans.modules.git]: java.lang.InternalError: Should not get here
java.lang.InternalError: Should not get here
at sun.nio.fs.WindowsNativeDispatcher.CreateSymbolicLink0(Native Method)
at sun.nio.fs.WindowsNativeDispatcher.CreateSymbolicLink(WindowsNativeDispatcher.java:901)
at sun.nio.fs.WindowsFileSystemProvider.createSymbolicLink(WindowsFileSystemProvider.java:578)
at java.nio.file.Files.createSymbolicLink(Files.java:1043)
at org.eclipse.jgit.util.FileUtil.createSymLink(FileUtil.java:96)
at org.eclipse.jgit.util.FS_Win32_Java7.detectSymlinkSupport(FS_Win32_Java7.java:80)
at org.eclipse.jgit.util.FS_Win32_Java7.supportsSymlinks(FS_Win32_Java7.java:71)
at org.eclipse.jgit.internal.storage.file.FileRepository.create(FileRepository.java:306)
at org.eclipse.jgit.lib.Repository.create(Repository.java:169)
at org.netbeans.libs.git.jgit.commands.InitRepositoryCommand.run(InitRepositoryCommand.java:89)
at org.netbeans.libs.git.jgit.commands.GitCommand$1.run(GitCommand.java:80)
at org.netbeans.libs.git.jgit.commands.GitCommand$1.run(GitCommand.java:77)
at java.security.AccessController.doPrivileged(Native Method)
at org.netbeans.libs.git.jgit.commands.GitCommand.execute(GitCommand.java:77)
at org.netbeans.libs.git.GitClient.init(GitClient.java:871)
at org.netbeans.modules.git.client.GitClient$33.call(GitClient.java:574)
at org.netbeans.modules.git.client.GitClient$33.call(GitClient.java:570)
at org.netbeans.modules.git.client.GitClient$CommandInvoker$1$1.call(GitClient.java:956)
at org.netbeans.modules.git.client.GitClient$CommandInvoker$1.call(GitClient.java:979)
at org.netbeans.modules.git.FilesystemInterceptor.runWithoutExternalEvents(FilesystemInterceptor.java:496)
at org.netbeans.modules.git.Git.runWithoutExternalEvents(Git.java:282)
at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethodIntern(GitClient.java:989)
at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:916)
Caused: org.netbeans.libs.git.GitException
at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:932)
at org.netbeans.modules.git.client.GitClient$CommandInvoker.runMethod(GitClient.java:898)
at org.netbeans.modules.git.client.GitClient$CommandInvoker.access$400(GitClient.java:892)
at org.netbeans.modules.git.client.GitClient.init(GitClient.java:570)
[catch] at org.netbeans.modules.git.ui.clone.RepositoryStep$RepositoryStepProgressSupport.perform(RepositoryStep.java:323)
at org.netbeans.modules.git.client.GitProgressSupport.performIntern(GitProgressSupport.java:115)
at org.netbeans.modules.git.client.GitProgressSupport.run(GitProgressSupport.java:108)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)
The stack trace shows that the code failed when trying to create a symbolic link by calling Files.createSymbolicLink(). To do that on Windows 10 you must run with Administrator rights, or you need to have the right to create a symbolic link, so the true solution to your problem is to set appropriate User Account Control (UAC). This is the case even if you created the file or directory to which you want to add a symbolic link.
If you open a Command Prompt window, create a directory and then try to add a symbolic link it will fail with the error "You do not have sufficient privilege to perform this operation", but if you do the same thing when selecting Run as Administrator before opening a Command Prompt window it works fine:
The same principles apply when creating a symbolic link in a Java application on Windows 10, and again the proper solution is to set UAC appropriately. However, there is an easy workaround solution: just as you can open a Command Prompt window as an administrator, you can also run NetBeans as an administrator:
Once you do that the java.lang.InternalError should be gone.
You can run the trivial Java application below to confirm that admin rights are needed when creating a symbolic link under Windows 10. The application fails with a FileSystemException ("A required privilege is not held by the client.") when calling Files.createSymbolicLink() from NetBeans if it is started normally, but works fine when NetBeans is Run as administrator.
public class SymLink {
public static void main(String... args) throws IOException {
String originName = "c:\\ThisIsJunk";
String targetName = originName + "SymLnk";
Path origin = Files.createDirectories(Paths.get(originName));
Path target = Paths.get(targetName);
try {
Files.delete(target);
} catch (NoSuchFileException e) {
}
try {
Path symLink = Files.createSymbolicLink(target, origin);
System.out.println("Symbolic link created: " + symLink.toString());
} catch (AccessDeniedException e) {
e.printStackTrace();
}
}
}
After having the same issue mentioned above while running in Administrator Mode, I noticed I had Netbeans running in Windows 8 Compatibility mode. Unchecking compatibility mode, I was then able to connect to the Github repository.

How to access methods from main regarding an array [duplicate]

There was error occurred in Line 14.
Exception in thread "main" java.lang.RuntimeException: Uncompilable
source code - Erroneous sym type:
Hard to find solution.
package example;
public class Num
{
public static void main(String [] args)
{
String s = "42";
try
{
s = s.concat(".5");
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s).doubleValue()); //Line 14
System.out.println(x);
}
catch (NumberFormatException e)
{
System.out.println("Wrong Number");
}
}
}
The code you provided runs fine on my computer.
I'm guessing you are using Netbeans and may be affected by a bug.
Try this:
Open the project properties, select the Build-Compiling, uncheck "Compile on save" and rerun the application. This will make sure all your source code becomes recompiled before running it.
Link: https://forums.netbeans.org/topic43241.html
This is a common issue which I get while working. What I do is clean and build the project. It solves the problem.
Right Click on the project name >> Clean and build
Download/install JDK major version number the same as NetBeans.
i.e. If You have NetBeans 9 version, but your JDK is version 10,then try use NetBeans 10 version... or download/install JDK 9 (the same as NetBeans).
Create new java platform for new jdk installation.
Open netbeans menubar->tools->Java Platforms->Add Platform
Specify the folder that contains the Java platform as well as the sources and Javadoc needed for debugging.
Set new java platform to your project
Right click on project ->properties->Libraries->Java Platform->select the jdk version that same as NetBeans
Select source format of your project
Right click on project ->properties->Sources->Sources/binary format->select the jdk version that same as NetBeans.
If it still gives errors like,
Exception in thread "main" java.lang.RuntimeException:
at javaapplication2.JavaApplication2.main(JavaApplication2.java:1)
C:\Users\James\AppData\Local\NetBeans\Cache\dev\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\James\AppData\Local\NetBeans\Cache\dev\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 1 second)
do as "sinclair" has mentioned above.
Open the project properties, select the Build-Compiling, uncheck "Compile on save" and rerun the application. This will make sure all your source code becomes recompiled before running it.
I received this error after I'd changed the type of a function parameter and it was the calling page that was in error - but I didn't see this until a magical Clean and Build pointed me to the actual issue!
I got this error message because I copied and pasted code without including the package name. I added the package name and it was fixed.
in my case
i have solved using import with package name and class name
like this import package.class1;
Please uncheck "Compile on save"

Compiling and running with JavaFX 2.1

I am trying a very simple use of JavaFX using a simple set of lines of code which I got from another stackoverflow page (here). But, the problem is clearly not with that code but with something more fundamental in the build and run process.
Here is my code:
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
.
.
.
Media medMsg = new Media("msg.mp3");
MediaPlayer medplMsg = new MediaPlayer(medMsg);
medplMsg.play();
At first I couldn't get this to compile at all. Eventually I figured out that I needed to put -classpath c:\Program Files\Oracle\JavaFX 2.1 SDK\lib\rt\jfxrt.jar on my javac command line. (One obvious complex of questions here is: Why isn't it documented in any obvious place (1) that this is needed and (2) how exactly to figure out what the path to the JavaFX installation is?!)
But, when I run the code I get:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/scene/media/Media
at progtest.main(progtest.java:120)
Caused by: java.lang.ClassNotFoundException: javafx.scene.media.Media
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
What does this mean? It looks like it doesn't know, at runtime, how to find the class javafx.scene.media.Media. But, my %CLASSPATH% variable definitely has "c:\Program Files\Oracle\JavaFX 2.1 SDK\lib\rt\jfxrt.jar" in it.
Any ideas? Thank you in advance!
This question somewhat duplicates compile javafx 2.0 manually.
This answer is specifically for JavaFX 2 versions before the release of Oracle Java 8. For Oracle JavaFX 8+, the JavaFX runtime is on the classpath, so you don't need to explicitly add it when compiling or JavaFX running applications.
Java includes JavaFX in jdk7u6 and above (for Windows and Linux) and jdk7u4 and above (for OSX).
Download and use jdk7u6+ and you won't need to specify the jfxrt.jar file in any classpath and all of your JavaFX related classpath issues should go away.
Here is a link to an early binary build of jdk7u6.
For JavaFX 2.1 on Windows you do need to include the jfxrt.jar lib in your classpath for compile (NetBeans will do this automatically if you use it's JavaFX platform settings) and (if you haven't packaged your app correctly using the javafxpackager or JavaFX ant tasks), also at runtime.
JavaFX 2.1 for Linux is a pre-release (in case you are using that). For the Linux pre-release you would only have to include jfxrt.jar in your classpath at both compile and runtime if the JavaFX runtime on Linux was not set up correctly.
Here is an example of a command line compilation and execution of a JavaFX program under windows.
Launch an editor:
C:\dev\test>notepad HelloWorld.java
Paste the following code and save it:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) {
stage.setScene(new Scene(new Label("Hello World")));
stage.show();
}
}
Compile and run it JavaFX 2.2:
C:\dev\test>javac -cp "\Program Files\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" HelloWorld.java
C:\dev\test>java -cp ".;\Program Files\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" HelloWorld
For Oracle Java 8+, the explicit JavaFX classpath specifier is not required:
C:\dev\test>javac HelloWorld.java
C:\dev\test>java HelloWorld
Note that usually rather than just compiling the code and running it, you would also package the code with javafxpackager or the javafx ant tasks. These tasks will embed a launcher class into your packaged app which will detect the version and location of the JavaFX runtime so that you don't need to specify the jfxrt.jar location unless you want to override the default location for the platform.
For Java 7 update 21, Windows XP SP3, I used
javac -cp "\Program Files\Java\jre7\lib\jfxrt.jar" HelloWorld.java
and
java -cp ".;\Program Files\Java\jre7\lib\jfxrt.jar" HelloWorld

Categories