Issue about Intellij IDEA with scala - java

I have a scala project but I don't know how to run it :
This is an java project and it has a button in main Method line:
my project is this :
what should I do to find the button to run my scala program
there is no run button

As I cannot comment, I will write here: you must point the scala class and right click on it, and then you have the Run. In the pictures you are trying to run the java class

Few things:
a) Check to make sure, your source directory is included as module
i.e. File > Project Structure. In the attachment below you see my modules
b) Check to make sure you have included your scala library, I believe you have this setup.
c) Last resort, see if you can add your object as Application
i.e. Run > Edit Configuration & the following
Hope this helps, enjoy!

You need a scala plugin to run a scala file. And find more at the get started documentation of idea.

Related

IntelliJ IDEA is not recognizing my java files as runnable and instead wants to run the class files. Any ideas of how to fix?

Anytime I try to run a java file by clicking run, it instead tries to run the class file and thus gives a no main method error.
When I try to right click on a java file and run that, it doesn't recogize it as a file that is runable.
I am still able to run programs from the command prompt but I would prefer to be able to run them in IntelliJ.
This occurred after trying to create a Class path when using JSon Libraries.
Edit:
Normally it shows java files with this icon:
But instead it's showing this icon for java files:
I think the change in icon might have something to do with it.
Edit 2:
the exact error I get is "C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe"...bunch of other program file locations
Error: Could not find or load main class sample.Main
Process finished with exit code 1
I had the same problem and found out that my src wasn't marked as Sources Root. To change this:
right-mouse click on your src
navigate to "Mark Directory As"
choose "Sources Root"
It will now recognize your files correctly and your main classes will be able to run again
IntelliJ not recognizing my .java-files
Problem solved
I had a similar problem.It wouldn't pick up ModlServer in any project. (Not just limited to the one I had open).
I had to file -> Manage IDE Settings -> Restore Default Settings
Note: I lost all my live templates, fonts, etc so just a heads up.
I restarted my computer and that somehow fixed it.
My issue was that I have multiple modules for my project and the module I was working on (where java files were not recognized) was not included in the main pom. I just added that module in the main (project) pom and it worked.
Right click on the project and click 'Add framework support' all directories and classes should now be the right type.
I've fixed this at Intelij2023 by using JDK17 as the JDK the IDE uses to import java source files.
Mind this JDK version does not need to be the same you use to build your project.
Go to: Settings > Build, Executio, Deployment> Build Tools > Maven > Importer
Set the JDK For Importer to zulu-17
I'm using zulu-17 as JDK for imports and coretto-8 to build the project (having JDK version 8 seems to be preventing intelij to properly recognize the project structure)
If you are using Maven or Gradle, try to re-import the project and see if that helps. Could be that your IDEA project has some incorrect settings in it set by mistake, so this way those would be removed.

Jcabi Github ExceptionInInitializerError

I am currently working on a Bukkit plugin, and trying to implement to get config files from github. I am trying to use JCabi-Github for this. I got the library implemented and working, but whenever I use it, it creates an error. I tried to use this code:
Github git = new RtGitHub(user, pass);
Which doesn't give any compile-time errors
And following the Javadoc should be just right
But when it runs, it creates a java.lang.ExceptionInInitializerError.
How do I fix this?
Check how you are using your program with JCabi-GitHub.
See issue 1270:
I'm afraid that "compile via eclipse" is what broke the structure of the JAR file.
Try to package with Maven.
The problem is not only "compile via eclipse". There's a bug in the library: it reads some attributes from its Manifest.MF, which may be problematic when you package your app in a .war, for instance.
There is an open ticket to change this mechanism; until then, the best solution is to:
1) use Maven to build and package your app
2) use maven-assembly-plugin to hardcode the needed values into your final artifact's Manifest.MF.
See here: https://github.com/jcabi/jcabi-github/issues/1198#issuecomment-225122003

Scala IDE Error -could not find/load main class

I am using Scala IDE 4.4.1.,using the jdk 8.When I try to run a scala program ,getting the error "Error: Could not find or load main class example.Credit" .
I was stuck with the same error a few days ago. In my case, it was an incompatibility of my JDK and the selected target JVM for my Scala project.
To check your current Java version, run java -version on the command line. To check your project JVM target in Eclipse, go to "Project > Properties > Scala Compiler" and check the target JVM (choose the same version as your current Java).
Hope it helps.
You should write object instead of class
I was having the same problem so that is how I came to this link & would like to share my findings. In my case I found that incompatible jars where present due to it was throwing error. After providing correct jar issue was resolved.
I used Scala for Eclipse IDE,
The solution for this could be right click on project and select scala -> Set the Scala Installation, will set the scala path to this project and rebuild the same.
Hope this helps you.
If the above mentioned solutions are already configured in your system and still getting this error then consider reading my answer. When incompatible scala jars are referenced by projects, a red cross mark is shown at project level and no errors are shown in scala files. In this situation scala code doesnt compile and when executed shows the message "error could not find or load main class scala". Best solution is to go to the scala installation folder and to check if the jar is present there, if present then reference it else reference jar files that do not show error (red mark) at project level or at source code.

Using custom Java classes in Clojure REPL

In Eclipse, using the CCW plug-in, I want to load a clojure file into a REPL. The problem is that I have an import statement for one of my own java classes, but apparently it is not in my classpath.
(ns my-clj-ns
(:import [alg.gen Enumerator]))
Do I have to make jars out of every class that I want use/test in a Clojure REPL?
Currently, trying to load my clj into a REPL results in an error:
"Load file in Clojure REPL" did not complete normally. Please see the log for more information.
java.lang.NullPointerException
Any help would be greatly appreciated.
You can let leiningen compile these for you using,
:javac-options {:destdir "classes/"}
:java-source-path "src/main/java" ; location of Java source
options or manually compile them and move the class files to the classes/ directory. No need to create a jar.
When you're in the ccw repl, you can hit alt-e to see the stack trace. If you're getting a NullPointerException, I don't think its a classpath issue.
Your code looks fine to me.
I suspect the issue is with your Eclipse Java Build Path, which determines what Eclipse includes in the classpath for your application.
In particular, if your Java class is in a separate project, you will need to either add that project to the build path (right click on project / Properties / Java Build Path / Projects) or package it as a jar.
When you start to have more sophisticated build requirements, you may also want to start looking at Maven to handle this kind of thing for you. Maven is a pain to learn / set up in the first place but it pays of in the long run.
Leiningen is also a great tool to use but I personally don't use it for the following reasons:
It is great on the command line, but doesn't integrate so nicely with an Eclipse workflow
Maven is more widely used and better supported in the Java world
There is really nice guide if you want to learn how to do this.
https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md
But in gist, have a project definition like the following for Java source code.
(defproject megacorp/superservice "1.0.0-SNAPSHOT"
:description "A Clojure project with a little bit of Java sprinkled here and there"
:source-paths ["src/clojure"]
:java-source-paths ["src/java"])

Implement Growl in Java Application

I want my Java application to make a growl notification. My IDEs are Eclipse and Netbeans, and I am trying to implement a library in either (so far it worked it neither). How can I just add the library to my project and then reference the classes from within my own classes? Moreover, where can I find an appropriate library?
Thanks in advance!
EDIT: Ok, now I have somehow managed to implement the library ^^ However: the following command fails:
System.loadLibrary("growl");
It returns following error:
Message: no growl in java.library.path
How can I fix this?
About an appropriate library you should just google it. I found this one (that is tested on 10.5 so maybe it will need some tweaks): http://www.cocoaforge.com/viewtopic.php?f=6&t=17320
To add the library to your project in Eclipse copy it into the project folder (this is not necessary, you could just copy it wherever you want, also in extension folder of the JDK) and then add it through the project settings:
open project properties by right clicking the project and choosing Properties
go to Java Build Path option
go to Libraries and add it
It's possible to use AppleScript script engine in Java 6 on OS X to communicate with Growl. Here's a blog post describing how to do it.
You can use the network binding like in https://github.com/chamerling/JavaGrowl or https://github.com/aerofs/growljavabindings
Maybe this can help you.
If your classes are packaged in a JAR file, just like a 3rd party library, you should be able to put it in your project /lib directory and add it to the CLASSPATH using the IDE. That should be all you have to do (if I understand your question correctly).

Categories

Resources