I'm trying to compile a Java 1.6 program. The following compiles without error:
# javac -cp /path/to/ojdbc6.jar:. MyJavaProgram.java
But adding a flag causes this error:
# javac -cp /path/to/ojdbc6.jar:. -Doracle.jdbc.SetFloatAndDoubleUseBinary=true MyJavaProgram.java -help
javac: invalid flag: -Doracle.jdbc.SetFloatAndDoubleUseBinary=true
Usage: javac <options> <source files>
use -help for a list of possible options
Is the flag not supported? I added the -help but it didn't give any more info (did I add it in the right place above?).
The options must come before the source files (as indicated in your question): remove the -help.
-D option specify properties and are passed to the JVM (java) and are not compile time flags. From java -help:
-D<name>=<value>
set a system property
To view the list of available compiler options execute:
javac -help
Related
Getting Error while executing the below command
dz> run app.package.manifest jakhar.aseem.diva
C:\Program Files\Java\jdk1.8.0_65\bin\javac.exe -cp C:\Program Files\drozer\lib\drozer\lib\android.jar XmlAssetReader.java
javac: invalid flag: Files\Java\jdk1.8.0_65\bin\javac.exe
Usage: javac <options> <source files>
use -help for a list of possible options
Error whilst compiling the Java sources.
The problem is that the program run doesn't understand the space in Program Files:
C:\Program Files\Java\jdk1.8.0_65\bin\javac.exe -cp C:\Program Files\drozer\lib\drozer\lib\android.jar XmlAssetReader.java
javac: invalid flag: Files\Java\jdk1.8.0_65\bin\javac.exe
It calls javac, which sees the -cp flag (for classpath). But javac doesn't realize that what follows is a single directory. It thinks the part from Files\ onward is a new flag... that it doesn't know.
If you created this program run yourself, then the easiest solution is adapt that source - put double-quotes around the argument. So you'd get:
-cp "C:\Program Files\drozer\lib\drozer\lib\android.jar"
Alternatively, on a Windows machine, you may be able to use Progra~1 as a shorthand for this directory. But off the top of my head that won't work on every Windows machine anymore.
I downloaded a sample code written in java that has multiple jar files and java files. I am not a Java programmer so I am having a hard time compiling the code. Here's my attempt:
javac -classpath lib/*.jar src/*.java
However this is what I get:
javac: invalid flag: lib/dom4j-1.6.1.jar
Usage: javac <options> <source files>
use -help for a list of possible options
What's wrong with my approach and how can I compile the code? ALl the jar files are located in the lib folder, and the java files in the src folder.
You need to stop the shell from globbing the wild-card in lib/*.jar by escaping it.
Also, you need to remove the .jar suffix ... because that's how classpath wildcards work; see Oracle's "Setting the classpath" document.
So ...
javac -classpath lib/\* src/*.java
Using an IDE is another option. However, if all you want to do is compile and run, then downloading and installing and learning to use an IDE is overkill (IMO). And the flipside is that it is good for an IDE-using Java programmer to also understand how to compile and run from the shell prompt ...
old post, but thought below details help,
you can specify jar files by separating by ; in windows and : in unix
Eg: (windows)
javac -cp first.jar;second.jar;third.jar YourClass.java
(unix)
javac -cp first.jar:second.jar:third.jar YourClass.java
Source: https://gullele.com/pass-all-the-jars-in-classpath-when-compiling-java/
I am trying to compile a Java servlet which uses multiple external jars. Javac recognises the first jar, but then spits out errors that it can't find the following jars. When I swap the order, it still recognises the first, but none after. The command line I am using;
javac -classpath ~/servlet/servlet-api-2.3.jar:~/servlet/gson-2.2.2.jar:~/servlet/mysql-connector-java-5.1.22-bin.jar ~/servlet/dataExchange.java ~/servlet/dbUserConnect.java ~/servlet/dbTTConnect.java -d $TOMCAT_HOME
As you can see I am trying to use the servlet jar, Googles GSON (JSON), MySQL & Oracle Jars.
If you need any other information just ask.
Thanks in advance!
At least one mistake:
Usage: javac <options> <source files>
Your command line is:
Usage: javac <options> <source files> <options>
Try this:
javac -classpath ~/servlet/servlet-api-2.3.jar:~/servlet/gson-2.2.2.jar:~/servlet/mysql-connector-java-5.1.22-bin.jar -d $TOMCAT_HOME ~/servlet/dataExchange.java ~/servlet/dbUserConnect.java ~/servlet/dbTTConnect.java
The problem is the use of the ~ character throughout the path. Only the instance at the beginning of the option will be expanded.
I was trying to execute this command in command prompt to find my build error. What I have broken down upto is that javac is treating one of the file name as a flag (option) and thats why its not able to execute. HOw do i fix this?
C:\Users\AUG>javac -verbose -classpath "C:\Program Files\MATLAB\R2010b\toolbox\j
avabuilder\jar\javabuilder.jar" -d "C:\Users\AUG\Documents\SourceTraceJAVA\Sourc
eTrace\src\classes" "C:\Users\AUG\Documents\SourceTraceJAVA\epanet2.h" "C:\Users
\AUG\Documents\SourceTrace\src\SourceTrace\SourceTrace.java" "C:\Users\AUG\Docum
ents\SourceTraceJAVA\SourceTrace\src\SourceTrace\SourceTraceMCRFactory.java" "C:
\Users\AUG\Documents\SourceTraceJAVA\SourceTrace\src\SourceTrace\SourceTraceRemo
te.java" "C:\Users\AUG\Documents\SourceTraceJAVA\SourceTrace\src\SourceTrace\pac
kage-info.java"
javac: invalid flag: C:\Users\AUG\Documents\SourceTraceJAVA\epanet2.h
Usage: javac <options> <source files>
use -help for a list of possible options
It is considering epanet2.h file as a flag instead of a file. Is there somethng wrong with the syntax ?
How do I resolve this?
Java doesn't know what to do with .h files -- that looks (based on extension) like a C header file so it shouldn't be included in the list of files passed to javac or if it is a valid java source file then change its extension to .java.
*.h is not a valid java source file extension.
I am trying to compile my source code from the Windows 7 command prompt. I have added the directory in which my *.java file is located to the classpath. Yet, I still get this error:
C:\Users\Alex>javac HelloThere.java
javac: file not found: HelloThere.java
Usage: javac <options> <source files>
use -help for a list of possible options
I'm very confused as to why this happens because if I navigate to the folder where this file is located, it will compile. However, this is not a satisfactory solution since I intend on compiling JUnit tests directly from the command line as well.
Other solutions I have attempted:
C:\Users\Alex>javac -classpath "C:\Users\Alex\AndroidProject\UnitTest\src" HelloThere.java
javac: file not found: HelloThere.java
Usage: javac <options> <source files>
use -help for a list of possible options
I do not think this has ANYTHING to do with typos.
Why can't I compile my project like this?
The CLASSPATH variable is not used by javac to find where your source code lives. Use the -sourcepath arg to javac instead.
Save yourself a lot of time and manual typing and use a build tool like Apache Ant or Maven.
You don't want to use classpath, that tells the compiler where to find externally referenced .class files used by your file. You want to use -sourcepath which tells javac where your .java files may be hiding.