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 /.
Related
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.
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
Hi I have a batch file which basically updates some table in the database by running the job.
Here is a batch file code:
set CLASSPATH=C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\selenium-server-standalone-2.32.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jsoup-1.7.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xstream-1.1.3.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\XmlSchema-1.4.7.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-http-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\log4j-1.2.17.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\mysql-connector-java-5.1.13.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\httpclient-4.1.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\httpcore-4.1.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\commons-httpclient-3.0.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\gson-1.6.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\lucene-core-3.3.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-adb-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axiom-api-1.2.12.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-kernel-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\wsdl4j-1.6.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\XmlSchema-1.4.7.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axiom-impl-1.2.12.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\neethi-3.0.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\freemarker.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\smtp.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-local-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-http-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\mailapi.jar;
C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-context-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-core-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-beans-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-asm-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-aop-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-tx-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\aopalliance-1.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-expression-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-orm-3.1.1.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\transactions-jdbc-3.8.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\transactions-osgi-3.8.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\hibernate-3.2.1.ga.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\hibernate-annotations-3.2.0.ga.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jboss-transaction-api_1.1_spec-1.0.0.Final.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-jdbc-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\dom4j-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\transactions-hibernate3-3.8.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\gdata-core-1.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xstream-1.1.3.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\commons-lang-2.3.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xmlunit-1.5.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\log4j-1.2.17.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-http-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\mailapi.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\antlr-2.7.7.jar;
C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;
java -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m com.myProject.batch.PropertyRatesUpdaterBatchJob
I am trying to run the batch file from command prompt but I am getting error like
C:\ProjectWorkSpace\myProject\tools>C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;
'C:\ProjectWorkSpace\myProject\web\WEB-INF\classes' is not recognized as an internal or external command,
operable program or batch file.
and the second error at the end I am getting as
Exception in thread "main" java.lang.NoClassDefFoundError: com/myProject/batch /PropertyRatesUpdaterBatchJob
Caused by: java.lang.ClassNotFoundException: com.myProject.batch.PropertyRatesUpdaterBatchJob
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
and I am not able to run the batch file.
Anybody can help me to how to run the same and what this error mean.
Hi here is my new batch file:
set CLASSPATH=C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\selenium-server-standalone-2.32.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\jsoup-1.7.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\xstream-1.1.3.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\XmlSchema-1.4.7.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-http-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\log4j-1.2.17.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\mysql-connector-java-5.1.13.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\httpclient-4.1.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\httpcore-4.1.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\commons-httpclient-3.0.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\gson-1.6.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\lucene-core-3.3.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-adb-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axiom-api-1.2.12.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-kernel-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\wsdl4j-1.6.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\XmlSchema-1.4.7.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axiom-impl-1.2.12.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\neethi-3.0.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\freemarker.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\smtp.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-local-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-http-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\mailapi.jar;C:\ProjectWorkSpace\zaranga\WEB-INF\classes;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-context-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-core-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-beans-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-asm-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-aop-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-tx-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\aopalliance-1.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-expression-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-orm-3.1.1.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\transactions-jdbc-3.8.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\transactions-osgi-3.8.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\hibernate-3.2.1.ga.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\hibernate-annotations-3.2.0.ga.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\jboss-transaction-api_1.1_spec-1.0.0.Final.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-jdbc-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\dom4j-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\transactions-hibernate3-3.8.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\gdata-core-1.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\xstream-1.1.3.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\commons-lang-2.3.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\xmlunit-1.5.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\log4j-1.2.17.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-http-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\mailapi.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\antlr-2.7.7.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\classes
java -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m com.zaranga.batch.PropertyRatesUpdaterBatchJob
Now I am getting a new error log4j as
Error is :
No org.slf4j.impl.StaticLoggerBinder found in ClassPath, trying with log4j...
Any help will be greatly appriciated.
I assume with
set CLASSPATH=C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\selenium-server-standalone-2.32.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jsoup-1.7.2.jar;
You wanted to also add jsoup-1.7.2.jar; to the CLASSPATH variable, but you can't just extend a command over multiple lines like that.
If you want to write this on multiple lines, each line (except for the last one of course) must end with the so called "line continuation character" which tells Windows that the command (in your case the SET) isn't finished yet, even though the line is. This character is ^ in Windows (comparable to the \ in Linux/Unix shell scripts)
So what you need is:
set CLASSPATH=C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\selenium-server-standalone-2.32.0.jar; ^
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jsoup-1.7.2.jar; ^
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xstream-1.1.3.jar; ^
.... ^
.... ^
C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;
java -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m com.myProject.batch.PropertyRatesUpdaterBatchJob
(btw: you have C:\ProjectWorkSpace\myProject\web\WEB-INF\classes twice in your list)
You must make sure that there is no whitespace whatsoever after the ^ otherwise this will not work.
Btw: you shouldn't be using the CLASSPATH variable anymore. It's better to explicitly define a classpath using the -cp (or -classpath parameter for the java command).
In recent (up-to-date) versions of Java for Windows you don't need to specify each element in the classpath variable.
Quote from http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html
As a special convenience, a class path element that contains a base name of * is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR
So you can get rid of all the lines and just use:
java -cp C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\*;C:\ProjectWorkSpace\myProject\web\WEB-INF\classes com.myProject.batch.PropertyRatesUpdaterBatchJob
Team,
Ia m using IKVM to convert a jar file to a dll, so that I can use it with C# to test the Java application...I dont have the original java source code or the class files.
Here is what I am doing and the error I get:
ikvmc myApplication.jar
Note IKVMC0002: output file is "asapi.dll"
Warning IKVMC0100: class "org.apache.log4j.Logger" not found
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in "com.myApp.authenticateUser(LNote IKVMC0002: output file is "asapi.dll"
Warning IKVMC0100: class "org.apache.log4j.Logger" not found
Warning IKVMC0111: emitted java.lang.NoClassDefFoundError in
vices.AsApi.authenticateWithArtifact(Ljava.lang.String;Lcom.myApp.AppApi)....
Any ideas? This jar file doesnt contain a main method...
Regards,
Deekshit
I believe you need something more along the lines of:
/usr/bin/mono \
/path/to/ikvm-0.42.0.6/bin/ikvmc.exe \
/path/to/project/target/project-1.2.3.4.jar \
-out:/path/to/project/target/project-1.2.3.4.dll \
-keyfile:/path/to/project/target/private-key.snk \
-assembly:project-1.2.3.4 \
-fileversion:1.2.3.4 \
-version:1.2.3.4
If your application depends on third-party jars, you might need to add them to the jar, using shading (not good practice at all).
I have a problem while trying executing my java application.
Whenever I try to execute the program through the command
java ProgAudioJ
I get this error:
Exception in thread "main"
java.lang.NoClassDefFoundError: ProgAudioJ (wrong name: es_2011/ProgAudioJ)
at java.lang.ClassLoader.defineClass1(NativeMethod)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(NativeMethod)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: ProgAudioJ. Program will exit.
If I remove from my code:
package es_2011;
Everything works perfectly. How do I solve the problem?
Because I found these answers unclear, here is what you need to do.
First, if you package your code (IE your classes have the package keyword at the top) the compiled classes have to be in a directory with the same name as your package declaration in code. After you have compiled your classes, you need to move up a directory when you exectute the java command, and you include the name of the package. For example, if your code exists in /myFolder/myPackage/ , and your class starts with package myPackage (note that the directory and the package are the same name), then you would do the following (linux / osx):
cd /myFolder/myPackage
javac MyClass.java
cd ..
java myPackage.MyClass
Edit - A late edit to clarify something I see people get confused on. In the example above, the package is only one deep, meaning its just myPackage. If you code has a larger package, like
package com.somedomain.someproject;
you will need to execute the java command from the directory which contains the root directory for that package. For example if your compiled code is in myCode/com/somedomain/someproject/MyMainClass.class, then you will execute the java command from the myCode folder, like this (Again, take special note that the directory structure is the same as the package declaration):
cd /myCode
java com.somedomain.someproject.MyMainClass
Try using:
java es_2011.ProgAudioJ
(instead of java ProgAudioJ).
I'm making some assumptions here about your current working directory and your CLASSPATH. If you can provide information about the command you're running (e.g. what directory you're in, where the class file is located, etc.), we can help you more efficiently.
Try this (compile and run):
dir
2011-02-10 00:30 <DIR> .
2011-02-10 00:30 <DIR> ..
2011-02-10 00:27 58 es_2011
javac es_2011/ProgAudioJ
java es_2011.ProgAudioJ
It's quite clearly stated there:
java.lang.NoClassDefFoundError: ProgAudioJ (wrong name: es_2011/ProgAudioJ)
If you want to put a class in a package(*), then the source code must be placed in a corresponding directory, e.g.,
src/Main.java <- root package (no declaration)
src/es_2011/ProgAudioJ.java <- package es_2011;
(*) You should do it always, except for tiny throw-away stuff and possibly for the main class.
Try this,
Compile your class using below command
$ javac ProgAudioJ.java -d .
Run your application by command
$ java es_2011.ProgAudioJ
The reason that it works when you remove
package es_2011
is that you are changing how the compiler packages up, and effectively locates, the file.
I had the same problem - and the error message wrong name: does indeed point you to the answer. You are using the wrong name "ProgAudioJ" in order to run the .class file.
It has been packaged up as
es_2011/ProgAudioJ
In order to run it - you have to either move up a directory:
If you are here: (Windows)
src\es_2011\
move to
src\
Then run the line:
java es_2011.ProgAudioJ
This tells the compiler to look for the ProgAudioJ - which resides in the es_2011 package. For a standard installation, this will be based on folders - so it will look for the es_2011 folder first, and then the name of the .class file that you want to run (ProgAudio).