I faced a rather strange problem while executing a java program from the command line on Windows.
I used this command to create a source.class file from a source.java file.
javac source.java
After this, I tried to execute the source.class file using:
java source.class
This gave me the following error:
Error: Could not find or load main class source.class
However, when I do this:
java source
I get the output as desired.
I am curious to know why it failed when I mentioned .class explicitly. My professor told me that the java command is associated with .class files. Thus I want to know why this happened. Thank you.
EDIT: I don't believe this is a duplicate. I have already read the linked question. I am asking why the java command cannot execute a file when I mention .class explicitly.
Related
I successfully installed the Oracle Code Compliance Inspector (CCI) extension for JDeveloper by following the instructions. Afterwards I was able to run CCI in JDeveloper. But I'm not able to invoke Oracle CCI from a Command Line.
I can't find the script ("checkCompliance.sh") mentioned in the documentation. It's not part of the zip file I downloaded from oracle.com.
I tried to run the compliance.policy.engine.jar file directly but this fails with an error message:
java -jar /oracle/jdevhome/jdeveloper/jdev/extensions/oracle.fp.compliance.inspector/lib/compliance.policy.engine.jar -inputDir /AIA/demo -outputDir /ComplianceOut
Failed to load Main-Class manifest attribute from
/oracle/jdevhome/jdeveloper/jdev/extensions/oracle.fp.compliance.inspector/lib/compliance.policy.engine.jar
Any suggestions on how to invoke CCI from a command line or where I can find the script mentioned in the documentation?
Regarding the error message I read that this can be fixed by adding a manifest file to the jar archive which defines the Main-Class - but which one is the Main-Class of this jar file?
Okay, it's solved.
As mentioned in this part of the documentation, the CCI command line tools are distributed with Oracle Enterprise Repository (OER).
The CCI command line tools are distributed with OER within the <OER Oracle Home>/tools/solutions/<version>-ComplianceInspector.zip.
What confused me: The OER-Download only contained a single .jar file. It took me some time to realise that the .jar file is a installer.
java -jar OER111170_generic.jar [-log=full_path_to_log_file]
See installation documentation for detailed instructions.
checkCompliance.sh
After successfully installing OER, I found the <version>-ComplianceInspector.zip in <OER Home>/repository111/core/tools/solutions/.
The <version>-ComplianceInspector.zip actually contained the checkCompliance.sh file.
I have created a program in Java, but it is not taking the inputs correctly in edit-plus(compiler) so now I want it to run in cmd. My JSK file is at : C:\Program Files\Java\jdk1.7.0_21\bin and my Java file is at: C:\TurboC4\TC\java new programs
Please tell me the steps to run it in cmd.
On the command line use:
java -jar path/to/your/jar_file.jar
if you do not have a jar file, than you have to compile first your Java classes:
javac -g Foo.java
if you have just a single file (containing a static void main()) than you can simply run it with:
java path/to/your/compiled_class_file [<command line args>, ...]
Note: Run the command above without .class extension. i.e.
java Foo
if you want to generate a jar file from your compiled .class files run:
jar cf jar-file input-file(s)
However, I would recommend you to use a IDE that compiles, packs and runs your code for you automatically with one click. i.e. IntelliJ or Eclipse
If your class is not into a package and is compiled as java.class in C:\TurboC4\TC\:
cd C:\TurboC4\TC\
C:\Program Files\Java\jdk1.7.0_21\bin java
If you just want to run your single java class as a command line program, then the answer is in This question.
Example:
java my.class.HelloWorld
If you have compiled an entire java project into a JAR file, check this Stackoverflow question for the answer.
Example:
java -cp c:\location_of_jar\myjar.jar com.mypackage.myClass
I am trying to compile WordCount.java file into jar inside of /Desktop/Hadoop/playground/src.
Here's the command I am using.
javac -classpath hadoop-1.2.1-core.jar -d playground/classes playground/src/WordCount.java
The compiler seem to be getting invoked, however I am getting tons of errors like this
error: package org.apache.hadoop.conf does not exist import org.apache.hadoop.conf.Configuration
How do I go about fixing this?
May be there is an answer to this issue already. However I could not fix it.
You need to set the paths of hadoop-1.2.1-core.jar and all the other dependent jars correctly --
Try this exactly while you are in the Desktop/hadoop directory (valid in your case only solely based upon the inputs you provided in the comments)
javac -classpath *:lib/* -d playground/classes playground/src/WordCount.java
I have used the STS(Spring Tool Suite) to create a compiled groovy script which exists as a file on windows called Test.class. I am able to right click on the file in STS and execute it which works well.
However - I want to be able to execute the script on the windows command line, so far I have tried various ways but have not been successful. I have tried the following...
java -cp C:\Users\MyName\springsource\sts->
3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\
org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar Test.class
But that does not work it gives me an error --> Error: Could not find or load main class Test.class
Any Pointers?
You are trying to run a test case, so you really ned to be launching junit and ass this test as the test to run.
The easiest thing to do is to download a distribution of groovy, unzip, and run:
groovy Test.groovy
Step 1
In STS(Spring Tool Suite) ,Create a Groovy Class e.g. Customer.groovy file. Specify a Package Name e.g. com.customer. In the main method put in code to validate the code is being called e.g. println ‘test’.
Step 2
Go to your command line (Windows use command prompt). Switch\cd to the ROOT directory of your project. Execute the command below.
Step 3
execute java -cp C:\Users\Profile\springsource\sts-3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar;. com.customer.Customer
The code should run.
V Important
If like me, you do not have a class and you only have a groovy script then in step#3 specify the Groovy script name without the suffix.
Test is naked? (without package name?) try this.
java -cp C:\Users\MyName\springsource\sts-> 3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\ org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar;. package.Test
Pay attention to ;. and package name.
I also need to generate outside eclipse and i didn't figured out how to do it.
I've read this thread but I have another problem to overcome first : I'm unable to start the main !
I tried different ways : export the project as standalone, put the project in a regular or executable jar, and launch directly Generator.class. I would like some help with the last solution. Here's how I launch it :
java -cp "..\testGene\bin\;C:\Program Files\Eclipse\plugins" testGene.main.Generate testModel.uml outputDir
I can't copy the whole console (dev computers are not connected to internet), but it says :
Exception in thread "main" java.lang.NoClassDefFoundError: org/Eclipse/acceleo/engine/service/AbstractAcceleoGenerator
Could not find the main class: testGene.main.Generate.
The generator works well inside eclipse, and I manage to call a simple test class with the same command line. I tried to copy the whole acceleo plugins in my bin directory in case the space in "Program Files" is a problem.
I'm pretty sure this is a simple error I made, any ideas ?
Furthermore, I'm not sure that it's sufficient to use the plugins folder in your classpath. Shouldn't there be a list of the jar files you need?
Since the program does not seem to find the AbstractAcceleoGenerator I would say that you are lacking some dependencies of the generator. Have a look at this screenshot to see the jar used for an UML to Java generator.