I was learning about Frege and saw this command line:
$ java -Xss1m -cp build:fregec.jar examples.SimpleIO
I've never seen that build: before. What does that mean and what does it do?
More context: https://github.com/Frege/frege/issues/289
I don't see it documented in this official article or when I type java at the command line.
: is the separator, so it's including build and fregec.jar on the classpath.
Looking at Frege specifically, you first use it to compile some code and create some class files in the build directory. For example:
java -Xss1m -jar fregec.jar -d build SimpleIO.fr
Then to run the compiled code you need both Frege itself, and the class files you just created, on the classpath:
java -Xss1m -cp build:fregec.jar examples.SimpleIO
Related
I have 4 Java-Data:
Common.java
Constants.java
KeywordsEditor.java
ExecutionEngine.java (There is here a Main-Method)
I have successful compiled in Command-Line with this Command from Project-Directory (C:\ProjectDemo\src\main\java\ValueInput)
javac -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar" *.java
I got 4 Data .class in the same Directory. Now i want to run them with this code:
java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar" ExecutionEngine
But i got Error:
Error: ExecutionEngine main class could not be found or loaded
```
I've tried with some same code else:
```
java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;libs\*;selenium-server-standalone-3.141.59.jar" ExecutionEngine
java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;libs/*;selenium-server-standalone-3.141.59.jar" ExecutionEngine
```
And some more, but they don't work. Can somebody help me?
Update
From your comment, I learnt that you have package ValueInput; mentioned in ExecutionEngine.java. Therefore, you should use the switch -d when compiling:
javac -d . -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar" *.java
The option -d . asks the compiler to place the generated class files at the current directory. Now, if you use the command ls in Mac/Unix or dir in Windows, you will see a directory, ValueInput has been created and all the .class files have been placed inside this directory. Learn more about the switches by simply using the command javac
In order to execute ExecutionEngine.class, you can now use the following command:
java -cp ".;C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar" ValueInput.ExecutionEngine
You can also check this answer for a similar solution.
Side note: You should follow the Java naming conventions. As per the convention, the name of the package should be something like value.input.
Original answer
The root cause of the problem is using only jars with -cp. You missed realizing that your ExecutionEngine.class is not in the jars; rather it is at the current directory which is denoted by a dot (.) which you missed to include in the classpath.
Thus, the correct command will be:
java -cp ".;C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar" ExecutionEngine
It doesn't matter where you put . i.e. the current directory e.g. the following will also work for you:
java -cp "C:\Users\ABC\selenium-java-2.48.2\selenium-2.48.2\selenium-java-2.48.2.jar;selenium-server-standalone-3.141.59.jar;." ExecutionEngine
Note for Mac:
The separator used for this purpose in Mac is : instead of ; e.g.
javac -cp mysql-connector-java-5.1.49.jar MysqlDemo.java
java -cp mysql-connector-java-5.1.49.jar:. MysqlDemo
Note for Java-11 onwards:
Java-11 allows launching Single-File Source-Code programs without compiling e.g.
java -cp mysql-connector-java-5.1.49.jar MysqlDemo.java
You can learn more about it from this article.
I'm trying to compile some java code for hadoop and need to know what classpath I need to specify. For cloudera I use this below but what do I use for a MapR installation? Surprisingly I could only find how to set the classpath in google, not what to set it to.
javac -classpath "/opt/cloudera/parcels/CDH-4.6.0-1.cdh4.6.0.p0.26/lib/hadoop/client/*" mr.java -d mr
Found the answer by trial and error. Oddly google is very silent on this and all the books and examples I've read appear to assume this is too obvious to bother printing.
mkdir MyClass
javac -classpath "/opt/mapr/hadoop/hadoop-0.20.2/lib/*" MyClass.java -d MyClass
jar -cvf MyClass.jar -C MyClass .
Additionally, if you want the hive libraries, eg for compiling a hive UDF:
javac -classpath "/opt/mapr/hadoop/hadoop-0.20.2/lib/*:/opt/mapr/hive/hive-0.12/lib/*" MyClass.java -d MyClass
EDIT: one thing I would add is make sure you put quotes around the path, otherwise linux expands it on the command line which is not what you want. The * in the path needs to be passed to java as is.
It seems that all of the examples are constructed with older versions in mind.
How do I compile my java program on Ubuntu such that it will refer to hadoop-2.2.0 libraries?
Where are the jar files that I am supposed to include?
What is the command?
Is it like -
javac -classpath libraries wordcount.java
Thank you.
The simplest solution for Linux machines would be:
javac -classpath `yarn classpath` -d . WordCount.java
Or:
export CLASSPATH=`yarn classpath`
javac -classpath $CLASSPATH -d . WordCount.java
I found the following:
javac -classpath $HADOOP_HOME/share/hadoop/common/hadoop-common-2.2.0.jar:$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.2.0.jar:$HADOOP_HOME/share/hadoop/common/lib/commons-cli-1.2.jar -d wordcount_classes myWordCount.java
This allowed me to compile the Wordcount example (or in this case a copy of mine called myWordCount).
Hadoop has a command "hadoop classpath" that supplies you with the necessary classpath.
ie
hadoop classpath
/etc/hadoop/conf:/usr/lib/hadoop/lib/:/usr/lib/hadoop/.//:/usr/lib/hadoop-hdfs/./:/usr/lib/hadoop-hdfs/lib/:/usr/lib/hadoop-hdfs/.//:/usr/lib/hadoop-yarn/lib/:/usr/lib/hadoop-yarn/.//:/usr/lib/hadoop-mapreduce/lib/:/usr/lib/hadoop-mapreduce/.//
So if you wanna compile you can use it this way..
javac -classpath $(hadoop classpath) -d . WordCount.java
you have to instal Cygin and there you can run your hadoop example and also you can configure your hadoop with eclipse
Run the command: "yarn classpath" to see a list of directories. When I use this list as my -classpath option for javac, my Java program compiles.
I am running HortonWorks v2.0, Apache Hadoop 2.2.0.
I'm having bumpy ride with Hadoop Example jars too. Information in many videos/tutorials/blogs is based on older version.
When we compile these examples or write any of our own MapReduce program, that is going to use hadoop packages (i.e. import jar in IDE/add reference to external jars - akin to Add reference to .dll in MS Visual Studio), and IDE will take care of correctly calling javac for each class.
Now for manually compiling any class e.g. WordCount.java, we need to tell javac which all jars our class is dependent on. I followed outdated videos but that shared one information i.e. to set a variable in .bashrc, having reference to all Hadoop related jar files and then use that in javac -classpath $VARIABLE filename.java.
e.g. I'm using name as $HADOOP_CLASSPATH and values as shown here (I'm on Mac OS X)
/usr/local/hadoop/etc/hadoop:/usr/local/hadoop/etc/hadoop:/usr/local/hadoop/etc/hadoop:/usr/local/hadoop/share/hadoop/common/lib/:/usr/local/hadoop/share/hadoop/common/:/usr/local/hadoop/share/hadoop/hdfs:/usr/local/hadoop/share/hadoop/hdfs/lib/:/usr/local/hadoop/share/hadoop/hdfs/:/usr/local/hadoop/share/hadoop/yarn/lib/:/usr/local/hadoop/share/hadoop/yarn/:/usr/local/hadoop/share/hadoop/mapreduce/lib/:/usr/local/hadoop/share/hadoop/mapreduce/:/contrib/capacity-scheduler/.jar:/usr/local/hadoop/share/hadoop/yarn/:/usr/local/hadoop/share/hadoop/yarn/lib/*
with this variable, I could compile class successfully.
"javac -classpath $HADOOP_CLASSPATH WordCount.java "
What is the difference in calling the -classpath option from javac and from java
for example:
javac -classpath MyJar.jar GetJar.java
java -classpath MyJar.jar:. GetJar
it works as well as:
javac -classpath MyJar.jar GetJar.java
java GetJar
So basically where the first -classpath related to javac needs to be there, on the other hand in the java command line it might be optional. Why? Do you know in which circumstance it would be mandatory. And more in general what is the effect of -classpath called by javac and what is the effect of -classpath called by java.
Thanks in advance.
One is the classpath used for compiling. The other is the classpath used for running. And they do not have to be the same thing. The set of classes needed for the compilation processes are all those referred to by every class being compiled. Whereas your runtime JAR could be invoking a standalone class with an empty main method and no dependencies.
Just remember that at runtime class dependencies are resolved dynamically, aka a class is only loaded when it is needed (this is a generalization, boot and system classes are always loaded).
This document contains answers for your questions
http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/javac.html
using -classpath every time is a very time consuming work. Instead, use environment variables (if you are dealing with a package such as Java Mail)
classpath is used for compiling. Javac is the Java Compiler, where it converts your code into byte code.
When it comes to java it is used to run your Java source file/jar.
I have a folder on my desktop titled "Stuff" and in that folder I have the following:
Hello.java
mail.jar
And Hello.java imports from mail.jar, so I need to tell Hello.java to look for mail.jar.
From a Windows command line and from a unix command line, how can I compile this and run this?
Compile:
javac -cp .;mail.jar Hello.java
where ; is for Windows; use : for *nix.
and run:
java -cp .;mail.jar Hello
where again, use ; for Windows and : for *nix.
-cp tells both javac and java what classpath to use, and as your files are in the local directory where you're executing the command, you can use . for the Hello part and the name of the jar for the paths inside the jar. Wikipedia has a decent article on classpaths.
Mind you, if you're going to be doing this on a regular basis, you may want to set your CLASSPATH environment variable rather than constantly using the -cp flag. Both java and javac use the CLASSPATH variable.
For my own development machine, I actually include . in my CLASSPATH variable, for convenience. It's not something I would do on a production or build/test box, but it's very handy for development purposes. You'd want to have your usual jars in it as well.
Assuming Hello.java does not contain a package declaration, on Windows:
javac -cp mail.jar Hello.java
java -cp mail.jar;. Hello
The only difference on Unix platforms is that you separate the elements of the classpath with a scolon instead of a semicolon:
java -cp mail.jar:. Hello
Follow this tutorial and you should be able to do it in no time:
Java Compilation
You also shouldn't have any problems with the classpath because your classes are in the same folder