Eclipse JVM Version won't change - jvm

I need to get my eclipse install to use 1.7 update 51. I've installed both JRE and JDK's matching this version for 64 and 32 bit. If I change the vm in eclipse.ini I get an error code 1 saying eclipse cannot be started. If I change the compliance level in window -> preferences then it says that it's changed but after writing a simple application and running it in eclipse using RuntimeMXBean I'm being told 24.51-b03 is being used. I would assume this means update 51 is in use but my workspace is still complaining about major/minor version mismatches.
Any help/insight is appreciated
edit:
Here is the output of
public static void main(String[] args) {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
String jvmArgs = runtimeMXBean.getVmVersion();
System.out.println(runtimeMXBean.getSpecVersion() + " " + runtimeMXBean.getVmVersion());
}
1.7 24.51-b03

Figured it out, kinda. I built my jar with 1.7 update 51 and was using in a project with 1.7 update 51. No idea why it wasn't working, I just downgraded to 1.6 on the jar I built and it works.

Related

Attempting To Run Kotlin Project In IntelliJ Idea But Getting Bug Error

My Previous Question + More
I am trying to start learning Kotlin, and I have installed IntelliJ Idea from JetBrains, I really like the layout of the IDE, and so I don't really want to change it.
Whenever I try to run the program, I get the following error:
Could not open init generic class cache for initialization script 'C:\Users\Jacob\AppData\Local\Temp\wrapper_init1.gradle' (C:\Users\Jacob\.gradle\caches\6.6.1\scripts\9x7j38tmeo1ohlyu8452ntfdm).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 60
I know it's not the code, and since I am not very familiar with IntelliJ Idea or Kotlin, I have no idea where to start looking for the error or where to fix it...
Someone said that this question's answers were the solution, but I looked their, tried what it shows, but still found now solution for my situation... When I follow what they say, I get the same error.
Someone please help!!! 😁
I created instruction:
Install JDK (for example Oracle JDK 14)
Open project folder with build.gradle and settings.gradle in Idea
Add JDK to project: press F4 on left Project Tool -> SDk -> Add -> Apply
Set new SDK to project: press F4 on left Project Tool -> Project -> Project SDK -> Set new SDK -> OK
Set new SDK to Gradle Build Tool: press Ctrl + Alt + S -> Find gradle in search -> Go to Gradle JVM -> Set new SDK -> OK
Create new directory src/main/kotlin/main.kt with code
fun main() {
val jdk = System.getProperty("java.version")
println("Using JDK: $jdk")
}
Go to main.kt in Editor and press Ctrl + Shift + F10 and you must see your JDK version in console like: Using JDK: 14.0.2
Take a look sample project

Can't get kotlin "hello world" example to Run in intelliJ

I'm following the intelliJ IDEA tutorial titled Create your first Kotlin application
(Last modified: 08 March 2021). Here are the various versions I'm using:
~$ java -version
java version "16" 2021-03-16
Java(TM) SE Runtime Environment (build 16+36-2231)
Java HotSpot(TM) 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
~$ javac -version
javac 16
Here's my code:
fun main(args: Array<String>) {
println("What is your name?")
val name = readLine()
println("Hello $name")
}
Here's what my project structure looks like:
I notice that it says "Kotlin not configured" above my code, but when I go to Tools > Kotlin > Configure Kotlin in Project, I get
:
In the Event Log pane, I see this:
4/15/21
1:54 PM Download pre-built shared indexes
Reduce the indexing time and CPU load with pre-built JDK shared indexes
Always download
Download once
Don't show again
Configure...
1:54 PM Gradle sync started
1:54 PM Gradle sync failed: Unsupported class file major version 60 (5 s 329 ms)
1:55 PM No IDE or plugin updates available
In the Problems(?) pane, I see this:
Unresolved reference: println
Unresolved reference: readLine
Unresolved reference: println
Parameter 'args' is never used
Package directive doesn't match file location
Any ideas on why the basic functions in my program are not recognized?
Thanks for looking!
Edit: I tried downloading JDK 15 and specifying that in my Project Structure, but I got the same results:
try build>clean project.
As for your unresolved references, you can double-click/left-click > show context options. If that doesn't work then maybe reinstall InteliJ Idea or download Android Studio which has a lot more support on google and yt.
Okay, I got it working. I'll try to figure out what I did.
tldr; I had to switch from JDK 16 to JDK 15 to get my hello world console application to run.
First, when I was setting up the project, I chose the wrong Project Template: I selected JVM - Application rather than JVM - Console Application. This is what I needed to do:
So, I started a new project, chose the right template, and I typed in my code, and I noticed a Build pane at the bottom left displayed:
I tried Build > Build Project, and nothing changed. So, I tried the Run menu item: the first section of the Run menu was grayed out, but there was another Run command in the second section of the Run menu. I selected that Run, and a little window popped up with the following:
Run
0 Edit Configurations
The "0 Edit Configurations" line was highlighted, and I got nowhere trying to figure out how to Run my code.
So, I started yet another new project, and this time I selected a different JDK, version 15:
After clicking Next, then Finish, I typed in my code, and this time the Build pane looked like the following (without me doing anything but typing in my code):
After I finished typing in my code, as the tutorial described, this time there was a little green arrow in the gutter:
When I clicked on the green arrow in the gutter, I could successfully Run my program.
So, it appears that you cannot use JDK 16, and you have to use JDK 15. intelliJ was able to detect all my installed Java versions, so any version you have installed should appear as a choice in the the project settings. You may have to quit intelliJ, then restart intelliJ after you install JDK 15 in order to see it listed as a choice under Project JDK: when you create a project.

Simple Intellij Kotlin project doesn't recognize LinkedHashMap or other collections

I installed the latest version of Intellij on Linux (2019.2.3 Community Edition) and added the Kotlin plugin.
I followed the Kotlin website's Getting Started with IntelliJ IDEA and created a hello world app. It worked fine until I added a LinkedHashMap. (BTW, I was running into this in a bigger project, but simplified it to this.)
This is all the code I added:
import kotlin.collections.LinkedHashMap
fun main(args:Array<String>) {
println("Hello world")
val map: LinkedHashMap<Int, String> = linkedMapOf(1 to "x", 2 to "y", -1 to "zz")
println(map)
}
I get this error on the map line:
Cannot access class 'java.util.LinkedHashMap'. Check your module classpath for missing or conflicting dependencies.
You can see I have 1.8 selected in the modules, and I verified java 8 is installed via terminal (java -version). What is the issue for this vanilla/default installation?
Ok, so I figured it out. For some reason, if I change the module to 11 (java 11) from 1.8 it just works.
Kind of weird that standard collections don't work out of the box, but... eh, I guess this works.

IntelliJ Error:java: java.lang.ExceptionInInitializerError

Every time I encounter this exception in IntelliJ, I fix it trivially and forget the fix easily.
Code:
package whatever;
import org.junit.Test;
public class TestClass
{
#Test
void test() {}
}
Scenario:
Add new TestClass.
Right-click TestClass.
Select "Run 'TestClass'" to run test cases.
The "Messages Build" pane shows:
Information:javac 9-ea was used to compile java sources
Information:Module "dummy" was fully rebuilt due to project configuration/dependencies changes
Information:8/16/17 11:35 PM - Compilation completed with 1 error and 0 warnings in 1s 663ms
Error:java: java.lang.ExceptionInInitializerError
What can possibly go wrong?
What are the likely issues in this simple scenario?
IntelliJ: COMMUNITY 2017.1 (idea-IC-171.4424.56)
To fix the issue, I do:
File -> Project Structure... -> Project Settings / Project -> Project SDK.
Change from "9-ea" to "1.8".
DETAILS
Apparently, the issue is discrepancies in selected JDK-s to build (java 9) and run (java 8).
I'm not sure how "9-ea" gets re-selected there for the same project - neither IntelliJ itself runs in "9-ea" JRE (according to Help -> About) nor JAVA_HOME env var is set to it nor other possible settings (like Maven -> Runner) suggest any "9-ea".
I also didn't manage to run the test under the same JDK (java 9) which it gets compiled under. However, it's unclear what JDK tests are run under because IntelliJ reports only about JDK for compilation.
If you use Lombok: For me it was a solution to set the newest version for my maven lombok dependency in the pom.xml.
*<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.8</version>
</dependency>*
I was facing same error when i tried to run my application in IntelliJ-2019.2 version. Below are the steps i followed to resolve this issue.
Versions:
IntelliJ : IDEA-IntelliJ-2019.2
Java : jdk1.8_221
Go to below path in IntelliJ
File -> Project Structure -> Project -> Project SDK -> (select java version which you want to use )
(In my case under 'project SDK' java-11 was selected, I changed it to 'java8')
Click on 'Apply' and then 'OK'.
I feel I ran into this issue because IntelliJ was trying to compile my java classes using in-built java-11 whereas my java classes are built on java-8. So when i explicitly configured java-8 in IntelliJ, It worked!! Hope this helps.
I started seeing this exception once I installed Java 11 in my machine. JAVA_HOME was by default pointing to Java 11 and my project was still in Java 8. Changing JAVA_HOME to Java 8 jdk fixed the issue for me.
If you have multiple projects each running on a different JDK, use this command to temporarily change the Java version per command.
JAVA_HOME=/path/to/JVM/jdk/Home mvn clean install
If you have recently updated your IDE then you can try these steps.
Delete .idea directory for the idea project/workspace
Then go to File -> Invalidate Caches / Restart...
Once Idea is restarted re-add/import your module(s)
I faced a similar issue with JARs and Jena (while run from IntelliJ it works).
I was using Apache Jena v4.0.0 in my project and have built a JAR (with a main class for the JAR to act as a console app).
The JAR builts successfully with IntelliJ but when run throws java.lang.ExceptionInInitializerError ... Caused by: java.lang.NullPointerException. NPE suggests that something was not initialized properly.
The jar built with previous version Jena 3.17.0 works perfectly.
What I did to fix it
I've opened both the JARs, compared their META-INF folders and encountered the difference in
my.jar\META-INF\services\org.apache.jena.sys.JenaSubsystemLifecycle
The new version (jena v4.0.0) contains only one line:
org.apache.jena.tdb.sys.InitTDB
The old version (jena v3.17.0) contains two different lines:
org.apache.jena.riot.system.InitRIOT
org.apache.jena.sparql.system.InitARQ
I've added the old two lines to the file and repacked new JAR with it:
org.apache.jena.tdb.sys.InitTDB
org.apache.jena.riot.system.InitRIOT
org.apache.jena.sparql.system.InitARQ
It resolved my issue.
Update: recent Jena v4.4.0 builts with the same "bug".
I'm not an expert and there is probably a better way than patching a JAR by hand.
But I still hope that this solution will help someone like me.

Kotlin - Error: Could not find or load main class _DefaultPackage

I followed the Kotlin tutorial for eclipse here : Getting Started With Eclipse Luna
However, I'm running into this error:
Error: Could not find or load main class _DefaultPackage
Anyone who knows to get around this?
This was a severe bug (KT-10221) in automatic generation of Launch Configuration in plugin version 0.4.0. It was fixed in 0.5.0 so the recommendend way to workaround is to update plugin.
The source of the problem was that the plugin used an old pattern for generating name of the class for main function that had been abandoned by Kotlin compiler.
It's possible to workaround it by editing launch configuration (Eclipse Menu -> Run -> Run Configurations...) by hand and changing Main class field in Java Application group. If the file is named hello.kt with no package directive, as it is described in tutorial, than corrected string should be HelloKt.
If file has name other.kt with package my.tutorial than the Main Class should contain my.tutorial.HelloKt. You can read more about it in the section Package-Level Functions of Calling Kotlin From Java page.
I have been getting the same issue. And after putting the right compiler output path, it got resolved.
Go to Project -> Project Compiler output :
In the text box, fill this:
[Absolute Path]/{Project Name}/out
In my case I was having this problem while trying to run the program using the Application Gradle plugin. The problem was in the mainClassName property using single quotes instead of double ones
This didn't work:
mainClassName = 'demo.HelloWorldKt'
With double quotes, it works:
mainClassName = "demo.HelloWorldKt"
For me it worked after I installed the correct JDK. I first had JDK 11 but the tutorial I did was with JDK 8 so after I installed this and set it in the "installed JREs" options it found the main class without having any "mainClassName" or any other option in the build.gradle file.
For me, it worked in a fresh eclipse workspace. Possibly, the Kotlin eclipse plugin is not playing well with other plugins (in my case, PyDev).
I'm creating a Kotlin Application with JavaFX and I had this issue until I went to:
Run > Run Configurations > Java Application > Common
I unticked "Allocate console" and it fixed the issue.