I used to launch a java tool with a batch like this :
java -classpath "./lib/JSanExport.jar;./lib/JSanRmiApiEx.jar;./lib/JSanRmiServerUx.jar" -Xms128M -Xmx768M -Dmd.command=command_VSPLA.txt -Dmd.logpath=log sanproject.getmondat.RJMdMain
For some reasons i need to convert that batch into a Powershell script. But when I copy the same line on my powershell script I got an error, whereas I launch it in the same workingdir.
c:\Program Files\ExportTool\export>powershell .\Run_VSPLA.ps1
Exception in thread "main" java.lang.NoClassDefFoundError: /command=command_VSPLA/txt
Caused by: java.lang.ClassNotFoundException: .command=command_VSPLA.txt
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: .command=command_VSPLA.txt. Program will exit.
Do you know what happens?
try to set jvm options before classpath :
java -Xms128M -Xmx768M -Dmd.command=command_VSPLA.txt -Dmd.logpath=log -classpath "./lib/JSanExport.jar;./lib/JSanRmiApiEx.jar;./lib/JSanRmiServerUx.jar" sanproject.getmondat.RJMdMain
It searches for class named /command=command_VSPLA/txt. For batch = is a delimiter and is parsed in a different way than powershell.
EDIT
The solution given by the OP:
java -Xms128M -Xmx768M "-Dmd.command=.\command_VSPLA.txt" "-Dmd.logpath=log" -classpath "./lib/JSanExport.jar;./lib/JSanRmiApiEx.jar;./lib/JSanRmiServerUx.jar" sanproject.getmondat.RJMdMain
Seem like it can't find command_VSPLA.txt, maybe try a full path.
Related
It is quite frustrating when you can't execute a .bat file in python while it is executing manually.
I am attaching my code here:
directory = 'E:/'
with open(os.path.join(directory, 'output_file.bat'), 'w') as OPATH:
OPATH.writelines(['"""',"\n"'E:',"\n",
'javacCreatingUser.java',"\n",'javaCreatingUser',"\n",'"""'])
os.system("E:/output_file.bat")
The above is my python code which is creating a bat file with 2 java command
javac CreatingUser.java
java CreatingUser
I can run the .bat file manually and it is working fine but my python script is giving me the following error:
java.lang.NoClassDefFoundError: oracle/iam/identity/exception/ValidationFailedException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: oracle.iam.identity.exception.ValidationFailedException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" '"""' is not recognized as an internal or external command,
operable program or batch file.
The question is that if some classes are missing in my file then it should not execute manually as well, but manual execution is fine.
javac CreatingUser.java
java CreatingUser
This is the source of your problem: You're only compiling one class file and then calling that class without a classpath.
Java has a search path for classes comparable to Pythons PYTHONPATH called classpath.
You can give this a try:
javac CreatingUser.java
java -classpath YOUR_CLASSPATH CreatingUser
YOUR_CLASSPATH can be a colon (Linux) or semicolon (Windows) separated list of JAR files and directories containing class files. Let your classpath point to the JARs you're needing and you're fine.
I am trying to execute the performance-meters.jar according to the tutorial at
http://marklogic.github.io/performance-meters/tutorial.html
using the command
java -cp performance-meters.jar:xcc.jar com.marklogic.performance.PerformanceMeters
I am getting the following error:
D:\MBS\performance-meters-master\performance-meters-master\classes>java -cp performance-meters.jar:xcc.jar com.marklogic.performance.PerformanceMeters
Exception in thread "main" java.lang.NoClassDefFoundError: com/marklogic/performance/PerformanceMeters
Caused by: java.lang.ClassNotFoundException: com.marklogic.performance.PerformanceMeters
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.marklogic.performance.PerformanceMeters. Program will exit.
I have kept both the jar files in the same folder.
Links to the jar files are:
http://developer.marklogic.com/code/performance-meters
[http://developer.marklogic.com/products/xcc][3]
Any help would be appreciated.
try to use semicolon instead colon in your cp declaration.
java -cp performance-meters.jar;xcc.jar com.marklogic.performance.PerformanceMeters
You are using windows system or Unix? If windows then I think you need to use ; and not : in separating jars as follows:
java -cp performance-meters.jar ; xcc.jar com.marklogic.performance.PerformanceMeters
i'm trying to run testng tests using command line like this :
C:\Documents and Settings\Administrateur\Bureau\automatic tests testNG>java -cp
C:\Documents and Settings\Administrateur\.m2\repository\org\testng\testng\6.3.1\
testng-6.3.1.jar org.testng.TestNG testng.xml
but i'm getting this error :
Exception in thread "main" java.lang.NoClassDefFoundError: and
Caused by: java.lang.ClassNotFoundException: and
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: and. Program will exit.
So How to add testNG to the classpath.
Thanks
The spaces in the filename are confusing things - Java thinks that only the c:\Documents part is in the classpath argument. Try this:
java -cp
"C:\Documents and Settings"\Administrateur\.m2\repository\org\
testng\testng\6.3.1\testng-6.3.1.jar org.testng.TestNG testng.xml
(where the whole thing is on one line and there's no break after "org" of course)
If you want to run via java on command line, you'll need to either enquote your path ("C:\Documents and Settings\Administrateur\.m2\repository\org\testng\testng\6.3.1\") or alter slightly as follows: C:\Documents%20and%20Settings\Administrateur\.m2\repository\org\testng\testng\6.3.1\. You may also want to run via maven to avoid having to specify this classpath info.
I installed the latest version of Weka on Windows
http://www.cs.waikato.ac.nz/ml/weka/
and I tried to run one of the weka features from the command line:
java weka.core.converters.TextDirectoryLoader -dir text_example > text_example.arff
which is a reference to this: http://weka.wikispaces.com/Text+categorization+with+WEKA
but then weka returns this error:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
Exception in thread "main" java.lang.NoClassDefFoundError: weka/core/converters/
TextDirectoryLoader
Caused by: java.lang.ClassNotFoundException: weka.core.converters.TextDirectoryL
oader
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: weka.core.converters.TextDirectoryLoader. Progra
m will exit.
I already set the CLASSPATH environment variable to point to the weka jar.
What did I do wrong?
The shell you run the command in apparently doesn't have the CLASSPATH environment variable set properly, otherwise the ClassNotFoundException wouldn't occur. As an alternative to the environment variable you can specify the classpath using the command line:
java -cp path/to/weka.jar weka.core.converters.TextDirectoryLoader -dir [...]
You can also check whether the environment variable is set correctly by executing echo %CLASSPATH% in the cmd shell.
class HelloWorld
{
public static void main(String[] args)
{
System.out.println("hey");
}
}
Command prompt session:
C:\Users\zobdos\Desktop>javac HelloWorld.java
C:\Users\zobdos\Desktop>dir *.class
Volume in drive C is OS
Volume Serial Number is A45E-7B01
Directory of C:\Users\zobdos\Desktop
11/20/2010 10:16 AM 417 HelloWorld.class
1 File(s) 417 bytes
0 Dir(s) 8,145,432,576 bytes free
C:\Users\zobdos\Desktop>java HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: HelloWorld. Program will exit.
C:\Users\btolbert\Desktop>
Nevermind, it works after using:
java -classpath . HelloWorld
You've a %CLASSPATH% environment variable in your environment. Get rid of it, it's disturbing your java commands, it's a poor practice tought by Sun Oracle anyway. Once you use -classpath argument or its -cp shorthand, then the %CLASSPATH% will be overridden. If the classpath is not specified by either the environment variable or the arguments, then the current path will be taken as default (as you initially expected).
run with classpath specified to the current directory:
java -cp . HelloWorld