When running a project plugin I want to execute a simple method (eg: System.out.println), so how where can I do this?
What I'm trying to do is create a project plugin with an activator class and insert inside the Activator constructor the method System.out.println but it is not working.
If you want something to run during the Eclipse start use the org.eclipse.ui.startup extension point:
<extension point="org.eclipse.ui.startup">
<startup class="example.StartupClass"/>
</extension>
where StartupClass implements org.eclipse.ui.IStartup
Related
I have two projects. One of them is projectA a processor for annotations. Second one, projectB use projectA as dependency. Now this processor is add toJson method to exists class before final compile. Everything works normally. When I compile projectB my projectA is run and modify exists source file and add toJson method. Also intellij auto detect this processor and automatically configure my custom processor to the processor path. But editor give error Cannot resolve method 'toJson' in 'CacheData'. How I can solve this problem?
The below image is my intellij configuration. As you see IDEA automatically detect my processor from my pom.xml but editor does not recognize the generated code
I use IntelliJ IDEA 2021.3 (Ultimate Edition), maven-3.8.1, jdk-1.8 for processor(projectA) and jdk-11 for projectB
Finally I solved my problem. It seems that current version of Intellij only supported auto generated class. But if you modify exist file with you annotation processor Intellij editor can not recognize your changes and shows as errors. Thank you very much to #mplushnikov for his lombok-intellij-plugin. I just create my own plugin for IntellIJ and add dependence. After doing this you need to override some entrance classes and add your own annotation and its processor handler and extends it from AbstractClassProcessor
Let me share some example so if anyone who has this problem can use it.
IntellIJ Plugin tutorial for beginner
The below code snippets are from my plugin.xml. First you need add some dependencies to your plugin
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.java</depends>
<depends>Lombook Plugin</depends> <!-- this is the lombok-intellij-plugin-->
Second step is adding required extensions to your plugin as below
<extensions defaultExtensionNs="com.intellij">
<!-- Add your own custom processor. because lombok plugin default search only lombok package and own annotations -->
<lang.psiAugmentProvider implementation="your_package.AugmentProviderImpl"/>
<!-- if you packaged your classes other than lombok -->
<codeInsight.externalLibraryResolver implementation="your_package.ExternalLibraryImpl"/>
<implicitUsageProvider implementation="your_package. ImplicitUsageProviderImpl"/>
<!-- Add your custom annotation processor handler and extend it from AbstractClassProcessor -->
<applicationService serviceImplementation="your_package.CustomAnnotationProcessor"/>
</extensions>
Thats it. Follow these steps, build your plugin and install it. After restart your class's methods which is generated by your own annotation will be recognized by intellij.
Implementing the class is not hard. Just look the lombok-intellij-plugin source code and copy the required file and just modified it.
I have a Mac (Catalina OS) with Java 15 and IntelliJ 2020.2 (community edition) installed. The kotlin plugin is also installed. When I create a new Kotlin Project, add a main function, then there is way to run it, there is no 'Start' Button next to the main function. The problem is obviously that it doesn't find the runtime. The iml file looks as follows
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
When I click on 'add framework support', I can add a new KotlinJavaRuntime which then just appends an <orderEntry> to the iml file with the name KotlinJavaRuntime (2).
I don't want to use maven or gradle here. I know that gradle can resolve the dependencies for me. I just want a plain vanilla Kotlin hello world project. The documentation has a 'Getting Started with IntelliJ IDEA' section which just mentions the Kotlin plugin for IntelliJ. There seems to be no requirement to have gradle or maven installed, the plugin should do it.
I know that you can use brew install kotlin to install the SDK manually, but then the documentation is wrong and the plugin alone cannot run Kotlin with a prior manual installation of the SDK or the usage of maven/gradle.
I think I know what happened in this case.
The Kotlin Code was loaded as an 'IntelliJ' Module inside a Java project that was using maven. In IntelliJ there's a hidden folder .idea/libraries/ which was missing the description of the Kotlin Runtime (this makes sense, since the dependencies were managed via maven). I have restarted and created a new project from scratch. This time you'll see the file .idea/libraries/KotlinJavaRuntime.xml, which is exactly what is referenced from the iml file. The .idea folder is very magic. For me the confusion is that modules in IntelliJ are not really isolated from the project, they share - like in this case - the .idea folder.
I hope this helps also other users.
If you created the kotlin-file yourself, you have to tell IntelliJ that it should run this file.
Normally shows a run icon next to your main method.
run button/icon
Option 2: Right Click on the file containing the main method and see if there is a run this file option.
Option 3: add run config manually
Click add config which should be on the left of the run button (don't mind that it is disabled)
Click + and choose Kotlin.
Set main class to MainKt which is the default for kotlin
I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!
I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!
I'd like to generate the intellij project files from a typesafe activator project via a script - is there a command line interface or command i can use for this purpose?
(i wasn't able to find directions for one online, or in the usual help locations)
Please note that since IntelliJ IDEA version 13 it is no longer necessary to generate files for IntelliJ IDEA. sbt support is now build in, you can open/import the project by opening your build.sbt with IntelliJ IDEA: http://blog.jetbrains.com/scala/2013/11/18/built-in-sbt-support-in-intellij-idea-13/
Remember that Activator is just an sbt wrapper with optional UI mode. So what you want is sbt-idea:
https://github.com/mpeltonen/sbt-idea
The Activator UI will auto-add this plugin and then (on the Code tab) it has an "open in" menu item to generate the intellij project.
If you want to script it, there are two steps:
add the plugin (either drop an idea.sbt in project/ directory or put it globally in ~/.sbt/0.13/plugins)
run activator gen-idea