When I try to run the command
jar uvf Century.jar Century$1.class
from the command line, I get the following response:
adding: Century.class(in = 6441) (out= 3544)(deflated 44%)
Notice that instead of adding Century$1.class, is adds Century.class. The issue here is that Century$1.class is the class file for a new runnable thread that gets created in Century.class, which is the main class. Is there some way I can add the Century$1.class file to the jar?
try any of
jar uvf Century.jar Century\$1.class
jar uvf Century.jar 'Century$1.class'
A unix shell will interpret $1 as the value of the first command line parameter which is not what you want, you want the $ verbatim.
And please remember to comment or accept an answer given to your last question Datepicker Multiple Dates not working in Google Apps Script
Related
I'm trying to understand the inclusion of third party jar files in a java project using only the command line in Windows 10.
Specifically, I try to include the file json-20200518.jar in my "project" so that I can use the java object JSONObject in the project.
My java file:
package com.mypackage.example;
import org.json.JSONObject;
class Example {
public static void main(String[] args) {
// ... program logic
}
}
location of my java file (Examp.java):
./com/mypackage/example
location of jar file:
./jars
using cmd win10 I compile:
javac -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" "C:\Users\pfort\Desktop\java\com\mypackage\example\Examp.java"
compilation is successful.
Run:
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" com.mypackage.example.Examp
I get a report:
Error: Could not find or load main class com.mypackage.example.Pokus
Caused by: java.lang.ClassNotFoundException: com.mypackage.example.Pokus
Second attempt:
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar" "C:\Users\pfort\Desktop\java\com\mypackage\example\Pokus"
But the same error message comes back to me.
Where am I going wrong? Is it the wrong structure? I don't get it, the compilation is successful but the run does not work.
The compiled Examp.class file isn't part of json-20200518.jar, so you'll need to add the directory containing it to the command line. Assuming it's the current directory (.):
java -cp "C:\Users\pfort\Desktop\java\jars\json-20200518.jar;." com.mypackage.example.Examp
Editing the original question.
I am trying to execute a groovy script which uses classes from an external jar. How can I execute the groovy file from command line?
This is the command I tried
groovy -cp .:cicdutilities-1.0-SNAPSHOT.jar:http-builder-0.4.0.jar Test_Execution.groovy
and getting the error :
`org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /Users/sroy107/git/CICD-2020/src/main/java/com/groovy/Test_Execution.groovy: 188: unable to resolve class HTTPBuilder # line 188, column 24. def http = new HTTPBuilder(baseUrl) ^ 1 error`
I was not aware earlier that we need two jars.
This command is not working. Could somme one please help me on this.
This question already has an answer here:
Java error in making file through console
(1 answer)
Closed 4 years ago.
I have an executable that generates some file, and I need to call this executable from a Java application. The command goes like this
Generator.exe -outputfile="path/to/file" [some other params]
It works fine on the command prompt, but running it from Java,all steps are executed but the file is not created.
I doubt the problem was that my java application is not able to crate files / directories, so I tried to create a directory as below
try {
String envp[] = new String[1];
envp[0] = "PATH=" + System.getProperty("java.library.path");
Runtime.getRuntime().exec("mkdir path/to/folder", envp);
}
catch (Exception e) {
e.printStackTrace();
}
I get the following exception, even If the directory exist
java.io.IOException: Cannot run program "mkdir":
CreateProcess error=2, The system cannot find the file specified
I also tried using java.lang.Process and java.lang.Process and I got the same exception, although the command mkdir path/to/folder works fine on the command prompt
Two points:
1) You don't need to pass in the java.library.path to the mkdir command. Mkdir expects one parameter - the directory/ies you want to created.
2) Why not use the Java File class to create the directory instead? Create a File object of the path, then call the mkdirs() function on it.
I am executing a batch file (placed in the User's folder) using below code :
Process p = Runtime.getRuntime().exec(System.getProperty("user.home") + "/myapp/bin/dashboard.bat");
OR
Process process = new ProcessBuilder(System.getProperty("user.home") +"/myapp/bin/dashboard.bat").start();
dashboard.bat run some jars which has UI interface contains :
#echo off
TITLE MyApp Console
if exist %APP_HOME% goto checkuserdata
set APP_HOME=C:\Users\<UserName>\myApp
:checkuserdata
if exist %APP_USERDATA_DIR% goto setuserdatadir
set APP_USERDATA_DIR_TMP=%APP_HOME%\userdata
goto startapp
:setuserdatadir
set APP_USERDATA_DIR_TMP=%APP_USERDATA_DIR%
:startapp
set POI_JARS= .. // Path of some jar file inside the APP_HOME
set JAVAX_MAIL_JARS= .. // Path of some jar file inside the APP_HOME
set C3P0_JARS= .. // Path of some jar file inside the APP_HOME
set APPLET_JARS= .. // Path of some jar file inside the APP_HOME
set APP_CLASS_PATH= .. // Path of some jar file inside the APP_HOME
java -version
java -Djsse.enableSNIExtension=false -Djava.util.logging.config.file=%APP_USERDATA_DIR_TMP%\config\log.properties -classpath %APP_EXT_CLASS_PATH%;%APP_CLASS_PATH% net.ui.Dashboard "%APP_HOME%" "%APP_USERDATA_DIR_TMP%"
pause
after executing the dashboard.bat in TaskManager process get started but we are not able to get UI interface (i think it run as background process - not sure).
But if we move the dashboard.bat to some other location [other than C drive(OS drive)] and then if we run the batch file from java then it works fine.
please suggest any other way to achieve this or tell me where I am doing wrong ?
Thanks in advance.
I create an Applet and I generate the jar file with the following code
JAR FILE
"c:\arquivos de programas\java\jdk1.7.0_05\bin\jar" cvf C:\Users\lucas\Desktop\AbrirAplicativo3000.jar C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\WebcamApplet.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\QRCodeProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\QRCodeListener.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\OpenCVWebCam.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\CVImageProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\AbstractProcessor.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\ImagePanel.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\LabelPanel.class C:\Users\lucas\workspace\WebcamApplet\bin\com\colorfulwolf\webcamapplet\gui\LoadingScreen.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\StringsResourceTranslator.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\BufferedImageLuminanceSource.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\CommandLineRunner.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\GUIRunner.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\ImageConverter.class C:\Users\lucas\workspace\WebcamApplet\bin\com\google\zxing\client\j2se\MatrixToImageWriter.class
and I singed the JAR file normally.
I put the JAR file in a visible HTTP (http://www.netimoveis.com/AbrirAplicativo3000.jar)
In my ASPX page, I'm calling the APPLET following this code
<applet code="com.colorfulwolf.webcamapplet.WebcamApplet"
archive="http://www.netimoveis.com/AbrirAplicativo3000.jar, http://www.netimoveis.com/AbrirAplicativoAssinado3000.jar"
height="550" width="550">
</applet>
But when I try to run, I got the error
Incompatible magic value 218774561 error in applet
Someone can help me ?
Your AbrirAplicativo3000.jar is not correctly packaged. If you look inside, it has this structure:
META-INF/
C:/
Users/
lucas/
workspace/
WebcamApplet/
bin/
com/ --> this is where the jar should start from.
...
Try using the -C option on the jar command like this:
"c:\arquivos de programas\java\jdk1.7.0_05\bin\jar" cvf C:\Users\lucas\Desktop\AbrirAplicativo3000.jar -C C:\Users\lucas\workspace\WebcamApplet\bin\ .
Also it's not the first time that this magic number comes up on SO, although it seems more related with a bad URL. However I did download the jar with your supplied URL so just try re-packaging it.
The magic value error means that the class file doesn't start with the integer 0xCAFEBABE as it should. You probably had a transfer or compression problem.
If you can open the file in an hex editor, you may look for those bytes.