This question already has answers here:
Package not found; javac
(2 answers)
Including jars in classpath on commandline (javac or apt)
(5 answers)
Closed 8 years ago.
I am compiling java files from terminal. But It gives error for external jar files. where can I put external jars. so, it can be used at compile time from terminal?
You can pput it in every directiory and then add it to the classpath:
javac -cp <path_to_jar_including_filename> <class_to_compile>
Related
This question already has answers here:
Why am I getting a NoClassDefFoundError in Java?
(31 answers)
Closed 1 year ago.
I'm trying to compile a java file that uses multiple jar files as imports.
the command that I have used to compile my code :
javac -cp jackson-databind-2.12.1.jar:jackson-core-2.12.1.jar:jackson-annotations-2.12.1.jar TestRunner.java
as a result two .class files are created : TestRunner.class and TestRunner$1.class
then I run the command :
java TestRunner
but it throws an error that says:
Error: Unable to initialize main class TestRunner Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/type/TypeReference
I have included all the required libraries in the javac command, tested it with the IDE and it works fine.
I have tried other versions of the jackson library but I'm stuck with the same error.
You need to specify the classpath when running your code, by using the same -cp args that you used when compiling, plus the folder where your compiled class is in.
In your cas that would mean something like java -cp .:jackson-databind-2.12.1.jar:jackson-core-2.12.1.jar:jackson-annotations-2.12.1.jar TestRunner
The libs you specified are not included in the .class files generated, so Java still needs them to understand how to call the code that's not coming from your class file.
This question already has answers here:
How to make an executable JAR file?
(5 answers)
Closed 2 years ago.
hello someone could suggest me how to compile the java project that I attach to generate the sri.jar file that appears in the Readme file
//Project java to compile
https://github.com/joselo/sri
//command line where the sri.jar that I want to generate appears
java -jar sri.jar /path/sample/certificate.p12 cErTiFicAtEPaSsWoRd /path/sample/unsignedFile.xml /path/sample outputFile.xml
To create a jar file first thing that needs to be done is to compile the project using javac
javac -cp ./sri-master/lib/*: ./sri-master/src/sri/*.java -d ./out/
and then run the below to create the jar
jar cvfm xyz.jar ./sri-master/manifest.mf -C ./out/ .
This question already has answers here:
How do I run a class in a WAR from the command line?
(11 answers)
Closed 5 years ago.
I am web-development noob and use vaadin 8 for an application and gradle to build the war-file. How can I run the apllication file from command line?
I tried this without success:
java -cp root.war my.namespace.RootServlet
The class is not found.
That will only work if you have an embedded servlet container inside the WAR, that is defined as main class in your manifest file. See the following answer to a similar question:
https://stackoverflow.com/a/3804844/8819761
This question already has answers here:
How do I load optional task sshexec into Ant in a no-configuration manner?
(2 answers)
Closed 6 years ago.
How to include jsch-0.1.53.jar file in build.xml (to execute ant sshexec and scp) other than passing as command line argument - lib jsch-0.1.53.jar?
The easiest way, if you have the possibility, is copy it into your ant lib installation
This question already has answers here:
Compiling a java program into an executable [duplicate]
(7 answers)
Closed 7 years ago.
In C/C++, the .exe file is automatically generated by the compiler when we run the code.
My question is how do you generate the .exe file in Java instead of just hitting run every time when we open up the .java file.
To do that, you'd need to create an Executable .jar file. Here's the instructions on how to do it.