Error while trying to run the jar file in command prompt - eclipse

My requirement is to run a eclipse java project in command prompt. I am using following program structure:
project name:parser
package name:xml
class name:Sample (with the main method)
I tried exporting the jar file by right clicking the project name-->export-->jar file-->gave the destination path for jar file->checked the Generate Manifest file and selected the main program(Sample.java).
Now in the command prompt i tried to run the jar file in the cmd using
java -jar myjar.jar.
And the error message I get is:
Exception in thread "main" java.lang.UnsupportedClassVersionError: XML/Sample:
Unsupported major.minor version 51.0
Could not find the main class: XML.Sample. Program will exit.
I have been searching for a solution for a long time but failed to find one. I would be very thankful if someone could help me with this problem. Kindly excuse for any mistakes in my question as I am new to java coding. Thanks in advance

Related

How to run Liquibase on command line with Custom Change java class?

I am trying to run my liquibase update from the command line. However, I have a customChange in my changelog file, i.e. a Java file that implements liquibase.change.custom.CustomChange. The update is successful when running via Spring. However, when I try to apply the update via command line using
liquibase --changeLogFile=<my_changelog_file> --username=<my_user> --password=<my_password> --url=<my_url> --driver=org.postgresql.Driver --classpath='<path_to>/postgresql-42.2.8.jar:<absolute_path_to_my_jar.jar>' update
I am getting this error:
Liquibase Community 3.8.6 by Datical
Unexpected error running Liquibase: liquibase.parser.core.ParsedNodeException: liquibase.exception.CustomChangeException: java.lang.ClassNotFoundException: com.<my_company>.platform.changeset.EncryptPasswordsChangeset
I have obscured any real values I am passing in for security reasons. Anyone know how to let liquibase find this file? I tried creating a jar with just the necessary files and adding that jar to the classpath, but that doesn't seem to work as the jar does not contain any main classes.
Running
jar tf <my_jar.jar>
results in:
META-INF/
META-INF/MANIFEST.MF
com/<my_company>/platform/changeset/EncryptPasswordsChangeset.java
com/<my_company>/platform/security/PasswordEncryptUtil.java
com/<my_company>/platform/encrypt/SymmetricCipher.java
My jar was not formed properly. Should be building it with compiled .class files, not .java files.

Error occurred during initialization of boot layer java.lang.module.FindException executing Selenium tests using TestNG and Java 12 through Eclipse

ErrorOccuredDuringInitializationofbootlayer I keep getting this error when I run
my test:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for
C:\Users\Bonfire.eclipse\org.eclipse.platform_4.12.0_867647348_win32_win32_x86_64\plugins\com.beust.jcommander_1.72.0.jar
Caused by: java.lang.IllegalArgumentException:
com.beust.jcommander.1.72.0: Invalid module name: '1' is not a Java
identifier
How can I fix it?
Add TestNG Library to classpath in buildpath ( not to module path). It will work fine.
To avoid this error, do not add TestNG library in the project or src folder. Try adding it into the package. To do so , follow the below mentioned procedure.
Right click on the package, click Build Path->Configure Build Path, go to Libraries tab, select Classpath and click on Add Library to select TestNG.
This error message...
Error occurred during initialization of boot layer java.lang.module.FindException:
Unable to derive module descriptor for C:\Users\Bonfire.eclipse\org.eclipse.platform_4.12.0_867647348_win32_win32_x86_64\plugins\com.beust.jcommander_1.72.0.jar
Caused by: java.lang.IllegalArgumentException: com.beust.jcommander.1.72.0: Invalid module name: '1' is not a Java identifier
...implies that there was an issue with the java classpath.
As per the discussion Launch with java 11 fails: Error: Could not find or load main class with Caused by: java.lang.ClassNotFoundException: with there are some issues with some particular classpaths for java-11 and the launch fails if:
The classpath contains a folder with spaces
The classpath length is larger than 32767 characters.
Where as java-8 works fine.
Reference
Unable to import org.openqa.selenium.WebDriver using Selenium and Java 11
Outro
Eclipse plugin: TestNG testcase does not run with Jdk11
Need to add 1.8 version library
Remove TestNG from build path library and add again
Recheck - the issue should be resolved.
I got same issue and I solved it. When creating the project, don't create module-info.java. When the project was already created with the module-info.java, deleting this file didn't help me.
I just created new project without module-info.java, and all works good now.
Best option to resolve this:
Find all file and folder starting with . e.g. — .metadata / .setting and delete them.
Add all the JARS.
Add testNG Libraries.
Execute it.
Done.

AntBuilder works in Groovy Console but not in Eclipse

I am running Windows 7. The following code works in Groovy Console:
def fileEx = new File(/Y:\Documents\Test File.txt/)
def copyToFile = new File(/Y:\Documents\Test File - Copied by Groovy and Ant.txt/)
ant = new AntBuilder()
ant.copy(file:fileEx, tofile:copyToFile)
but when I try to run it as a Groovy Script in Eclipse, I get this error:
Caught: java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException
java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException
at copyFile.run(copyFile.groovy:4)
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.BuildException
I have tried adding ant.jar to myclasspath, both the ant.jar in the Groovy lib folder and the one in the Eclipse plugins lib folder, but this does not solve the problem.
Looks like groovy-eclipse plugin ships with a subset of libraries a full install of groovy does. You'll want a full install of groovy, which you may already have, in addition to the eclipse plugin.
You should be able to solve your problem by going to your project, and going to Properties->Java Build Path, then click 'Libraries'. 'Add External Jars' and navigate to your full groovy installation. Under there, the lib directory should have the ant.jar and ant-launcher.jar. Add them both. This should clear this up (and queue up the underlying problem for debugging).

Error in Eclipse about type indirectly referenced from required .class file

I'm having this exception with some stubs generateds by Axis2:
"The type org.apache.axiom.om.OMElement cannot be resolved. It is
indirectly referenced from required .class files"
I've been reading many posts, and trying to find a solution. What I've found so far is to add the apache tomcat 5.5 library to the build path. It removed the error in the java file, but then, when I to execute any java program inside the project, I got this error:
'Launching myApp' has encountered a problem Exception occurred
executing command line. Cannot run program "C:\Program
Files\Java\jdk1.5.0_22\bin\javaw.exe" (in directory
"D:\Digicel\workspace\Digicel\myClassSample"): CreateProcess error=87,
The parameter is incorrect
then if I remove the apache tomcat library from the build path, I can run the other java programs, but not the one mentioned initially.
Any thoughts about it?
Okay, I've found the cause of the problem with the help of a friend :)
The thing is that Eclipse is aware that one of my dependencies, depends of another library, and Eclipse is checking for it when it tries to build the code.
So, what I've done is try to check which jar file contains this library: " org.apache.axiom.om.OMElement".
I've googled it and found that it is "axiom-api-1.2.10.jar" and finally my file compiled with 0 errors.
He also explained to me that my original solution of adding the apache tomcat server library is adding all the jars that cames with apache tomcat (which is a big list), and probably there may have been a version conflict with my current list of added jars.
So, the fix was to find the appropriate jar and add it to the project.
This error can also occur when a indirect dependency has a corrupt jar file. This may be caused by problems at the public maven repository.
If this is the case removing the local maven repository to download fresh jar files will fix your problem:
rm -Rf ~/.m2/repository/{enter/path/to/broken/stuff}
Goto Maven >Update Maven project>checkmark the Force update >Then Run
..That error Will gone....

Eclipse VM Argument and external JAR file error

I just added "-Djava.library.path=" to the "VM Arguments" under Run Configuration in Eclipse and everything works fine until I tried to add an external JAR file. I get the following error:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
Am I not setting something properly in Eclipse?
If your interested I forked RXTXserial a while back since thier update "schedule" sucks. I have just ported it over to the Android platform too. We decided to move the native libs into the jar and use reflection to deploy them. The API is the same as RXTX, but everything just works. You can find jars and full project sources at:
http://code.google.com/p/nrjavaserial/
The exception indicates that the class gnu.io.RXTXCommDriver tries to load a native library, which would be named rxtxSerial.dll on Windows and rxtxSerial.so on Linux, and the JVM cannot find it in the directories listed in java.library.path. Have you tried to add a JAR containing the library to java.library.path? I don't think that's possible, it has to be a directory containing the extracted library file.
Appearently that external library has a dependancy with another class gnu.io.RXTXCommDriver
. Perhaps you will need to add that library to class path.