ClassNotFoundException com.ibm.db2.jcc.DB2Driver - java

I have the following code:
import java.sql.*;
public class ImageDB
{
public static void main(String[] args)
{
try
{
Class.forName("com.ibm.db2.jcc.DB2Driver");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
My CLASSPATH has the db2jcc.jar:
.;
E:\All_Junk\DB2\java\db2java.zip;
E:\All_Junk\DB2\java\db2jcc.jar;
E:\All_Junk\DB2\java\sqlj.zip;
E:\All_Junk\DB2\java\db2jcc_license_cu.jar;
E:\All_Junk\DB2\BIN;
E:\All_Junk\DB2\java\common.jar
and related paths from my Path variable:
C:\Program Files\Java\jdk1.8.0_45\bin;
C:\Program Files\ibm\gsk8\lib64;
C:\Program Files (x86)\ibm\gsk8\lib;
E:\All_Junk\DB2\BIN;
E:\All_Junk\DB2\FUNCTION;
E:\All_Junk\DB2\samples\repl;
E:\All_Junk\DB2\java
So my question is: why am I still getting the error? Everything I've seen regarding this error has said that updating the CLASSPATH and/or Path variables will fix this, however Java is still unable to find the driver class.

did you try adding the Driver to the Java project build path and see if it can find that one.

Related

Can't use java.io.* on CodeRunner

import java.io.*;
public class WriteFile {
public static void main(String[] args){
try {
FileWriter writer = new FileWriter("Test.txt");
writer.write("this is a plain text file.\n");
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
错误: 找不到或无法加载主类 O:WriteFile
原因: java.lang.ClassNotFoundException: O:WriteFile
This code can run on both eclipse and vs Code but not on Coderunner. How to solve it.
Your classpath is broken.
Method #1
Try adding the classpath while running it.
On windows:
java -classpath .;yourjar.jar YourMainFile
On Unix:
java -classpath .:yourjar.jar YourMainFile
Method#2
Configure the build path in your IDE and add an external JAR containing your class to the build path.
Method#3
Please read this to resolve the issue.
Note:
You could also refer to this.

terminating: libs to export not found on above classpath: /sikulixlibs/windows/libs64

I am writing sikuli scripts in Eclipse..
I have added sikulixapi-1.1.0.jar and sikuli-3.0.0 in Eclipse Project build path.
I am getting following error:
*** classpath dump end
[error] RunTimeINIT: *** terminating: libs to export not found on above classpath: /sikulixlibs/windows/libs64
Picked up _JAVA_OPTIONS: -Xmx512M
I have added folderpath where the jar is there, i have added in Environment Variable as Path
How to resolve this issue?
Here is my code..
import org.sikuli.script.Button;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Key;
import org.sikuli.script.Match;
import org.sikuli.script.Screen;
import org.sikuli.script.Keys;
public class test {
/**
* #param args
* #throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
try{
Screen s = new Screen();
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\step1.png");
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\step2.png");
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\field38.png");
Thread.sleep(2000);
s.type("D");
s.type(Key.TAB);
if(s.exists("C:\\Users\\eguru\\Desktop\\sikuli\\warningOkbutton.png")!=null){
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\warningOkbutton.png");
}
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\step3.png");
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\lastnametextfield.png");
s.type("a",Key.CTRL);
s.type(Key.DELETE);
s.type("Last Name for CTR");
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\firstnametextfield.png");
s.type("a",Key.CTRL);
s.type(Key.DELETE);
s.type("First Name for CTR");
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\step4.png");
s.click("C:\\Users\\eguru\\Desktop\\sikuli\\step0.png");
String typeoffiling = "C:\\Users\\eguru\\Desktop\\sikuli\\typeoffilingcheckbox.png";
while(s.exists(typeoffiling)== null){
s.wheel(Button.WHEEL_DOWN, 5);
}
s.click(typeoffiling);
//s.click("C:\\Users\\eguru\\Desktop\\sikuli\\typeoffilingcheckbox.png");
Thread.sleep(10000);
String saveButton = "C:\\Users\\eguru\\Desktop\\sikuli\\savebutton.png";
while(s.exists(saveButton)== null){
s.wheel(Button.WHEEL_DOWN, 5);
}
s.click(saveButton);
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
You have to double click the .jar.
There's a setup over there. I selected pack 2 and 3.
1.Download this jar file, https://mvnrepository.com/artifact/org.sikuli/SikuliX-Setup/1.1.0
Double click and select your options
I will generate sikulixapi.jar and sikulilibswin-1.1.0
link those jars with java build path -> classpath.
Ctrl+B build all
I hope your issues has been solved.
For people who do not have the solution of our partner alansiqueira27 (that my example), they should be downloaded directly,
sikulixlibswin-1.1.1.jar (last version windows)
with these lib should not have problems in windows and that is the link:
https://jar-download.com/cache_jars/com.sikulix/sikulixlibswin/1.1.1/jar_files.zip

How to get path to class file in eclipse and linux in java?

In eclipse for windows, when I run
public class HelloWorld {
public static void main(String[] args) {
System.out.println(System.getProperty("user.dir"));
}
}
It gives me the path of the project root folder (which contains the bin folder which has the class file). For example
SampleProject
and the class file is actually located at
SampleProject\bin\myclass.class
But if I run the same program in linux with
javac myclass.java
java myclass
it gives me the directory that has the .class file, which is the same as pwd command. This is what I want in eclipse for windows. I want some code that will give me the path to the class file in both eclipse for windows and linux.
Does anyone know how do this?
Thanks
If I understand you correctly, you'd like a method that retrieves a class' path on disk. This is easily achievable, like so:
public String getClassPath(Class c) {
try {
return c.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
} catch (URISyntaxException e) {
e.printStackTrace();
}
return null;
}
NOTE this will work even if the class is contained in a jar file. It will return the path to the jar in this case.
The easiest way is to do this:
public class HelloWorld {
public static void main(String[] args) {
System.out.println(HelloWorld.class.getResource("HelloWorld.class"));
}
}

How to call a class from another in th same package shows an error how to fix it in java?

How to call a class from another in th same package shows an error how to fix it?
i have three classes
FirstPack.java
SecondPack.java
Main.java
Here is my FirstPack.java
//FirstPack.java
package mypack.in;
public class FirstPack
{
public void fun()
{
try
{
System.out.println("First Package");
}
catch(Exception ae)
{
}
}
}
Here is my SecondPack.java
//SecondPack.java
package mypack.in;
public class SecondPack
{
public void fun()
{
FirstPack f=new FirstPack();
f.fun();
try
{
System.out.println("Second Package");
}
catch(Exception ae)
{
}
}
}
Here is my Main.java
//Main.java
import java.lang.*;
import mypack.in.*;
class Main
{
public static void main(String args[])
{
try
{
//FirstPack obj_fp=new FirstPack();
//obj_fp.fun();
SecondPack obj_sp=new SecondPack();
obj_sp.fun();
}
catch(Exception ae)
{
}
}
}
On compiling Firstpack.java ie javac FirstPack.java - no problem
On compiling SecondPack.java ie javac SecondPack.java- Error ....
C:\JAVASAMPLE\Package\Three\mypack\in>javac SecondPack.java
SecondPack.java:7: cannot find symbol
symbol : class FirstPack
location: class mypack.in.SecondPack
FirstPack f=new FirstPack();
^
SecondPack.java:7: cannot find symbol
symbol : class FirstPack
location: class mypack.in.SecondPack
FirstPack f=new FirstPack();
^
2 errors
And, on compiling Main.java ie javac Main.java - no problem
Package - mypack.in FirstPack.java and SecondPack.java Outside mypack.in Main.java Sir if without package yes it workinf but with pakage it didnt working I am not using any IDEs
[EDIT]
Note, you should not be compiling each class independently. The Java compiler is designed to compile each class as it encounters the first instance of it in your source file. Compile your Main.java from the root directory, and you won't have any errors.
[/EDIT]
[SECOND EDIT]
I believe this is all happening because the javac compiler begins looking for classes in the current directory and then searches through sub-directories. Since FirstPack is part of the mypack.in package, it needs to be in a folder ./mypack/in/ beginning from the current directory (the directory you execute the compiler from. Basically, your compiler knows that FirstPack is actually mypack.in.FirstPack and will begin looking for ./mypack/in/FirstPack from wherever the file you are trying to compile is residing.
http://kevinboone.net/classpath.html
[/SECOND EDIT]
Although it is throwing an error on compilation, this program is executing properly for me. Ensure that Main.class is in the root directory, and that FirstPack and SecondPack are in %root%\mypack\in
I can't tell you exactly why all of this is the way it is, but I know it's working this way.
You can do it like this:
///**Import the Package
import mypack.in.FirstPack;

Extracting Text From JPG

I've tried this code and added the needed jar files but still I'm getting an error message like Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302'.
Is there a complete tutorial how to extract text and what things should be done to address the error? Any help is appreciated...
import net.sourceforge.tess4j.*;
import java.io.File;
public class ExtractTxtFromImg {
public static void main(String[] args) {
File imgFile = new File("C:\\Documents and Settings\\rueca\\Desktop\\sampleImg.jpg");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
try {
String result = instance.doOCR(imgFile);
System.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
In addition to adding the jars, you also need to add the natives. You can do so with Djava.library.path="C:\[absolute path to dir containing *.dll files and such]"
Note that you need to provide the directory, not the file itself.

Categories

Resources