I loaded a java jar file into http://www.sikuli.org/ and tried to run it like this but it is not working. Any hints?
load("C:\Users\...\TJF.jar")
import subprocess
subprocess.call(['java', '-jar', 'TJF.jar'])
Error message: Unable to access jarfile TJF.jar
The comment was correct. Full path necessary. No "load" line necessary.
Related
I think when I use os.system("cd java path") to change the path to java directory it's just don't change the path to that directory...
Here's the code I have written:
import os
import time
#import subprocess
os.system("cls")
os.system("cd C:\\Program Files\\Java\\jdk-13.0.1\\bin")
time.sleep(2)
os.system("javac add.java")
os.system("java add")
Error:
error: file not found: add.java
Usage: javac
use --help for a list of possible options
Error: Could not find or load main class add
Caused by: java.lang.ClassNotFoundException: add
I think the problem is that your current directory may not contains add.java after doing cd C:\\Program Files\\Java\\jdk-13.0.1\\bin:
You may try this "static solution" that works for one java instalation:
import os
import time
#import subprocess
os.system("cls")
time.sleep(2)
os.system("C:\\Program Files\\Java\\jdk-13.0.1\\bin\\javac add.java")
os.system("C:\\Program Files\\Java\\jdk-13.0.1\\bin\\java add")
You may also include your java installation path in the PATH of the operative system, and you may run javac and java without their absolute path. If you later change the java version, with only updating the java path the script will maintain operable. In this case the code will be like this:
import os
import time
#import subprocess
os.system("cls")
time.sleep(2)
os.system("javac add.java")
os.system("java add")
This code worked for me and I had to copy script into the bin folder to make it work..
import os
import time
aditya = True
while aditya:
os.system("cls")
print("Enter a program name to execute:")
name = input()
os.system(f"javac {name}.java")
os.system(f"java {name}")
key = input()
I am running java 1.8.0_65 on Windows 7.
I create a JAR and run it with the following command:
java -jar printxml.jar
And get this error:
Error: Could not find or load main class printxml.PrintXml
Here is my command to create the JAR:
jar cmfev manifest.txt printxml.jar printxml.PrintXml #filelist.txt
Contents of file "manifest.txt":
Class-Path: C:\Users\Me\SQLSER~1\JDBC\jtds-1.3.1.jar
I checked whether printxml.PrintXml class is in the JAR via this command:
jar tvf printxml.jar printxml/PrintXml.class
The command succeeded, i.e. PrintXml class is in the JAR.
I then checked if the PrintXml class in the JAR has a "main" method via this command:
javap -classpath printxml.jar -public printxml.PrintXml
The command succeeded and its output included...
public static void main(java.lang.String[]);
Searching the Internet, I found only the obvious answers, like:
Your classpath is wrong.
Your class doesn't have a "main" method.
Can someone please tell me how to resolve this problem?
Thanks,
Avi.
As Homer Simpson would say: D'OH
The value of the Class-Path entry in file "manifest.txt" is wrong!
It needs to be a URL!
So I changed it to:
file:/C:/Users/Me/SQLSER~1/JDBC/jtds-1.3.1.jar
Hey presto! No more error message. Now it runs!
Thanks to all who helped. ;-)
I have a jar file named- ParseCSV-0.0.1-SNAPSHOT.jar and the contents of it are -
META-INF/
META-INF/MANIFEST.MF
foo/
foo/ReadCSV.class
META-INF/maven/
META-INF/maven/Test/
META-INF/maven/Test/ParseCSV/
META-INF/maven/Test/ParseCSV/pom.xml
META-INF/maven/Test/ParseCSV/pom.properties
The main class is ReadCSV.class and it takes a CSV file (C:\Testting\ValidaResults.csv) as an input parameter. I am trying to execute the jar file from the command promt by running the following command-
java -jar . ParseCSV-0.0.1-SNAPSHOT.jar "C:\Testting\ValidationResult.csv"
But I am getting an error saying-
Error: Could not find or load main class foo.ReadCSVTest
What is going wrong here.
Why do you have a . between jar and ParseCSV..?
Try this first:
java -jar ParseCSV-0.0.1-SNAPSHOT.jar "C:\Testting\ValidationResult.csv"
If this does not work, then try:
java -cp ParseCSV-0.0.1-SNAPSHOT.jar;. foo.ReadCSV "c:\Testting\ValidationResult.csv"
If this works, then i would inspect the META-INF/MANIFEST.MF file to figure out what the classpath is like, and what the value of Main-Class is. It seems to be running ReadCSVTest instead of ReadCSV.
Your JAR file includes foo/ReadCSV.class, but your MainClass is set to foo.ReadCSVTest. You'll need to fix your Main-Class attribute in META-INF/MAINIFEST.MF
I'm trying to run a complied class with the command:java SocketTest in current directory.
But something wrong:
Exception in thread "main"
java.lang.NoClassDefFoundError:SocketTest(wrong
name:socket/SocketTest)...
here is my classpath AND path configration in windows XP:
JAVA_HOME:
C:\Program Files\Java\jdk1.7.0_25\
classpath:
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
path:
%JAVA_HOME%\jre\bin;C:\Program Files\Java\jdk1.7.0_25\bin;C:\Ruby187\bin;H:\Program Files\ARM\ADSv1_2\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%JAVA_HOME%\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
I think the .; has been carefully written,so I'm not sure what's wrong with the java command. Someone help,please!
The error message has pointed out you need to put the your class to the corrected package socket. So you need to create folder with name socket and then put your SocketTest.class to this folder and run the following command (under the parent folder of socket):
java socket.SocketTest
I used the following guide to get started, http://cnd.netbeans.org/docs/jni/beginning-jni-win.html.
But when I try to generate the header file using the command below
JAVA_HOME\bin\javah.exe -o
HelloWorldNative.h -jni
-classpath PROJECTS_ROOT\HelloWorld\build\classes
helloworld.Main
I get the following error.
Error: Can't recover from an I/O
error with the following message:
HelloWorldNative.h (access denied)
Thanks in advance :)
Looks to me like you are standing in a directory where you are not granted write access when you run javah.
Edit: What if you specify a full path to somewhere you know you have write access?
I also got that problem and this is how I solved it:
After building your project,go to the directory where your .class files are.
e.g C:\Users\Development\Documents\NetBeansProjects\DLLDevelopment\build\classes
and run your command again.