Java external library in terminal error - java

In terminal, I get the follow error after I compile my program:
WriteExcel.java:7: error: package jxl does not exist
I compiled the program by typing:
javac -cp /Desktop/folder/src/jxl.jar WriteExcel.java
Basically, how do I get the compiler to recognize the external library?

Related

running a java file in python using os.system()

I'm trying to run the following code in pycharm using python 3.7
os.system("java ToPython")
however I get the following error:
Error: Could not find or load main class ToPython
I tried executing the same java file from terminal:
javac ToPython.java
java topython
and it works perfectly file
note: all the files exist in the same folder

compile and run java code written on Eclipse on cmd prompt

I am trying to run a java project that includes two libraries jpbc-api-1.2.1.jar and jpbc-plaf-1.2.1.jar. The code has been written on Eclipse and I am now trying to run it on the cmd prompt on a Windows machine. I went to the .classpath file and made sure to modify the paths as follows:
classpathentry kind="lib" path="lib/jpbc-api-1.2.1.jar" sourcepath="lib/jpbc-api-1.2.1.jar"
classpathentry kind="lib" path="lib/jpbc-plaf-1.2.1.jar" sourcepath="jpbc-plaf-1.2.1.jar"
Whenever I try to compile my java code I get the following error:
error: cannot find symbol
To compile I used the command:
javac filename.java
That is obviously because the compiler cannot locate the files I am trying to show the path to. Is there a specific way to compile and run the code?
You don't need the compiler to run the program if it's already compiled by Eclipse - you only need the Java runtime. The .classpath file is Eclipse-specific, so it won't be used by either the Java compiler (javac) or the Java runtime (java).
Assuming that your main class is called com.my.MainClass and your classes directory is called "myclasses", you would run your class using this command line:
java -classpath lib/jpbc-api-1.2.1.jar;lib/jpbc-plaf-1.2.1.jar;myclasses com.my.MainClass
I think you should have a look at the documentation of the Java command line tools:
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html
Good luck!

error: could not load or find main class xyz

I have checked my java installations by compiling and running a HelloWorld program which works perfectly fine.
The problem comes when I compile my program with certain jar files which are located in the same directory as my java file. This is what I've done.
javac -cp "A.jar:B.jar" MyProg.java
This generates the class file MyProg.class successfully. Next when I run the following command, it gives this error error: could not load or find main class MyProg
The command is:
java -cp "A.jar:B.jar" MyProg
Next, I even tried next by moving the jars in a folder named lib and issued the following commands:
javac -cp "lib/*" MyProg.jar (works fine;generates a class file)
java -cp "lib/*" MyProg (issues the same error)
I am working on a linux machine. Can some one please resolve the error.
Add the current path to the classpath
java -cp .:A.jar:B.jar MyProg

How do you pass multiple paths to Java -cp command?

So I am trying to compile a file that imports code from 2+ different .jar files.
The following is the command I am using to compile my file:
javac -cp /home/ugrads/majors/quinnliu/workspace/WalnutiQ/build/libs/WalnutiQ.jar:. HowMARK_II_FitsInToBrainAnatomy.java
Now I am getting an error because I am calling code in another .jar file in another folder but I don't know how to add it correctly to my current -cp command above.
Sample of errors I am getting:
HowMARK_II_FitsInToBrainAnatomy.java:3: error: package com.google.gson does not exist
import com.google.gson.Gson;
Use:
javac -cp jar1.jar;jar2.jar source1.java source2.java ...
On Windows you have to use semicolon to separate the JAR files, but on Unix you can use a colon.

OpenKinect Java JNI error: libOpenKinect.so: undefined symbol: libusb_init

I get the following error when making the Java JNI Wrapper for OpenKinect:
java: symbol lookup error:
/home/richard/libfreenect/wrappers/java/dist/libOpenKinect.so:
undefined symbol: libusb_init
I use the Ubuntu Manual Install with the following exceptions:
git://github.com/michael-nischt/libfreenect.git instead of git://github.com/OpenKinect/libfreenect.gitworks, because the JNI wrapper isn't integrated into the main distribution.
freeglut3-dev instead of libglut3-dev.
I am able to run glview successfully.
I modify the build.sh script so that LIBFREENET_LIBRARY refers to the correct directory. The jar build then compiles successfully. The example file compiles correctly.
javac -d ./ -classpath .:./dist/OpenKinect.jar ./OpenKinect/src/Example.java
I get the error when I run:
java -Djava.library.path=./dist -classpath .:./dist/OpenKinect.jar Example
Has anyone else experienced this error?
Has anyone been able to resolve this error?
Verify the dependencies of the shared library libOpenKinect.so:
ldd /home/richard/libfreenect/wrappers/java/dist/libOpenKinect.so/libsample.so
You must find a line with libusb-1.0.so.0. If not this mean that the library is not link to libusb. A solution is to recompile the shared library with the flag -lusb-1.0:

Categories

Resources