Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Thursday, December 12, 2019

How To Brand Executable Jolt File Inward Eclipse Ide - Java

If y'all are Java programmer thence y'all know what is the role of JAR file, but for those who are unaware, JAR file is deliverables of Java application. Just similar C in addition to C++  application attain EXE files, Java produces JAR files. In other words, Influenza A virus subtype H5N1 JAR (Java Archive) file is a ZIP format file that bundles Java classes into a unmarried unit, it may incorporate all the resources needed past times Java application every bit well. There are mainly ii types of JAR file inward Java:  Library JAR (normal JAR) files: JARs which are reusable libraries e.g. Apache park JAR file, guava.jar itself or fifty-fifty JDBC drivers e.g. ojdbc6_g.jar. There is simply about other type every bit well, Executable JAR files: JARs which tin hold upwardly executed every bit a standalone Java applications. The original divergence betwixt normal in addition to executable JAR file is that afterwards contains a mainfest file, which specifies a main-class entry. When y'all run that JAR file, Java starts your application past times reading that main-class entry, because y'all shout for the original method to execute Java programs.

I had before shared steps to create JAR file from ascendancy prompt, which if y'all guide maintain non read, become read it. You volition larn virtually basics of JAR command, which comes amongst JDK, mainfest file in addition to dissimilar attributes of manifest file.

In this tutorial nosotros volition larn how to make/create/export both library in addition to executable JAR file inward Eclipse IDE. Why it's of import to know creating executable JAR inward Eclipse, because its i of the most used tool past times Java programmer.

Once y'all know the steps, y'all export your Java plan every bit JAR file inward a minute or two. After creating executable JAR file, y'all tin follow these steps to run Java plan from JAR file inward ascendancy line.




Steps to Create Executable JAR file inward Eclipse

Influenza A virus subtype H5N1 pic is worth to a greater extent than than a one k words, that's why I guide maintain provided all steps past times taking screenshots. You tin apace larn how to create executable JAR for your Java application inward Eclipse, past times simply looking at these screenshot. They are arranged from start to end. Which agency commencement picture is for commencement mensuration in addition to concluding picture is for concluding step. By the way, if your application is subject upon simply about other JAR files e.g. third-party library, thence don't shout for to include them within JAR. All y'all shout for to exercise is include them within your Java Classpath. Java is smart plenty to pick classes from those JAR. Also recall to include original method or entry shout for of your Java program, spell creating executable JAR, every bit y'all tin non run a Java plan without original method, every bit discussed here.


Step 1
Select your projection in addition to click on the export option.




Step 2
Choose Java in addition to select JAR file for exporting


Step 3
Now select the beginning in addition to resources y'all desire to export into JAR file. After selecting src folder in addition to whatever resource, select the destination folder, where y'all desire your JAR file to hold upwardly created. Also don't forget to depository fiscal establishment lucifer selection "compress the content of JAR file". This volition cut down size of executable JAR file. If y'all desire y'all tin destination the procedure inward this step, but y'all tin also become i mensuration farther to salve these education of executable JAR file creation for hereafter use.


Step 4
In this mensuration y'all tin salve all education into a "JAR description" file for hereafter use. This volition create a description file e.g. Test.jardesc inward the chosen folder.


Step 5
This is an of import step, because y'all are going to generate the manifest file, don't forget to guide original class. This is of import to brand your JAR an executable JAR file. Remember main method is entry shout for of whatever Java application.


Step 6
You are done amongst creating executable JAR file. Now y'all tin become to the target folder, which y'all guide maintain chose inward previous steps to encounter both JAR file every bit good .jardesc file to recreate JAR file over again in addition to again. This fourth dimension y'all don't shout for to include main class every bit well, every bit those are already included.


Step 7
After making code changes, if y'all desire to create a novel JAR file, y'all don't shout for to become through all previous steps. This time, simply select your JAR description file in addition to tell "create JAR", a correct click carte selection inward Eclipse. This volition create simply about other JAR file inward same folder. You tin double depository fiscal establishment lucifer timestamp of JAR file.



That's all virtually How to create or brand Executable JAR file inward Eclipse IDE. By next these steps y'all tin export your Java plan every bit executable JAR, which allow y'all to percentage your plan amongst your user, customer in addition to whatever i who wants to guide maintain a look. I strongly advise to salve education to export JAR file, thence that y'all don't shout for to run through all these steps over again in addition to again. Next time, when y'all update your code, simply click on your jardesc file in addition to your JAR file volition hold upwardly ready inward a blink.

Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 in addition to 2

Sunday, November 24, 2019

How To Increase Heap Size Of Coffee Plan Running Inwards Eclipse

It is possible to increment the heap size allocated past times the JVM past times using dominance business options Here nosotros attain got iii options

-Xms<size>        to laid the initial Java heap size
-Xmx<size>        to laid the maximum Java heap size
-Xss<size>          to laid the coffee thread stack size

$ coffee -Xms1G -Xmx2G MainClass

In the inwards a higher house line, nosotros attain got laid the minimum heap size to 1GB too maximum heap size to 2GB.


On a 32-bit JVM, the largest heap size you lot tin theoretically laid is 4GB, but inwards practice, you lot volition never meet that level. Practically, you lot volition acquire simply about 1.5GB inwards 32-bit Windows, 2.5GB on 32 chip Linux too slightly to a greater extent than on 32-bit Solaris system.  To role a larger heap size, you lot require to role a 64-bit JVM, where you lot tin theoretically laid quite a large heap space. See this article for learning to a greater extent than near maximum heap size of a 64-bit JVM.

In Solaris, you lot tin laid large heap infinite on a 64-bit JVM every bit following:

$ coffee -Xmx6144M -d64 MainClass

The -d64 flag is of import every bit this tells the JVM to run inwards 64-bit mode. See hither to larn near some to a greater extent than important JVM arguments, every Java developer should know.



If you lot are experienced Java developer hence it's also expected from you lot to know to a greater extent than near JVM, Garbage collection too how to melody both JVM too Garbage collection. You should also know near tools similar a profiler, heap dump analyzer to troubleshooting application functioning issue. If you lot desire to amend your JVM too GC tuning science hence you lot should depository fiscal establishment tally out Java Performance The Definitive Guide By Scott Oaks, ane of the must read a mass for experienced Java programmers.

 allocated past times the JVM past times using dominance business options Here nosotros attain got  How to Increase Heap Size of Java Program running inwards Eclipse



Increasing Heap Memory for Java Program Running on Eclipse

It is possible to increment heap size allocated past times the JVM inwards eclipse straight In eclipse IDE acquire to

Run---->Run Configurations---->Chose the right application --->VM Arguments

Enter -Xmx1G, to laid the max size to 1GB. You tin also role G or K, which stands for Megabytes too Kilobytes for event -Xmx256M way maximum heap space would move 256 Megabytes.

Here is measuring past times measuring guide to laid  the heap size of Java programme inwards Eclipse:

Step 1: Go to the Run Configuration of Application or Program for which you lot desire to increment the heap space.

 allocated past times the JVM past times using dominance business options Here nosotros attain got  How to Increase Heap Size of Java Program running inwards Eclipse


Here nosotros are increasing heap size of MultipleThreadDemo application which is run past times the Main shape MultipleThreadDemo, every bit you lot tin meet inwards configuration.

Step 2: Enter right JVM options at the VM Arguments area

 allocated past times the JVM past times using dominance business options Here nosotros attain got  How to Increase Heap Size of Java Program running inwards Eclipse


Beware non to add together the JVM arguments at the Program Arguments text area, that's for programme arguments e.g anything you lot desire to role to programme using -D e.g. -Dversion="1.0"



Important points

1) Depending upon the heap infinite you lot render too operating arrangement you lot are running you lot may acquire the Invalid maximum heap size error every bit I got when I tried to laid maximum heap size for a 32-bit JVM inwards Windows to 1.5G:

Invalid maximum heap size: -Xmx1.5G

When you lot run the programme you lot volition also meet the "Error: Could non attain the Java Virtual Machine" every bit seen inwards the next pop-up which indicates the JVM is non created due to invalid heap size:

 allocated past times the JVM past times using dominance business options Here nosotros attain got  How to Increase Heap Size of Java Program running inwards Eclipse


2. Make certain at that topographic point is no infinite betwixt -Xmx too 1G e.g. -Xmx 1G volition also throw invalid heap size error.

3. One to a greater extent than mutual error you lot require to avoid is using suffix similar GB, MB, too KB instead of G, M, too K, those volition also number inwards could non attain the Java Virtual Machine error.


That's all near how to increment heap size of Java application running on the Eclipse every bit good every bit on the dominance line.

Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 too 2


Jdbc - How To Connect Eclipse To Oracle Database - Pace Past Times Pace Guide

Though I prefer Toad or Oracle SQL Developer tool to connect Oracle database, sometimes it's useful to straight connect Eclipse to Oracle using JDBC using its Data Source Explorer view. This way you lot tin sentiment data, run SQL queries to the Oracle database right from your Eclipse window. This volition salvage a lot of fourth dimension wasted during switching betwixt Toad in addition to Eclipse or Oracle SQL Developer in addition to Eclipse. Eclipse also allows you lot to sentiment Execution excogitation inwards both text in addition to Graphical mode, which you lot tin purpose to troubleshoot functioning of your SQL queries. In this article, I'll tell you lot steps to connect Eclipse to Oracle database. Since Eclipse uses Java to connect to Oracle database, it asks for JDBC driver information. Since connecting using sparse Oracle JDBC driver is much easier, every bit you lot merely demand to drib a JAR file inwards the classpath, nosotros volition survive using JDBC sparse driver to connect Oracle from Eclipse. Depending upon your Oracle version e.g. Oracle 10g or Oracle 11g you lot demand to download Oracle JDBC sparse driver e.g. ojdbc14.jar file. Just download this JAR file in addition to configure it on Eclipse IDE. Enter the username, password, in addition to sid in addition to you lot are hit to execute SQL query to Oracle database from Eclipse.


In companionship to connect to Oracle database instance, you lot demand ii things:

1) Eclipse IDE for Java EE developers, because that contains the database evolution plugin which doesn't come upwards along alongside Eclipse IDE for Java developers. You tin download the latest version of Eclipse IDE for Java EE developers here.

2) Oracle JDBC JAR, since Eclipse uses JDBC to connect to Oracle database it needs JDBC driver JAR for Oracle. You tin purpose whatever type of JDBC driver, but I prefer Oracle JDBC sparse driver e.g. ojdbc14.jar file to connect to Oracle 11g instance. If you lot don't have, you lot tin download from here.

Once you lot receive got these ii things, nosotros are hit to connect to whatever local or remote Oracle database illustration from Eclipse IDE.   I am using Eclipse Java EE IDE for Web Developers, Version: Kepler Service Release 2.




Steps to connect Oracle database from Eclipse

The steps are just similar to what I receive got shown you lot earlier piece connecting to Microsoft SQL Server from Eclipse IDE, here, the alone divergence is, this time, nosotros are choosing Oracle from the listing of database in addition to installing Oracle JDBC driver instead of SQL Server JDBC driver.

Here are the exact steps to connect Oracle illustration from Eclipse:
  1. Open Eclipse IDE in addition to Select Database Perspective (Windows >> Open Perspective >> Other >> Database Development).
  2. Create Connection Profile, Chose Oracle
  3. Choose JDBC Driver in addition to specify its location
  4. Specify connectedness special e.g. host, port, username, in addition to password
  5. Test Connection

Tips similar this salvage a lot of fourth dimension in addition to amend productivity in addition to that's why I receive got e'er said that goodness agreement of Eclipse IDE is must to acquire an practiced Java J2EE developer in addition to developer should pass to a greater extent than or less fourth dimension to acquire their tools e.g. Eclipse.

If you lot are primarily a Java EE developer hence you lot tin also accept a expect at Ram Kulkarni's Java EE Development alongside Eclipse book, which volition assist you lot to write code, debug, test, in addition to troubleshoot Java EE vii applications right from the Eclipse IDE.




Now, let's encounter each pace inwards lilliputian chip special alongside screenshot if you lot are hit to connect to Oracle database from Eclipse, follow it along:

Step 1: Open Eclipse IDE in addition to Select Database Perspective
In companionship to opened upwards the Database Development perspective choke to Windows >> Open Perspective >> Other >> Database Development, every bit shown below:

 Though I prefer Toad or Oracle SQL Developer tool to connect Oracle database JDBC - How to connect Eclipse to Oracle Database - Step past times Step Guide



Step 2:  Create Connection Profile
For creating a novel connectedness profile, choose the "Database Connection" at the top left inwards the Database Development view, right click in addition to choose "New Connection". This volition opened upwards the New Connection Profile window every bit shown below. Now type Oracle in addition to give your connectedness profile a meaningful name e.g. combination of application, host, in addition to instance.

 Though I prefer Toad or Oracle SQL Developer tool to connect Oracle database JDBC - How to connect Eclipse to Oracle Database - Step past times Step Guide



Step 3: Choose JDBC Driver in addition to specify its location
Once you lot receive got selected the database, it's fourth dimension to choose the JDBC driver. To configure JDBC driver, merely click the setting icon on the previous covert every bit shown below:

 Though I prefer Toad or Oracle SQL Developer tool to connect Oracle database JDBC - How to connect Eclipse to Oracle Database - Step past times Step Guide

After that, the next covert volition opened upwards which volition listing downwards all JDBC drivers for supported Oracle versions e.g. Oracle 10g, Oracle 11g, in addition to JDBC sparse driver or other drivers. I receive got chosen the Oracle Thin Driver to connect Oracle 11g every bit seen below:

 Though I prefer Toad or Oracle SQL Developer tool to connect Oracle database JDBC - How to connect Eclipse to Oracle Database - Step past times Step Guide


Once you lot choose a special driver, you lot tin encounter the fault message look at the top proverb "Unable to locate JAR/ZIP inwards the file organization every bit specified past times the driver definition: ojdbc14.jar", this way you lot demand to locate the path of this JAR inwards your local file system, every bit shown below. If you lot don't specify the right JAR, you lot volition acquire "java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver" error.


Once you lot are done, click Ok in addition to hence it volition accept you lot to the previous screen. Click side past times side there.


Step 4:  Specify Database Connection details
Now, it's fourth dimension to specify the database connectedness details e.g. host, port, sid, username, in addition to password required to connect to an Oracle database instance.



Step 5: Test Connection
Once you lot are done alongside putting connect detail, merely click the "Test Connection" button, if everything is goodness hence you lot volition encounter a ping succeed message, if non hence you lot volition encounter a "ping failed" message.


That's all most how to connect Eclipse to Oracle database using Java in addition to JDBC. This is an immensely helpful tip if your application is using Oracle database at the backend in addition to you lot oftentimes demand to select, update or delete data.

Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 in addition to 2

Saturday, November 23, 2019

Unsupported Major.Minor Version 52.0 Inwards Coffee + Eclipse + Linux [Solution]

The "unsupported major.minor version 52.0" mistake started to come upwards afterward Java SE 8 unloosen as well as the rootage drive of this mistake is trying to run a Java application compiled amongst JDK 8 into a JRE lower than Java SE 8 e.g. JRE seven or JRE 6. This is really mutual because a developer has updated their compiler or IDE to Java SE 8 but many times their runtime is non upgraded to Java 8. If y'all remember, inwards Java y'all tin run a shape file compiled amongst a lower version nation Java vi to a higher version nation JRE 8 because Java is backward compatible but vice-versa is non allowed. This brand feel because Java SE 8 has features similar lambda expressions, method reference, functional interface as well as new Date as well as Time API, which lower version JRE has no information. Depending upon where y'all getting this mistake e.g. Eclipse, NetBeans, IntelliJ IDEA or Android Studio, the solution could hold upwards different. All these IDEs has dissimilar settings for JRE but the bottom business is same, y'all require to configure these IDE to work JRE 8 to run the Java programme compiled using Java 8.

The rootage causes of any java.lang.UnsupportedClassVersionError is ever that y'all bring compiled source file inwards higher JDK version as well as trying to run on lower JRE. The exact drive is printed on the version e.g. inwards the illustration of major.minor version 52.0, y'all know that shape file is compiled amongst JDK 8 because major version 52 corresponds to Java SE 8.

You mightiness bring seen the Unsupported major.minor version 51.0 error duo of years dorsum when JDK seven was released because that came when a shape file compiled using Java seven was running on Java 6. The major version 51 corresponds to Java SE seven release.




How to solve unsupported major.minor version 52.0 inwards Java

Now let's come upwards dorsum to the solution, how nosotros are going to solve the major.minor version 52.0 mistake inwards Java? One of the argue is wrong JRE inwards PATH surroundings variable.  If y'all are running the Java programme from ascendency prompt therefore brand certain the PATH has been setup correctly.

Just impress the PATH using echo %PATH% in Windows 8 as well as echo $PATH inwards Linux to banking corporation check if whatsoever lower version JRE is non coming upwards higher inwards the PATH than JRE 8. This is the master copy argue y'all acquire "unsupported major.minor version 52.0" fifty-fifty afterward y'all bring installed Java 8 on your machine.

If y'all run into JRE vi or JRE seven coming upwards higher or in that location is no JRE 8 at all therefore merely install the JRE 8 as well as brand certain it come upwards offset inwards the PATH. Don't impact the classpath, this upshot is non related to the classpath, it alone related to PATH as well as Java version used to run the program.

You tin besides banking corporation check out Core Java Volume 1- Fundamentals to larn to a greater extent than nearly this mistake inwards Java.




Unsupported major.minor version 52.0 inwards Android Studio

Android Studio uses the value of JAVA_HOME to observe the electrical current Java version. Check the value of this surroundings variable as well as if it's non pointing to JDK 8 therefore brand certain y'all right the value of this surroundings variable. Don't forget to restart the Android studio if y'all unset JAVA_HOME piece the android studio is running.

This should solve the job of "unsupported major.minor version 52.0 mistake inwards Android Studio".  If y'all recall Android Studio is built from IntelliJ Idea, 1 of the pop Java IDE of both nitty-gritty Java as well as Java EE developers. See this article larn to a greater extent than nearly the unsupported major kid version error inwards Java.

Mac OS X users y'all tin create next to teach IntelliJ should work Java 8

1) Go to /Applications/IntelliJ IDEA 14.app/Contents/bin/ folder
2) Add gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home to idea.properties file.
You tin observe the idea.properties file inwards Mac OS X (10.9 - Mavericks) at inwards the to a higher identify location (Applications/IntelliJ IDEA 14.app/Contents/bin/)
3) Restart IntelliJ IDEA.

IntelliJ IDEA uses Grade to compile as well as create your Java application.

JDK 8 installation every bit shown below:

export JAVA_HOME=/usr/lib/jvm/java-8-oracle

Make certain JAVA_HOME is pointing to right JDK 8 installation directory.

Also,add JAVA_HOME on PATH every bit shown below:

export PATH = $PATH:$JAVA_HOME;

You tin follow same steps to create unsupported major.minor version 52.0 mistake inwards other UNIX based operating systems e.g. ubuntu, Solaris or IBM AIX.


That's all nearly how to solve unsupported major.minor version 52.0 mistake inwards Java. The rootage drive of mistake is that your Java programme is compiled using Java 8 but the JRE running this programme is of lower version e.g. JRE seven or JRE 6. Just work the latest JRE i.e. JRE 8 to run this Java program. Mostly y'all require to banking corporation check the PATH surroundings variable that JRE 8 is included as well as its the offset 1 inwards the search path. Depending upon which OS y'all are running e.g. Windows 10, Linux or MAC OS X, y'all require to follow respective approach to laid the PATH correctly.

Other Java troubleshooting guide
  • General Guide to solve java.lang.ClassNotFoundException inwards Java [guide]
  • How to solve java.lang.ClassNotFoundException:org.Springframework.Web.Context.ContextLoaderListener [solution]
  • How to connect to MySQL database from Java Program [steps]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver inwards Java MySQL? [solution]
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver inwards Java? [solution]
  • How to fix java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver inwards Java? [solution]
  • How to create java.lang.ClassNotFoundException: org.postgresql.Driver mistake inwards Java? [solution]
  • How to avoid ConcurrentModificationException inwards Java? (solution)
  • Exception inwards thread "main" java.lang.IllegalStateException during Iterator.remove() (fix)
  • java.sql.SQLException: No suitable driver constitute for jdbc:jtds:sqlserver (solution)
  • Cause as well as solution of java.lang.ClassNotFoundException: com.mysql.jdbc.Driver (solution)


Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 as well as 2

3 Ways To Solve Eclipse - Top Dog Shape Non Flora Error

Like many Java programmers who acquire "Error: Could non give away or charge primary degree Main" while running Java programme inwards Eclipse, I was also getting the same work recently. The "Error: Could non give away or charge primary class" was rendered me puzzled fifty-fifty later my 10+ years of sense amongst Java errors as well as exceptions. Whenever I run my Java application either past times Run configurations or correct click as well as run equally Java program, I acquire an annoying popup complaining nigh "could non give away or charge the primary class, the programme volition exit". I checked, the projection was compiling fine, I tin run across the .class file for the primary degree inwards the bin directory of Eclipse, as well as I tin fifty-fifty run across the projection as well as output folder added on the classpath of Run configuration, but nevertheless I am getting the "could non give away primary class, programme volition leave of absence error".

I spent skillful ii hours trying everything I could, calling teammates for assist (getting an extra pair of optic e'er helps inwards this sort of situation),   searching on the internet, as well as lots of trial as well as error, but the mistake was persistent. The outset clue I got when I debug my Java program. I debug the Java application inwards Eclipse past times correct click as well as choosing "Debug As Java program" as well as constitute that it was throwing ClassNotFoundEexception for of a third-party class.

It was a sort of break-through later wasting such a long fourth dimension but still, the clue wasn't plenty because the degree belongs to i of the subject JAR which was available inwards classpath but somehow Eclipse was non seeing it. My mistake was resolved later deleting existing run configuration where User entry was non pointing to default classpath. Just deleting the run configuration as well as re-creating it past times running the degree past times correct click, "Run As Java program" volition gear upwards the error.




Solution of Error: Could non give away or charge primary degree inwards Eclipse

Even though I managed to solve the work but it was likewise much a problem for me as well as taken a lot of time. I don't desire to facial expression upwards the same province of affairs again, peculiarly if I am inwards urgency to run my Java programme to debug an urgent production issue. Hence, I conduct maintain decided to jot downwards my sense amongst a duo of to a greater extent than tricks from the past. In this article, I'll portion iii useful tips to solve "could non give away or charge primary degree error" inwards Eclipse. 


1) Delete the existing run configuration
When you lot run the primary degree equally "Run equally Java Program", it adds the default classpath of the projection equally User entries into Run Configurations's classpath equally shown below.

 I was also getting the same work late 3 ways to solve Eclipse - primary degree non constitute error


The work inwards my instance was that my projection also needed native libraries as well as due to other errors I conduct maintain been picayune amongst classpath. It seems spell creating the run configuration past times copying from approximately other project, I deleted the former projection amongst default classpath as well as added novel projection without default classpath. This caused the work equally Eclipse was non detecting whatever subject JAR inwards the project. The work was obscured past times the mistake because it e'er complains nigh primary degree non found, similar to the annoying popup below:

 I was also getting the same work late 3 ways to solve Eclipse - primary degree non constitute error


Remember, if your primary degree is subject upon whatever other degree or JAR file as well as if you lot believe everything inwards the classpath, as well as then simply delete the Run configurations as well as Run the primary degree equally Java programme as well as and then edit the run configuration. This solved the work inwards my case. You tin farther read Core Java Volume 1 - Fundamentals to larn to a greater extent than nigh classpath as well as how JVM search as well as charge degree files.

Also, approximately of you lot mightiness non live on getting this popup because I got the popup exclusively on Eclipse Kepler but when I tried to reproduce the effect inwards "Eclipse IDE for Java developers" on Eclipse Luna, I simply got the "Error: Could non give away or charge primary degree Main" inwards reddish as well as bold.


2) Check for missing library
If you lot run across a red exclamation mark inwards your projection way approximately of the libraries which are added inwards construct path is either deleted or moved to other location. Until you lot gear upwards this issue, your projection volition non compile as well as no degree is created inwards the bin directory, thence when you lot run your Java program, Eclipse's classloader volition non give away the primary degree as well as throw this error.

Here is how your projection volition await similar if whatever library from construct path is missing due to whatever argue e.g. someone copied to approximately other directory or you lot unopen the projection from which they were added.


 I was also getting the same work late 3 ways to solve Eclipse - primary degree non constitute error

To  solve this work simply follow below steps:
  • Go to configure construct path
  • Check which JAR is missing
  • Remove them as well as add together them from the novel location. 
You tin farther read Eclipse inwards Action: Influenza A virus subtype H5N1 Guide for the Java Developer to larn to a greater extent than nigh setting as well as edifice Java projects inwards Eclipse.



3) Debug the program
This volition nation you lot precisely which degree is missing inwards the classpath. I hateful if your primary degree is referring approximately other degree from a third-party library as well as that library is non inwards the classpath, Eclipse volition throw the same "main degree non constitute error". When you lot run the programme inwards debug mode, you lot tin run across precisely which degree the programme is non able to found.

Here is how the debug configuration await like, you lot simply require to click the debug to start debugging your program, the JVM volition start automatically if it's non able to give away the primary degree as well as impress the actual degree as well as mistake inwards console.

 I was also getting the same work late 3 ways to solve Eclipse - primary degree non constitute error


There were a duo of to a greater extent than reasons of "Error: Could non give away or charge primary degree Main" inwards Eclipse. I'll like shooting fish in a barrel add together those equally well. If you lot desire to assist you lot tin position your work as well as solution related to Eclipse primary degree non constitute mistake as well as I'll add together those reasons inwards the primary posts. I retrieve to brand this ship service my acquire to house whenever I acquire the ClassNotFoundException or NoClassDefFoundError inwards Eclipse to avoid wasting to a greater extent than fourth dimension inwards future.


Other Eclipse tutorials as well as tips for Java developers
  • How to connect Eclipse to Oracle database? (see here)
  • How to brand executable JAR file inwards Eclipse? (see here)
  • How to growth heap size of Java programme running inwards Eclipse? (see here)
  • How to gear upwards Unsupported major.minor version 52.0 mistake inwards Eclipse? (see here)
  • 3 Maven Eclipse tips for Java developers (see here)
  • Top xxx Eclipse keyboard shortcuts  for Java programmers (see here)
  • How to setup remote debugging inwards Eclipse (see here)
  • How to attach rootage code for JAR file inwards Eclipse for debugging? (see here)
  • How to gear upwards maven dependency search non working inwards Eclipse? (solution)
  • 3 Books to larn as well as master copy Eclipse IDE for Java programming (books)


Further Learning
Beginners Eclipse Java IDE Training Course
Eclipse Debugging Techniques And Tricks
The Eclipse Guided Tour - Part 1 as well as 2

Friday, November 1, 2019

Eclipse - Unsupported Major.Minor Version 53.0, 52.00, 51.0 Mistake Inward Java

The UnsupportedClassVersionError is a large nightmare for Java developers, belike the side past times side biggest afterwards NoClassDefFoundError together with ClassNotFoundException but its slightly easier to solve. The root drive of this fault is that your code is compiled using higher JDK version together with you lot are trying to run it on the lower version. For example, the Unsupported major.minor version 53.0 way your code is compiled inwards JDK ix (the shape version 52 corresponds to JDK 9) together with you lot are trying to run it on whatever JRE lower than Java 9, belike JDK 8, 7, or 6.

Similarly, the Unsupported major.minor version 52.0 way your code is compiled using JDK 8 compiler together with you lot are trying to run it on lower JVM e.g. JDK seven or 7.

And, finally, the Unsupported major.minor version 51.0 way your code is compiled using JDK seven together with you lot are trying to run it on JRE vi or 5.

This fault volition non occur if you lot compile inwards JDK seven together with running inwards JDK 8 because Java is backward compatible but it won't operate otherwise because higher version mostly has features which are non supported past times lower version.

I convey written how practise deal with UnsupportedClassVersionError inwards past but today we'll focus on dealing alongside this fault inwards Eclipse. For example, if you lot are running your plan inwards Eclipse together with getting this fault than what should you lot do? Or how practise you lot solve this fault inwards Eclipse?

Before you lot solve this fault you lot postulate to empathise the Eclipse setup e.g. how your projection or Java classes are compiled together with how they are executed. When you lot practise a projection inwards Eclipse together with then you lot pick out a JRE, which is used for both compilation together with execution.

Btw, if you lot are novel to Eclipse IDE together with then I advise you lot to starting fourth dimension become through Beginners Eclipse Java IDE Training Course to larn basic features of Eclipse IDE.

But, you lot tin laissez passer on the sack alter the JRE for execution nether run configuration together with sometimes it also selection upwards the default JRE. That's where the work occurs. If you lot are using JDK 8 inwards your projection every bit shown below but if you lot are using whatever lower JRE nether run configuration together with then you lot volition acquire Unsupported major.minor version 52.0 Error inwards Eclipse.

In social club to solve this fault only purpose the JDK 8 or JDK 8 on Run configuration for your projection every bit shown below:


Solving Unsupported major.minor version 53.0, 52.00, 51.0 Error

Now to empathise this province of affairs better, let's practise this fault together with solve it. I convey a Java projection together with a Java shape together with my projection are configured to purpose the JDK 8 inwards construct path every bit shown below:

 The root drive of this fault is that your code is compiled using higher JDK version together with y Eclipse - Unsupported major.minor version 53.0, 52.00, 51.0 Error inwards Java


Now, only compile together with run the plan which creates a run configuration for it automatically alongside correct JRE version. The plan volition run fine.

Now, let's alter the JRE version inwards the Eclipse Run Configuration:

 The root drive of this fault is that your code is compiled using higher JDK version together with y Eclipse - Unsupported major.minor version 53.0, 52.00, 51.0 Error inwards Java


Now, if you lot run the same program, this fourth dimension it volition throw Unsupported major.minor version 52.0 error:

java.lang.UnsupportedClassVersionError: Demo : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:281)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
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:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception inwards thread "main"

Here is the screenshot from Eclipse IDE:


 The root drive of this fault is that your code is compiled using higher JDK version together with y Eclipse - Unsupported major.minor version 53.0, 52.00, 51.0 Error inwards Java


Bingo, this happens because instantly you lot are trying to run a Java plan which is compiled at higher JDK into lower JRE. When you lot compile, shape files are created which has major together with fry version depending upon which javac is used to practise them.

They tin laissez passer on the sack alone run on the same version of JRE or the higher version of JRE. If you lot run them inwards the lower version they volition throw this "java.lang.UnsupportedClassVersionError: Demo : Unsupported major.minor version 52.0" error.

In short:
1) If you lot acquire Unsupported major.minor version 53.0 Error together with then brand certain you lot convey JDK ix nether your run configuration inwards Eclipse.

2) If you lot acquire Unsupported major.minor version 52.0 Error together with then brand certain you lot convey JDK 8 nether your run configuration inwards Eclipse.

3) If you lot acquire Unsupported major.minor version 51.0 Error together with then brand certain you lot convey JDK seven on your run configuration inwards Eclipse.


That's all nearly how to solve the Unsupported major.minor version 53.0, 52.0, together with 51.0 Error inwards Eclipse IDE. Just banking concern check which JRE or JDK you lot are using for compiling together with running your Java program. You tin laissez passer on the sack banking concern check that within your construct path together with run configuration. Make certain you lot purpose same or higher version of JRE to run your plan together with then you lot used for compiling them. This volition solve this error. If you lot desire to larn to a greater extent than nearly Eclipse IDE itself, together with then become through  Beginners Eclipse Java IDE Training Course, i of the quick ways to larn Eclipse IDE.


Further Learning
The Complete Java MasterClass
Solution]
  • How to solve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error? (hint)
  • How to solve java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver? (solution)
  • java.sql.SQLServerException: The index 58 is out of arrive at - JDBC (solution)
  • How to solve java.lang.OutOfMemoryError: Java Heap Space inwards Eclipse, Tomcat? (solution)
  • How to ready "Error: Could non discovery or charge top dog class" inwards Eclipse? (guide)
  • How to avoid ConcurrentModificationException inwards Java? (tutorial)
  • How to ready Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger (solution)
  • How to ready 'javac' is non recognized every bit an internal or external command (solution)
  • How to connect to MySQL database inwards Java? (tutorial)
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory fault (solution)
  • Common reasons of java.lang.ArrayIndexOutOfBoundsException inwards Java? (solution)
  • java.lang.ClassNotFoundException : org.Springframework.Web.Context.ContextLoaderListener (solution)
  • Fixing java.lang.UnsupportedClassVersionError unsupported major.minor version 50.0 (solution)
  • How to solve "could non practise the Java virtual machine" fault inwards Java? (solution)
  • 10 mutual reasons for java.lang.NumberFormatException inwards Java? (tutorial)
  • How to ready "illegal start of expression" compile fourth dimension fault inwards Java? (tutorial)
  • Cause together with solution of "class, interface, or enum expected" compiler fault inwards Java? (fix)
  • How to solve "variable mightiness non convey initialized" compile-time fault inwards Java? (answer)

  • Thanks for reading this article, if you lot similar this article together with then delight portion alongside your friends together with colleagues too. If you lot convey whatever uncertainty or questions together with then delight drib a comment.

    Thursday, October 31, 2019

    A Consummate Conduct To Remote Debugging A Coffee Application Inwards Eclipse

    The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java developer, which is oftentimes croak the in conclusion too solely tool to investigate a põrnikas on a Java application running on remote host e.g. on Linux server or Windows server. Almost all major Java IDE provides remote debugging like NetBeans, Eclipse, too IntelliJ IDEA, but I to a greater extent than oftentimes than non usage Eclipse for Java coding too so it's my preferred tool to remote debug a Java program. In fellowship to fix remote debugging inward Eclipse, y'all demand to exercise a pair of tasks e.g. y'all demand to start your JVM amongst debugging parameters or arguments too and so y'all demand to create a "remote debug configuration" inward Eclipse IDE itself.

    I bring been sharing a lot of Eclipses tips too tricks inward this spider web log similar how to escaping JSON string inward Eclipse to easily create JSON for testing too debugging purpose.

    In this article, I'll non solely learn y'all how to fix remote debugging inward Eclipse past times walking through a measuring past times measuring guide but also learn y'all how to genuinely debug a Java programme running on a remote Linux server.

    I'll also tell y'all how to usage essential debugging commands e.g. Step Into, Step Over, too how to spotter variables spell debugging, which volition non solely helpful during remote debugging but also on during local debugging, right from Eclipse.

    Btw, earlier starting this tutorial, I await that y'all are familiar amongst both Java, JVM, too Eclipse IDE itself because when nosotros verbalise close Run too Debug configuration, y'all should empathize what nosotros are talking about.

    I'll demo y'all every measuring using the screenshot too explicate to y'all what nosotros are doing too why nosotros are doing but some basic cognition of Eclipse is required. If y'all don't know Eclipse or never used Eclipse before, y'all won't last able to empathize whatever I say.

    That's why, If y'all are consummate beginner too so I propose y'all to source croak through a comprehensive Java course of report similar The Java MasterClass and Beginners Eclipse Java IDE Training Course to acquire Java too Eclipse picayune chip improve earlier starting amongst remote debugging. That volition assistance y'all to usage Eclipse IDE effectively for Java development.





    3 Steps to remote debug a Java appliation inward Eclipse IDE

    1) Start JVM amongst debug arguments
    In fellowship to debug a Java application running on a remote host(Linus or Windowx), y'all source demand to start the JVM amongst debugging arguments, every bit shown past times next command:

    $ /oracle/jre/v1.6.0_18-64bit/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,address=11001,server=y,suspend=y -jar app.jar

    Though at that spot are dissimilar JVM options to start your JVM inward debug mode, depending upon which version of JRE y'all are using.

    If you're using Java 1.4 JRE too so y'all demand to use -Xdebug too -Xrunjdwp arguments. These options volition also move inward afterwards versions, but it volition run inward interpreted trend instead of JIT, which volition last slower.

    Btw, I genuinely promise Eclipse should bring something similar to IntelliJ IDEA which makes it piece of cake to retrieve the JVM debugging options every bit shown below:

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse

    From Java 5.0, it is improve to usage the -agentlib:jdwp every bit unmarried alternative e.g. :

    $ coffee -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=11001

    Options on -Xrunjdwp or agentlib:jdwp arguments are almost the same:

    transport=dt_socket: way the way used to connect to JVM (socket is a expert choice, it tin flame last used to debug a distant computer)

    address=11001: TCP/IP port exposed, to connect from the debugger,

    suspend=y: if 'y', tell the JVM to hold back until the debugger is attached to get down execution, otherwise (if 'n'), starts execution right away.

    If y'all are debugging for an lawsuit which happens during startup too so y'all tin flame usage the suspend="y" to croak through startup sequence measuring past times step. On the other hand, if the number is happening after it receives a message or asking too so y'all tin flame start amongst suspend="n" too connect it later. See Eclipse Debugging Techniques And Tricks for to a greater extent than of such tips.

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse


    2) Create a Remote Debug Configuration inward Eclipse IDE

    You also demand to create a remote debug configuration inward Eclipse IDE earlier y'all start debugging. In fellowship to exercise so, only follow steps:

    2.1) Go to debug configuration from Run carte du jour every bit shown below:

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse


    2.2) Go to remote Java application

    2.3) Configure details e.g. name, project, the Eclipse projection which contains the code of Java application y'all are trying to debug. Connection type should last "socket attach" too and so specify host too port inward Connection properties every bit shown below. Always specify a fully qualified domain advert for the host

    2.4) Hit apply after making change

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse


    You are done amongst setting upward remote debugging inward Eclipse. In the adjacent business office of this article, I'll demo y'all how to remote debug a Java application measuring past times step.



    How to remote debug Java Program inward Eclipse

    Once y'all are done amongst setting upward remote debugging inward Eclipse IDE, y'all tin flame follow these steps to start debugging your remote Java program:

    1. Setup a Breakpoint  inward Your Code

    In fellowship to start debugging, y'all source demand to fix breakpoint inward your code. You tin flame setup breakpoint at whatever business past times the only left click of mouse i.e. croak to your Java code too left click on whatever business where y'all desire to halt the JVM.

    This is also known every bit business breakpoint, btw, don't pose business breakpoint on empty lines. Also, if y'all are only starting amongst debugging, y'all tin flame start amongst putting a breakpoint inward the main() method which is the entry betoken of Java application.

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse


    2. Start JVM amongst Debug Arguments

    Before y'all launch your Eclipse remote debugging configuration, y'all demand to start the JVM on the remote host every bit shown inward next command:

    $ /oracle/jre/v1.6.0_18-64bit/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,address=11001,server=y,suspend=y -jar app.jar

    Influenza A virus subtype H5N1 pair of things to Federal Reserve annotation here, nosotros are starting JVM on server trend too asking it to suspend until the debugger connects it, which way it volition non start execution until y'all start your Eclipse IDE too launch remote debug.

    It is also listening for the debugger on port 11001, which way your Eclipse remote debugging setting should also usage the same port.

    Once y'all start the JVM, it volition impress the next business the log file or command line, depending upon where y'all are redirecting the output stream:

    Listening for carry dt_socket at address: 11001

    This way JVM is cook to attach the debugger too immediately it's fourth dimension to start remote debugging inward Eclipse IDE. Btw, if y'all are non familiar amongst Java Virtual machine too so I propose y'all croak through the JVM is non running too so it volition demo next error:

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse

    This fault way either your JVM is non running but if y'all are certain that JVM is indeed started too cook to connect too so possibly your host too port configuration is wrong e.g. whatever typo on fully qualified domain advert or whatever network number which preventing your local machine to connect to the remote host.

    If your Eclipse IDE is successful to flora a connection to debugger running on remote JVM too so Eclipse volition opened upward debug perspective too y'all could encounter where just JVM has stopped, a total stack describe starting from loading the classes.

    Now, y'all got the command of flying too it's upward to y'all how y'all move.

    When y'all source fourth dimension debugs a Java program, Eclipse volition enquire y'all opened upward the Debug Perspective too and so adjacent fourth dimension it volition automatically exercise so.

    Here is how Eclipse' Debug Perspective expression like:

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse


    In Debug Perspective, y'all bring a lot of debugging tools similar y'all tin flame execute code measuring past times step, tin flame encounter where y'all bring pose breakpoints, tin flame spotter values of variables too tin flame encounter which thread y'all are debugging too tin flame terminate the debugging session. The debug perspective is same for both local too remote debugging.


    4. Move Step past times Step inward your Java Code

    There are a pair of alternative to motion inward your code y'all tin flame usage either Step Into for measuring past times measuring executing code, which way if the code contains a method telephone telephone too so your code volition croak within a method too and so initialize variable too other code too finally come upward dorsum to where y'all were.

     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse

    Alternatively, y'all tin flame use Step Over to only croak over the method telephone telephone too motion to the novel line. You tin flame usage a combination of these 2 commands to effectively motion around interested read to expose whatever põrnikas or observer the output inward the log file. The push to Step Over is only adjacent to Step Into every bit seen inward in a higher house screenshot.

    5. Watch values of Variables

    While remote debugging your Java application y'all tin flame also encounter values of a local variable too fellow member variables into "Variables" window every bit shown inward the next screenshot.
     The remote debugging of Java programme is an ultimate tool inward the arsenal of a Java develop Influenza A virus subtype H5N1 consummate Guide to Remote debugging a Java application inward Eclipse

    This is real useful to expose out whatever inconsistency betwixt expected too actual values.  You tin flame also add together a variable to spotter window to periodically cheque its value.

    6. Terminate the JVM

    Once y'all are done amongst remote debugging too expose the root crusade of your occupation y'all tin flame terminate the remote Java application right from the Eclipse IDE. This volition halt the JVM every bit good Eclipse remote debug console, but if y'all don't desire to halt the JVM on remote host too so only click the disconnect push too it volition halt the debugging procedure inward Eclipse.


    That's all close how to setup remote debugging inward Eclipse IDE too how to remote debug a Java application running on Linux server. The cardinal is that y'all should bring the same version of a cast file too Java source file on both remote too local machine.

    If your Java source code is non inward sync amongst the cast file on remote host too so the debugging volition last inaccurate i.e. y'all volition laid a breakpoint at business five but your code volition last running business 10, therefore it is an absolute must that both code too binary running on the remote host must last of the same version.

    Further Reading
    Eclipse Debugging Techniques And Tricks
    Beginners Eclipse Java IDE Training Course
    Top thirty Eclipse keyboard shortcuts for Java Programmers
    10 Tips to debug a Java Program inward Eclipse
    3 Maven Eclipse Tips for Java Developers
    Git amongst GitHub Bootcamp & Integration amongst pop IDEs
    5 Free Courses to acquire Eclipse too JUnit
    10 Tips to croak a improve Java Developer
    10 Tools Every Java Developer Should Know

    Thanks for reading this article so far. If your similar this article too so delight portion amongst your friends too colleagues. If y'all bring whatever query or feedback or facing whatever occupation spell setting upward Eclipse for remote debugging too so delight drib a comment too I'll endeavor to assistance y'all out.