Program compiles fine in javac but not in IntelliJ - intellij-idea

I am trying to test a java library I found online. I'm testing each component separately, and they work correctly on the command line when I do javac *.java followed by java test. This works perfectly fine, but if I try to build the same test.java file in IntelliJ 2017, it seems to build other irrelevant source files also present in the project and fails since they require dependencies that are not present (but I just want to compile and run test.java.)
How can I resolve this?

I don't know anything about the library you are using, so this may or may not work for you...
In the Project panel of Intellij IDEA select the class of the *.java file you want to compile/run.
Right-click, and on the popup menu you should see a couple of entries that look something like this:
Recompile 'Test.java' (That entry may or may not be present.)
Run 'Test.main()' (That entry will be present as long as you have a main() method.)
See the screen shot below for clarification.
Do you see similar entries?...
If so, what happens when you select them?
If not, please update the OP with more information on the error you are getting.

Related

Grails commands under Idea fail with a "NoSuchMethodError" for "getAndPut" in the "EvictableCache" class

I'm trying to get an existing project working on a new platform (MacOS, M1) with Idea as the IDE. (I'm extremely new to Idea, but I'm getting help from other project developers.)
For a particular module in the project, any attempt to run pretty much any Grails command fails with an exception:
org.codehaus.groovy.runtime.memoize.EvictableCache.getAndPut(Ljava/lang/Object;Lorg/codehaus/groovy/runtime/memoize/MemoizeCache$ValueProvider;)Ljava/lang/Object
I have verified (to the extent I know how) that there's only one Groovy installation on the machine, and it's version 2.4.14 installed by sdkman. (Grails is 2.5.6.) Running the grails command as part of the Idea build (ie, from clicking "Build" or whatever inside the IDE) and running the grails command in the module top-level directory from the command line have exactly the same results.
I don't have much (well, any) experience with grails or groovy, but to me a "NoSuchMethodError" means that some piece of code was compiled against a different version of that class (EvictableCache) than the version that's actually in the jar file when grails runs. There are groovy .jar files in the project directory, but their presence seems to make no difference; it always gets that exception.
I'm using the Azul zulu8 JDK, downloaded from Azul directly. Formerly I had been using a version installed with brew but that made no difference.
Any ideas as to how to locate the .class file with the attempted call to getAndPut() in EvictableCache would be welcome.
edit — as I was looking at the stack traces from running a command, I noticed something. Again, my groovy is 2.4.14, as I can verify with groovy -version. At the top of one of my stack traces (maybe more than one) I see that the attempted call to getAndPut() is coming from a class called AbstractExtensionMethodCache. Well, as far as I can tell, that class did not become part of Groovy until version 3. So clearly something is messed up.

where is com.intellij.rt.junit.junitstarter

i use intellij with junit to run tests (new), when i debug my test code for practice, one of the very first lines of code that seems to run is some method called main from package called com.intellij.rt.junit. I've tried clicking on it as well as searching for it open that package or class to see what's inside but i can't find it all. anyone know what it is or where i could find it in intellij and why i can't just access it from the debugger like every other class? i have junit 5.8 installed in maven.
y.bedrov's analysis is quite right.
com.intellij.rt.junit.JUnitStarter is part of IDE. In your case, the IDE is IntelliJ IDEA. You may find the source code in this local path:
/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar
then import the jar package into your own project to read the source code conveniently.

Coroutines working but IntelliJ shows errors

I am working on a project using kotlinjs for nodejs and I start to learn coroutines and integrate them into my code to say goodbye to the callback hell.
I managed to get coroutines working, my code can be compiled and executed, everything seems fine.
...except: The IDE still shows me errors. It seems to be confused by the additional libraries I added in order to get coroutines running.
I am currently fiddling around with the library dependencies, sometimes some errors go away, but then some code gets red which was okay before...
This is what I see:
Case 1:
Cannot access class 'kotlinx.coroutines.experimental.CoroutineContext'. Check your module classpath for missing or conflicting dependencies
Case 2:
Unresolved reference: JsModule
Modifier 'external' is not applicable to 'class'
You see, launch is recognized when I add the stdlib, but then the IDE complains with the other two errors.
Again, please note: In both cases, actual compilation is successful!
I am using IntelliJ 2018.1 with Kotlin Plugin 1.2.41.
Thanks to Alexander Chernikov at youtrack.jetbrains I could resolve my problem.
I cite his explanation:
The issue is that JavaScript libraries should be marked with special attribute to be recognized.
When they are imported from pom.xml or build.gradle, this mark is set, so the feature works.
In your project they are not marked.
At the moment, to correct the libs manually, please open .idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_js_1_2_41.xml and .idea/libraries/org_jetbrains_kotlinx_kotlinx_coroutines_core_js_0_22_5.xml.
In both files find type="repository" and replace it with type="kotlin.js".
Make sure IDEA sees the change. (You can exit IDEA, make the change and restart.)
Then you can keep only these two libs in dependencies. The editor should work.
Here is the issue link:
https://youtrack.jetbrains.com/issue/KT-24575
There I have also attached a sample project with the problem.

Did something Change with Pycharm 2016.3.2 - UnitTests no longer auto discovered

I have upgraded my Community version of PyCharm to 2016.3.2, and I'm not positive it was this exact version, but when I went to run files that had unittests in them, only some of them are recognized as UnitTests that I can right click and run.
I have looked to make sure that my classes implement unittest.TestCase
class clWorkflowWebClientTest(unittest.TestCase):
all of my tests begin with test_blahblah()
If I go into Edit Configurations and add one manually, I can right click and run it from the project tree, and it runs as a UnitTest. But I don't get the "Run UnitTests in Blah' dialog when I right click the file.
This turned out to be an issue I caused myself. we had added a folder called 'UnitTest' and introducing this to the path caused issues with PyCharm knowing what was a true UnitTest file.
I still don't know exactly what caused some files to work, but there appears to be one method in those files that did work that was probably being imported from another file that had the proper pathing.

pydev: undefined variable error when importing compiled modules

I want to switch my python-IDE from idle to pydev (eclipse). I am using a couple of modules which I have as compiled bytecode (*.pyc) only. In idle that was never a problem and it even offers code completion for those compiled modules. But pydev gives me a lot of "undefined variable" errors - however the code is interpreted correctly.
Is there a way pydev can handle bytecode modules the way idle does? Perhaps without decompiling the files?
Try adding the modules as forced builtins.
To do that, go into Settings → PyDev → Interpreter - (Python/Jython/IronPython as approriate), select the interpeter you're using, and add it to the list on the Forced Builtins tab (look here for more details).
(Note that you may or may not have to add multiple entries for subpackages and modules; for example to get Fabric working properly one needs to add both fabric and fabric.api)
That makes PyDev load those modules into an interpreter to get code-completion and error checking data, rather than just analysing source code.
I've not tried it for .pyc files, but it works for other things like importing something that's generated dynamically by a script's __init__.py or something (ie fabric) so it might work for you.
(see also this FAQ and that one on the PyDev site)