I need to call Closure Compiler from a .bat file passing a flag language_in=ECMASCRIPT5 I am using the following script but I receive an error
java.lang.classnotfoundexception: com.google,javascript.jscomp.SourceFile
I would like to know:
When I omit the flag code compile fine, so am I passing correctly the flag?
Could you provide me more information about this error?
java -Xms256m -Xmx256m -cp "%~dp0../shrinksafe/js.jar";"%~dp0../closureCompiler/compiler.jar --language_in=ECMASCRIPT5";"%~dp0../shrinksafe/shrinksafe.jar" org.mozilla.javascript.tools.shell.Main "%~dp0../../dojo/dojo.js" baseUrl="%~dp0../../dojo" load=build %*
As stated on the documentation:
(ClassNotFoundException) Thrown when an application tries to load in a class through its string name using:
The forName method in class Class.
The findSystemClass method in class ClassLoader .
The loadClass method in class ClassLoader.
What I think it's happening, due to the fact the code works when you omit the flag, is that the variable ECMASCRIPT5 is defined inside the compiler.jar, which you might not be including in the classpath.
You could try placing compiler.jar to your WEB-INF/lib in order for it to be deployed with your application and so on accessible when executed.
Related
I'm experimenting with -Xbootclasspath in Java just for fun, and have added a test method int java.lang.Object#id(), just an instance-like identityHashCode method shortcut:
package java.lang;
public class Object {
public final int id() {
return System.identityHashCode(this);
}
// the original code goes here
}
The code above is compiled into a single-class JAR file, and the code below is compiled and dependent on the patch JAR file, thus the following code is legal:
public static void main(final String... args) {
System.out.println(new Object().id());
}
Running the sample application is quite easy prepending the bootstrap classes:
$ java -Xbootclasspath/p:patch.jar -cp app.jar test.Application
366712642
Works fine. Now, I wondering if it's possible to do the same trick on Android. So, the closest equivalent, I think, should be (from adb shell):
$ dalvikvm -Xbootclasspath:patch.jar -cp app.jar test.Application
java.lang.NoSuchMethodError: No virtual method id()I in class Ljava/lang/Object; or its super classes (declaration of 'java.lang.Object' appears in /syework/core-libart.jar)
at test.Application.main(Application.java:11)
Looks like prepending, but not working since it's saying that the java.lang.Object class is already defined in another location (probably the real path is /system/framework/core-libart.jar, at least it says similar, but that JAR is quite different -- then how after all?). I also saw a few examples with the $BOOTCLASSPATH variable, but none of them works for me for some reason.
Is it possible to run dalvikvm overriding the bootclass path somehow and where are the core classes are loaded from?
EDIT 1:
It probably would work, but Android Dalvik VM is really dependent on the zygote that all new Dalvik VM processes are forked from, thus the zygote does not run with an alternative boot classpath. At least, this is what I understood from this question: How to pass dalvik command line parameters through .apk?
I want to run a java project in terminal. When I compiled, no error occurred, but when I run the program I get the following error:
Could not find or load main class orException in thread "main"
java.lang.NoClassDefFoundError: Appium (wrong name:
com/appiumproj/test/Appium)
Please help me to solve this problem.
iMac:~ Samuel$ javac -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar: /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/Appium.java
iMac:~ Samuel$ java -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar: /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/Appium
Error: Could not find or load main class .Users.Samuel.Downloads.AppiumTest.src.com.appiumproj.test.Appium
iMac:~ Samuel$
You need to specify the name of the class - not a filename. It needs to be the fully-qualified class name, and it needs to be on the classpath. So after compiling, you'd want something like this (just spread out on multiple lines for readability; the backslashes are line continuations - you should be able to copy and paste this straight into your shell):
java -cp /Users/Samuel/Downloads/AppiumTest/lib/selenium-server-standalone-2.45.0.jar\
:/Users/Samuel/Downloads/AppiumTest/lib/gson-2.3.1.jar\
:/Users/Samuel/Downloads/AppiumTest/lib/java-client-2.2.0.jar\
:/Users/Samuel/Downloads/AppiumTest/src \
com.appiumproj.test.Appium
Are you sure your compiled version is in /Users/Samuel/Downloads/AppiumTest/src/com/appiumproj/test/ ? I would say that it is probably where the javac was run. Check and find it and specify the path to to compile version
I am trying to run a java program in linux server which includes an imported jar.
While compiling it is not giving any issues , but when I try to run, it is giving an error "Error: Could not find or load main class ". If I remove the import and its references , my code is working fine without any load issues.
Any inputs please
javac -cp "/opt/CARKaim/sdk/pwdsdk.jar" SamplePwd.java //No issues
java -cp "/opt/CARKaim/sdk/pwdsdk.jar" SamplePwd //Error: Could not find or load main class
Assuming SamplePwd has an entry-point (e.g. main(String[] args)) make sure the current folder is also in your class-path, like
java -cp "/opt/CARKaim/sdk/pwdsdk.jar:." SamplePwd
This question already has answers here:
Exception in thread "main" java.lang.NoClassDefFoundError: wrong name
(3 answers)
Closed 9 years ago.
I have been fighting with this program for a little while now and cannot figure out what is wrong. Any help would be greatly appreciated.
So here's the issue. I have three classes one is for logging onto a mysql database, the other is to output data from the database, and the last one holds method main. I was having a huge issue with getting them to compile getting errors about not finding a symbol for a method in a different class. I finally got them to all compile by using command "javac -d bin/cdtPack src/CDT.java src/login.java src/ClientBase.java"
But, now when I try to run the class with method main I get error:
Exception in thread "main" java.lang.noClassDefFoundError: CDT (wrong
name: cdtPack/CDT)
then a list of at java....
Anyone have an idea what could be going wrong?
As the linked Q&A explains this happens when you try to run a Java application using the wrong class name.
Your class looks something like this:
package cdtPack;
public class CDT {
....
}
That means that its class name is "cdtpack.CDT".
But you are running it like this:
$ java CDT
The JVM is telling you this:
"You told me to run CDT, but when I looked at it, the class said its name is "cdtpack.CDT"!!"
You have to get your head around the way that the Java classpath works, and the way that javac and java and all of the other Java tools find classes.
Your "CDT.class" file should be in a directory called "cdtpack", and then "cdtpack"'s parent directory should be on the classpath; i.e.
Compile like this:
$ javac -d bin -classpath bin src/cdtpack/CDT.java
which should create "bin/cdtpack/CDT.class". Then run like this:
$ java -classpath bin cdtpack.CDT
It looks like CDT should either belong in the package cdtPack or you are running it from the wrong directory...
Try changing into the bin directory and run the class file again. Don't forget to include the package name before the class name. For example:
...\bin> java cdtPack.CDT
try this
you goto src directory and if class file available there, then type
java CDT
if the class is present in some other directory then type
java a/b/c/JavaClassName
if you want to add some runtime jar while running then
java -cp classpath=%classpath%;jarfilename.jar; a/b/c/JavaClassName
I am trying to use randoop(automatic test generator for Java) and randoop cannot find my class:
eliezer#ubuntu:~/Desktop$ java -ea -classpath \
randoop.1.3.2.jar:home/eliezer/myclasses \
randoop.main.Main gentests \
--testclass=/home/eliezer/Desktop/myclasses/ArrayListError
policy = sun.security.provider.PolicyFile#85af80
Throwable thrown while handling command:java.lang.Error:\
classForName(/home/eliezer/Desktop/myclasses/ArrayListError)
java.lang.Error: classForName(/home/eliezer/Desktop/myclasses/ArrayListError)
at randoop.util.Reflection.classForName(Reflection.java:206)
at randoop.util.Reflection.loadClassesFromList(Reflection.java:386)
at randoop.main.GenInputsAbstract.findClassesFromArgs(GenInputsAbstract.java:507)
at randoop.main.GenTests.handle(GenTests.java:184)
at randoop.main.Main.nonStaticMain(Main.java:80)
at randoop.main.Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException: \
/home/eliezer/Desktop/myclasses/ArrayListError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at randoop.util.Reflection.classForName(Reflection.java:198)
... 5 more
Randoop failed.
Last sequence under execution:null
My class is called ArrayListError.java and is found in /home/eliezer/Desktop/myclasses.
The randoop docs are found at: https://randoop.github.io/randoop/manual/index.html.
I am sure it is something really trivial but I'm inexperienced with these things.
You need to set your classpath such that, jvm should be able to locate all your resources like classes, files, jars etc.
In your case, ArrayListError is placed under directory /home/eliezer/Desktop/myclasses. You need to place this in your classpath.
Once you point your classpath to mentioned directory, You need to pass the class name to --testclass=ArrayListError.
java -ea -classpath randoop.1.3.2.jar:/home/eliezer/Desktop/myclasses randoop.main.Main gentests --testclass=ArrayListError
should fix your problem. I suggest you to search on setting classpath and read on.
This is wrong
my class is called ArrayListError.java and is found in
/home/eliezer/Desktop/myclasses.
Your ArrayListError.java is the source code, but java virtual machine needs a compiled class in its classpath.
EDIT:
Since you said that you have the .class file also, then your problem can be solved in two ways
a. No package
Run the command (take care of the --testclas, it is not directory, it should be the class)
java -ea -classpath randoop.1.3.2.jar:/home/eliezer/myclasses
randoop.main.Main gentests --testclass=ArrayListError
b. Class in a package
If your ArrayListError does have package com.test; make a directory /com/test in your myclasses directory and run the command below
java -ea -classpath
randoop.1.3.2.jar:/home/eliezer/myclasses/com/test/ randoop.main.Main
gentests --testclass=com.test.ArrayListError
Check your classpath on the command line;
I see home/eliezer/myclasses, without the leading /.