I am trying to compile WordCount.java file into jar inside of /Desktop/Hadoop/playground/src.
Here's the command I am using.
javac -classpath hadoop-1.2.1-core.jar -d playground/classes playground/src/WordCount.java
The compiler seem to be getting invoked, however I am getting tons of errors like this
error: package org.apache.hadoop.conf does not exist import org.apache.hadoop.conf.Configuration
How do I go about fixing this?
May be there is an answer to this issue already. However I could not fix it.
You need to set the paths of hadoop-1.2.1-core.jar and all the other dependent jars correctly --
Try this exactly while you are in the Desktop/hadoop directory (valid in your case only solely based upon the inputs you provided in the comments)
javac -classpath *:lib/* -d playground/classes playground/src/WordCount.java
Related
I faced a rather strange problem while executing a java program from the command line on Windows.
I used this command to create a source.class file from a source.java file.
javac source.java
After this, I tried to execute the source.class file using:
java source.class
This gave me the following error:
Error: Could not find or load main class source.class
However, when I do this:
java source
I get the output as desired.
I am curious to know why it failed when I mentioned .class explicitly. My professor told me that the java command is associated with .class files. Thus I want to know why this happened. Thank you.
EDIT: I don't believe this is a duplicate. I have already read the linked question. I am asking why the java command cannot execute a file when I mention .class explicitly.
I have had a hard time making sqoop1 work on hadoop2. I always run int Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.Tool error which suggests that sqoop1 is trying to use hadoop1. But i had downloaded the sqoop1 jar with hadoop 2.0.4-alpha release from http://www.us.apache.org/dist/sqoop/1.4.5/.
Then why does it not work with hadoop2?
PS: I have tried hard to make sqoop2 work, but i faced lot of problems in the setup.
Also, this post http://mmicky.blog.163.com/blog/static/1502901542013118115417262/ suggests that it should work, but i keep running into this ClassNotFoundException.
I figured out the problem. Whatever classpath i was setting was probably being overridden by the hadoop executable. So i had to modify the hadoop executable at the place where it called the java command and add a -cp flag with the classpath of my hadoop jars like below:
exec "$JAVA" -cp "$CLASSPATH:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/common/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/common/lib/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/hdfs/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/hdfs/lib/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/mapreduce/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/mapreduce/lib/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/tools/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/tools/lib/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/yarn/:/usr/local/Cellar/hadoop/2.4.1/libexec/share/hadoop/yarn/lib/" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$#"
That's the problem: I have done a simply Hadoop program to "clean" a graph saved in a text file that I will use later (with Hadoop), but I can't compile it!
The compiler can't find Hadoop classes (IntWritable, Text ecc...), and each time I get a "cannot find symbol" error.
I've tried with:
javac -classpath path/to/hadoop/root/hadoop-core-{version}.jar filename.java
I'm running with ubuntu 11.04, and the Hadoop version is 1.0.3.
the problem is that hadoop-core-{version}.jar depends on some other jars. You can find all the dependencies on the Maven repository web site :
http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-core/1.0.3
You should use Maven or add all the dependencies to your project to be able to build it.
I want run "ReutersToSparseVectors.java". I can compile and created JAR file without problem.
I compiled this file by below command:
javac -classpath hadoop-core-0.20.205.0.jar:lucene-core-3.6.0.jar:mahout-core-0.7.jar:mahout-math-0.7.jar ReutersToSparseVectors.java
created JAR file with below command:
jar cvf ReutersToSparseVectors.jar ReutersToSparseVectors.class
When I write java -jar ReutersToSparseVectors.jar to run, give me below error:
Failed to load Main-Class manifest attribute from
ReutersToSparseVectors.jar
Do you can help me to solve this problem?
IF this example can run with hadoop, please me that how i can run this with hadoop.
instead of using -jar option, then it's better to to run:
java -cp mahout-core.jar:... mia.clustering.ch09.ReutersToSparseVectors
or you can use mvn exec:java command, as described in README for examples...
mvn exec:java -Dexec.mainClass="mia.clustering.ch09.ReutersToSparseVectors"
Or you can run this file directly from your IDE (assuming, that you correctly imported Maven project).
P.S. your command isn't working, because to run with -jar switch, the .jar file should have special entry in manifest that describes that class should be started by default...
P.P.S. It's better to use book's examples with Mahout 0.7, as they were tested for it. You can use it with version 0.7 if you need, by then you need to take source code from mahout-0.7 branch of repository with examples (link is above)
i wanted to practice developing database programs in java so i set the classpath to E:\software\installed\java\jre\lib by declaring a new environmental variable classpath and gave value as E:\software\installed\java\jre\lib but now i am unable to run any program(not even non-database) i get an error
Error: Could not find or load main class MysqlConnect
but when i delete the classpath variable i am able to run non-database programs. what is the possible problem and please let me know the solution. i have set path to E:\software\installed\java\bin
nothing is helping i tried using class path switch in java which is not helping (java -cp C:\Program Files\MySQL\MySQL Server 5.5 MysqlConnect) nor do setting path is helping (set CLASSPATH=%CLASSPATH%:C:\Program Files\MySQL\MySQL Server 5.5:C:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar) all are giving the error
Error: Could not find or load main class MysqlConnect
You shouldn't be defining a classpath for your programs using system variables. Standard way is to use the command line -cp or -classpath option. Take a look at what java prints out if you run it with no arguments.
You will find this mentioned in this tutorial. It says:
The preferred way to specify the class path is by using the -cp command line switch. This allows the CLASSPATH to be set individually for each application without affecting other applications. Setting the CLASSPATH can be tricky and should be performed with care
Also, see how the default CLASSPATH environmetn variable has a . in it. If you still decide to add your classes in there, keep the . for other citizens and add your classes after a ;, don't just overwrite the whole value.
Here's a jdbc tutorial for beginners that could help you find your answer. If you skip to step 14 it gives an example of how the classpath is used. It is used as the first respondent is saying, by command line.
Hopefully this will help you in your particular situation. This tutorial is not database-specific so it will work with any type of database you are using.
ok atlast i got the solution it should be typed as
C:\Users\sarad mohanan\Desktop\rose>java -cp .;"c:\Program Files\MySQL\MySQL Server 5.5\mysql-connector-java-5.1.20-bin.jar" MysqlConnect
MySQL Connect Example.
Connected to the database
Disconnected from database
we have to add .; before the original path . holds default classpath. pravel veller had said it previously but i didn't understand it then
I would like to propose using a good tool like Eclipse. You can test the CLASSPATH indirectly and your environment by adding or removing jar files and libraries.
Obviously, the libraries in your default CLASSPATH is different than the one in your E drive. You may compare the files by knowing your CLASSPATH. In Windows, do "echo %CLASSPATH%".
Eclipse can help you by experimenting without rebooting or any annoying steps. And this stuff is not easy.
Crete o set environment variable if you use windows JAVA_HOME=E:\software\installed\java, and after append the Java bin directory %JAVA_HOME%\bin. Note that paths are separated from each other with semicolons (;) I hope help you. That's work for me !!!. I don't understand. What happen?.