Unable to import JAR files? - java

I need a particular JAR file, fo execute a code. I am able to run the code In eclipse by adding the JAR file to libraries.
But when I run he code from cmd prompt I get error saying unable to import javax.jms(the jar file).
C:\tibco\ems\8.5\samples\java\JNDI>javac tibjmsJNDIFT.java
tibjmsJNDIFT.java:43: error: package javax.jms does not exist
import javax.jms.*;
^
tibjmsJNDIFT.java:108: error: cannot find symbol
ConnectionFactory connectionFactory =
^
symbol: class ConnectionFactory
location: class tibjmsJNDIFT
tibjmsJNDIFT.java:109: error: cannot find symbol
(ConnectionFactory)jndiContext.lookup(factory[j]);
^
symbol: class ConnectionFactory
location: class tibjmsJNDIFT
3 errors
C:\tibco\ems\8.5\samples\java\JNDI>

You should use the "-cp" or "-classpath" option:
javac -cp ".:/path/to/jms.jar:/path/to/any-other.jar" tibjmsJNDIFT.java
On Windows OS you might have to use "semicolons" (;) instead of "colons" (:)

Related

Java cannot find package when importing

I have a file structure as follows:
src/cs/example/Hello.java
src/cs/utility/HelloHelp.java
bin/cs/example/Hello.class
bin/cs/utility/HelloHelp.class
The package and import statements in Hello.java are:
package cs.example;
import cs.utility.MyMethods;
While the package statement in HelloHelp is:
package cs.utility;
I attempt to run Hello (that uses a method from HelloHelp):
java -cp src/cs/utility src/cs/example/Hello.java
src/cs/example/Hello.java:2: error: package cs.utility does not exist
import cs.utility.HelloHelp;
^
src/cs/example/Hello.java:10: error: cannot find symbol
int max = HelloHelp.borp(intOne,intTwo);
^
symbol: variable HelloHelp
location: class Hello
Any help on resolving this issue would be very useful, thank you!
In your java -cp call you are pointing to your .java files instead of your .class files in /bin.
Try changing your java command to use the class files instead. Something like the following should work:
java -cp "bin/*" cs.example.Hello

Hadoop- How can I fix the errors of compilation

I downloaded a program contains 8 Java classes and 2 files.sh ( compile.sh and execute.sh ) and one jar file. I edit the Jars locations in compile.sh file, but when I compile it I got a Java errors like:
graphMining.java:19: error: cannot find symbol
import org.apache.hadoop.util.ToolRunner
symbol: class ToolRunner
location: package org.apache.hadoop.util
graphMining.java:22: error: package org.apache.hadoop.io.compress does not exist
import org.apache.hadoop.io.compress.CodecPool;
graphMining.java:121: error: cannot find symbol
public void reduce(Text symbol, Iterator values, OutputCollector output, Reporter reporter)
I fixed JAVA_HOME path in hadoop-env.sh and when I write echo $JAVA_HOME it works. What should I do please?

Java Symbol not found through javac weird error (Runs through Eclipse)

My project runs smoothly in Eclipse, no errors at all. I ran it through local tests (that are equal to the ones in an online mooshak contest) and all checks out. But when I sumbit it online, I get a CompileTimeError.
To try to locate the problem, I attempted to use javac in Main.java, and this happened:
javac -encoding US-ASCII Main.java
Main.java:8: error: package code does not exist
import code.*;
^
Main.java:129: error: cannot find symbol
public static void addWords(Scanner in, LibSystem system, int wordCount)
{
^
symbol: class LibSystem
location: class Main
Main.java:153: error: cannot find symbol
public static void searchWord(LibSystem system, String word) {
^
Other symbol errors follow for every reference to classes from my only package, which I fully import and the header of Main, for a total of 29 errors.
Project
src
Main.java
code (package with all my other java files)
Follow these steps :-
1.) make sure LibSystem class is in classpath.
2.)Compile java files in code folder using -d option. That will create directories with classes.
javac -d . code/*.java
3.) then compile your Main class.
javac Main.java

Compiling Java classes in linux via command line

Hi and thanks for taking the time to answer my questions.
I have two files in my root folder (~/). The Main.Java and TestMain.java. Main.java compiles and runs smoothly. TestMain on the other hand does not. TestMain is basically a test class where I use JUnit to handle different scenarios. I instantiate Main in TestMain but the problem is that the compiler cannot find Main.java.
Here's the code:
user#linuxbox ~ $ javac -cp junit-4.10.jar TestMain.java
TestMain.java:8: error: cannot find symbol
Main mainClass = new Main();
^
symbol: class Main
location: class TestMain
TestMain.java:8: error: cannot find symbol
Main luckyStrings = new Main();
^
symbol: class Main
location: class TestMain
2 errors
How can I make the Main class available to the MainTest.java class? Thanks so much!
In your classpath option, you have set the classpath to only junit-4.10.jar. You must also include the current directory where your Java files reside.
javac -cp "junit-4.10.jar:." TestMain.java
This includes two paths -- JUnit and the current directory, separated by a :. (If this were Windows, then you would use a ; as a separator).
Just another input...
-d can be used to specify the target directory where the compiled class files should be put
javac -d . -cp "junit-4.10.jar:." TestMain.java

Compiling servlets for tomcat

Hello
I am trying to modify one of the default files that comes with tomcat SessionExample.java, and trying to compile it but I get an error.
javac -classpath "E:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.18\lib\servlet-api.jar" SessionExample.java
Gives me this error
SessionExample.java:26: package util does not exist
import util.HTMLFilter;
^
SessionExample.java:90: cannot find symbol
symbol : variable HTMLFilter
location: class SessionExample
out.println(HTMLFilter.filter(name) + " = "
^
SessionExample.java:91: cannot find symbol
symbol : variable HTMLFilter
location: class SessionExample
+ HTMLFilter.filter(value) + "");
^
3 errors
Thank you
You have to compile HTMLFilter. Use can use the -sourcepath switch. See the javac docs. Consider using some IDE like Eclipse or NetBeans

Categories

Resources