I have 3 jar files and a .java file that depends on these jar files. How do I compile the .java file with these jar files using a command prompt?
Java – How to include jar files with java file and compile in command prompt
command-promptjarjava
Related Topic
- Java – How to read / convert an InputStream into a String in Java
- Java – How to create a Java string from the contents of a file
- Java – How to create an executable JAR with dependencies using Maven
- Java – How to avoid Java code in JSP files, using JSP 2
- Java – How to add local jar files to a Maven project
- Java – How to convert a String to an int in Java
- Java – How to create a memory leak in Java
- Java – Why is processing a sorted array faster than processing an unsorted array
Best Answer
You can include your jar files in the "javac" command using the "-cp" option.
Instead of "-cp" you could also use "-classpath"
You could including the jars every time you compile by setting the environment variable "CLASSPATH" correctly. The environment variable will store the path where the jars and classes that needs to be used for compiling/executing any java file. You will not have to include the jars individually every time you compile you file.
Different machines have different methods to set the classpath as an environment variable. The commands for Windows, Linux, etc are different.
You can find more details in this blog.