xxx not identified as internal or external command - java

Sry for bringing this question again as its most common solution would be to include path.. I am trying to implement a class and after implementation it displays the following
java -classpath java-getopt-1.0.8.jar;3dm-0.1.0.jar;xerces.jar tdm.
tool.TreeDiffMerge
3DM XML Tree Differencing and Merging Tool version 0.1.0 build 0.1.0-2006.02.07.
12.26.44
Usage: 3dm [options] {-m base branch1 branch2|-d base branch1 |-p base patch} [o
utfile]
Use the -m (or --merge) option to merge the files base, branch1 and branch2
Use the -d (or --diff) option to diff the files base and branch1
Use the -p (or --patch) option to patch the file base with the file patch
The options are:
-e, --editlog[=logfile]
Log edit operations to logfile, default edit.log
-c, --copythreshold=bytes
Threshold for considering a duplicate structure to be a copy. Default value i
s 128 bytes
Now a exe is not created ..Do u know wht the pblm might be.. Or can u suggest ways to solve this issue ?

The output doesn't seem to have anything to do with your question title.
It's clear from the message that you aren't invoking the tool properly, and need to provide command-line arguments to the tool in order to tell it what to do. E.g.:
java -classpath java-getopt-1.0.8.jar;3dm-0.1.0.jar;xerces.jar tdm.tool.TreeDiffMerge -p base patch
If you've implemented your own main class and want to invoke it, you'll need to provide the classname on the command line instead of tdm.tool.TreeDiffMerge. (And if you want an exe to be created, hopefully your class does this because Java has absolutely nothing to do with creating exes inherently.)

Related

Correct way to pass the argument for the main method in this class in command line java

Can arguments for a class be passed the following way?
java cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
Here, cs123 is the package within which the different java files and their compiled versions are located. I have already compiled the .java files using the following command
javac -cp commons-cli-1.2.jar cs123\*.java
To make things clear, the structure of the .java and .jar files are
lib
|--cs362
| |--all the java files including Learn.java
|--commons-cli-1.2.jar
I am running the command prompt from the lib folder. What worries me is that from java documentation and other sources the format for passing arguments is simply an array of strings and for options it can be seen from java documentation too. Using the above run time java execution, I get the
java.lang.ClassNotFoundException: org.apache.commons.cli.OptionBuilder
but if I execute,
java -cp commons-cli-1.2.jar cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
I get the following error
Unrecognized option: -mode
Error: Could not create the Java Virtual Machine
Error: A fatal exception has occured. Program will exit.
I understand that java tries to associate anything with a - associated with it as a predefined option, -mode not being the one it recognizes. but at the same time the .jar file is there to do it's job. For research purposes, the commons-cli-1.2.jar file is associated with several methods, two of them being commons/cli/Option and commons/cli/OptionBuilder.
I am having to do this because the instruction is to run the program using
java cs123.Learn -mode train -algorithm even_odd -model_file speech.even_odd.model -data speech.train -task classification
I have made a test with commons-cli with the -mode in option. It compile and run as expected. So I can make sure with you that you can using that option.
I am standing in java folder to run the command, my folder structure:
java
|--upwork
| |--Main.java
|--commos-cli-1.2.jar
For your problem: I see that your command only point classpath to commons-cli lib and not point to the location of your package. Refer to this answer your command should start with: java -cp .;commons-cli-1.2.jar ...
If this does not help, please upload your code to get help or you can create a simple test like mine to check this out.
Can arguments for a class be passed the following way?
I don't think so for the good reason that what you're trying to pass with your "-naming" are program arguments. Program arguments are retrieved in your app with the String[] args of your main and in Java you don't have String index in arrays.
If you want to achieve what you want, you could still do it but you would have to implement the logic in your program. Firstly, you would need to get all the args in your program and then implement the logic by building a map for example and process this map.
As an example, you could say that if any argument (i.e args[0]) starts by "-" it means that it's a key for your map and that the following argument (i.e. args[1]) is the associated value.
Edit: I haven't used commons-cli and I may be completely wrong but from a quick research online, I think the library is offering you the logic to build commands to execute in command line once your application is running.

customize the color of AnsiColorLogger in ant?

Currently my ant output is colorized by AnsiColorLogger. It works as expected, and now I want to customize the colors (default ones are too dim). I created a color file as specified, but have no idea how to pass the file name through. The documentation says
This file must be specified as the value of a system variable named ant.logger.defaults and passed as an argument using the -D option to the java command that invokes the Ant application.
How to pass an argument to the java command if I just run on terminal with ant? I tried to pass
-Dant.logger.defaults=<my file path>
to ant but no luck. I also tried setting environment variable
ANT_OPTS='-Dant.logger.defaults=<my file path>'
but it didn't work either. In case it matters, I am with
OS X 10.10.5
Apache Ant(TM) version 1.9.6
Java 1.8.0_65
I found my bug: my path to the file was ~/my-file but ~ in single quotes is not expanded. That simple.
(I forgot the fact that when I use ~ in terminal, it is expanded by the shell before passed to the program.)
Typical setup for ant:
export ANT_HOME="${HOME}/opt/apache-ant"
export ANT_ARGS="-logger org.apache.tools.ant.listener.AnsiColorLogger"
export ANT_OPTS="-Dant.logger.defaults=${HOME}/etc/ant-colors.properties"
export PATH="${ANT_HOME}/bin:${PATH}"
In this case I have ant installed in my home directory under opt/, while it's color configuration is similarly in the home directory under etc/. This can be customized to whatever it needs to be. Use of ${HOME} avoids issues with ~, as long as I also use double quotes as in the example instead of single quotes.
My initial error was that I thought the -D could be added with ANT_ARGS, but we need both ANT_ARGS and ANT_OPTS as above.
This is the ant-colors.properties I am using on macOs:
AnsiColorLogger.ERROR_COLOR=31
AnsiColorLogger.WARNING_COLOR=35
AnsiColorLogger.INFO_COLOR=36
AnsiColorLogger.VERBOSE_COLOR=32
AnsiColorLogger.DEBUG_COLOR=34
Note that I leave out the attribute prefix "2;", as that would but the output in Bold. I also do not use "1;", as then the output is way to light. Instead I leave it at the default which has ideal visibility to me.
Note the syntax is as follows:
AnsiColorLogger.*=Attribute;Foreground;Background

How to pass parameters from command line to a java program through makefile

My first question in stack overflow... Kind of excited but still struggling in the problem.
Alright, My question is how to pass parameters from command line to a java program through makefile.
Honestly I don't really know wether my description is correct....... Cause I don't really know much about makefile... In my assignment, the description is that we must develop a Makefile for GNU make to build our program. For example, the command lines
make
mipsim -v < test1.cmd > test1.log
will build the ISS (a simulator we made) and then run it with debugging output, taking input commands from the file test1.cmd and writing result to test1.log.
I have finished the program but I don't know how to make the things above happen.
What I know so far is just to use makefile to make the .class file from .java file....
I have no idea about how to get test1.cmd as my input file's name and test1.log as my output
file's name from command lines.... I guess these two names probably will get into my program through String[] args in the main function...
Could anybody give me some help please?
Thanks
There is some confusion as to the issues.
First, compile Java using make is a little... iffy. (Most people use ant or maven.) However, if you don't mind a little overhead, you can do it using make. You probably should run make from a directory at the root of the Java package hierarchy. You can determine all Java files below using make macros. Hint: shell:
JAVA_FILES = $(shell find -name \*.java)
Then you run javac. (Make sure to define all path names to compilers etc. using make macros.) With Java, it's not easy to derive a make target, because .class files are not 1:1 w.r.t. java files. I just use a target "compile", depending on all the java files, and touch a file acting as a dummy target.
Second, the execution. To invoke a Java program that is not in an executable jar, you set the classpath (option -cp), specify the main class name and add command line parameters. I'd have to know what "mipsim" is - probably a shell script for doing just that. Anyway, a make target could be the log file:
%.log : %.cmd
${JAVA_HOME}/bin/java -cp ${ROOT} <$< >$#
Now, make test1.cmd should run your program.
Note: Redirection is not specified by program arguments; this is handled by the shell.
Quick comment on your question.
your makefile needs 2 targets. one for build and the other for the run.
all: build run
build:
(this is to build class file from your java source)
run:
put your java command line here like "java ..."
When you run "make", it will call "all" target. And all target will call "build" and "run" target, so just put one thing in one target and use the combinations.
Your java code.
Is your java takes input filename as argument or from stdin?
If you want to take input filename, then you can take it from args argument passed to your main(String[] args).
If you want to read from stdin then you can create a bufferedreader as below.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Hope this help.
(+1 please, if you like this answer)
There are a bunch of unrelated questions..
The syntax you are showing:
mipsim -v < test1.cmd > test1.log
would call an executable mipsim. Pass "-v" to the args[1]. Redirect test1.cmd to be the standrad input and test1.log be the standard output.
The output input redirection happens by the operating system so in c++ reading from std::cin will read from the file and writing to std::cout will write to test1.log
In java these will be redirected to System.in and System.out
About makefiles
Basically a make file rule looks like this:
<target>: <dependency1> .. < dependencyn>
~tab~ command
So just like it is possible to build a target that calls Javac. It is possible to build a target that calls Java.. and so you can build a test target and use it to execute any command you need
If you built a c++ executable then you can execute it from the makefile in the same way.
test: mipsim
mipsim -v < test1.cmd > test1.log
Your final question about pass parameter values to command line from make file do you mean something like this?
make PARA1=1 PARA2=ABC.c
You can use the parameters in your makefile..
test: mipsim
mipsim -v < $(INPUT_FILE) > $(OUTPUT_FILE)

What does -cp mean in the terminal when running a .jar file?

I have to get some kinks out of a shell script for work, and one of the line looks like this:
-cp: this is the classpath
This is the set of classes that are used when running a specific class.
In your example; OrganT.Tune.Mix OrganT must be a class in the classpath (in this case, inside the OrganT.jar
Read the documentation, can be found here
Just a hint - under linux and mac you can use the
man <command goes here>
comman in the terminal/shell to display all parameters and usage information available for the specific command.
-cp stands for classpath. The CLASSPATH variable is one way to tell applications, including the JDK tools, where to look for user classes.
java -classpath .;YourJarFile.jar
I think you want to run a script for including the class path and execute the jar.
To do this in any text editor type java -jar YourJarFile.jar and save it, with extention (anyName.sh) assuming you have got linux flavour. Make it executable using the command chmod 775 anyName.sh
For windows type java -jar YourJarFile.jar, and save it with extention (anyName.bat)

Java path problems on Cygwin

I'm trying to compile a Java project under Cygwin using a native Win32 Java.
The Java binaries are correctly found under /cygdrive/c/jdk/bin on my machine.
The following command works fine:
javac -d . ./gnu/kawa/util/PreProcess.java
The PreProcess.class file is generated in ./gnu/kawa/util/. Trying to invoke Java on this fails however:
CLASSPATH=.:$CLASSPATH java gnu.kawa.util.PreProcess \
%java6 +use:com.sun.net.httpserver +enable:XML \
`sed -e 's|\([^ ]*\)|./\1|' < ./patch-source-list`
Error: Could not find or load main class gnu.kawa.util.PreProcess
...
This command was invoked by make, that's where the $CLASSPATH variable is set dynamically. patch-source-list is just a list of class names. The : in the classpath looks suspicious, but I'm not sure how to test ; while not annoying sh.
My only other suspicion is that the native Java is trying gnu\kawa\util\PreProcess, but I think cygwin can transparently handle that.
Any ideas? Thanks for your time.
Another option would be to build your path using the ':' and then fix the results using cygpath. This is probably overkill in your specific situation, but in a general case where you may have references to multiple directories, some of which may be referenced as absolute rather than relative paths, or if you are working with cygwin symlinks, it is much more useful.
$ ln -s /cygdrive/c/development/libraries/ ../libs
$ cygpath -pw /cygdrive/c/development/:.:../libs
C:\development\;.;C:\development\libraries\
so then you'd build your CLASSPATH variable as before, and in the final stage run
CLASSPATH="`cygpath -pw "$CLASSPATH"`" java (whatever)
Remember, the JVM has no idea that you are using the cygwin bash shell.
Two things:
for the classpath locations, use the windows path names. Thus, no "/cygdrive/c/somepath", but "c:\somepath\" ("/" and "\" can be used interchangeably however)
use ';' instead of ':' in the classpath list
This should work:
export CLASSPATH="./gnu/kawa/util/PreProcess.class"
CLASSPATH=".;$CLASSPATH" java gnu.kawa.util.PreProcess
The : in the classpath looks suspicious, but I'm not sure how to test ; while not annoying sh.
You're exactly right: you need to use ; instead of :. As for how to use it — as Mat alludes to above, you need to "quote" the semicolon. Any of these will work:
CLASSPATH=.\;$CLASSPATH java Foo
CLASSPATH=.';'$CLASSPATH java Foo
CLASSPATH='.;'$CLASSPATH java Foo
CLASSPATH=".;$CLASSPATH" java Foo
You can use whichever one you like best. (The first uses a backslash, which quotes a single following character. The second and third use single-quotes, which quote a sequence of zero or more characters. The fourth uses double-quotes, which are like single-quotes except that they still allow the variable $CLASSPATH to be expanded. For that matter, you could also write something like
CLASSPATH=".;"$CLASSPATH java Foo
if you want. See the above link for lots more information about quoting in Bash.)

Categories