A friend is just starting to learn Java, using IntelliJ.
He asks how can he set up some template so creating a new project will contain a default main class.
Currently, when he creates a new project, it has no source files, and he has to add a Run/Debug application configuration manually, and then select the main class.
I don't know if Settings->File Templates is what you have in mind, but I'll point it out just in case.
You can easily create a class and add a main method by typing "psvm " and filling in the method body. You run it by right clicking on the class and selecting "Run". It's automatically be added to your Run/Config list, you just have to save it to make it permanent.
But my gut feeling is that IntelliJ has no such a feature for reading somebody's mind about a "default main class", nor should it.
In the resources tree, right click on the class you want to be main and there should be item in the context menu like "Create main for xyz".
Related
My friend and I both have IntelliJ and just want to run plain old java. Every time I make a new java class, I can automatically run it. The configurations just work.
When my friend wants to run it, he has to go to edit configurations and type in the class name. We went through the exact same setup. How do we make it automatically the main function in the class?
Friend's
MINE Macbook Pro
When you're in a java file that contains a public static final void main(String[] arg) method you can press Ctrl+Shift+F10 to make and run a temporary run configuration for the current class. This can save a bit of time when setting up the configurations.
Alternatively you can try to share the .idea directory with him, as it contains all of the project's settings. I'm not sure what other options will be shared though.
it's easy, Your friend must do this and this setting is changed in the "Default Project Structure..." dialog. Navigate to "File" -> "Other Settings" -> "Default Project Structure...".
Next, modify the "Project language level" setting to your desired language level.
IntelliJ IDEA 12 had this setting in "Template Project Structure..." instead of "Default Project Structure..."
Creating files in the src(source folder) where the jvm expects to find the java classes instead of creating them in the project root folder helped solve the problem for me.
I am having problems setting up Java Compiler for Visual Studio and keep getting this error. I am using Visual Studio 2015 and the latest version of JDK. I downloaded the Java extension from here.
What could be the cause, how do I solve this problem?
Thank you for your time.
This is the answer that nerdyguy64 said in a forum , This ONE work for ME .....
".. I had this same problem but I figured it out.
Do what it says, go into the Debug tab and then go down and click "'PROJECT_NAME_HERE' Properties"
Then click the "Debug" tab on the side and then you will see "Start Class within project:" radio button. Make sure it is clicked and then in the text field along side it type in the class name that has you main method in it.
Remember, if your main method is within a package you must type the package name then forward slash ("/") and then your class name (with the main method).
For example: if you start a new console application, you should get a basic hello world console application. Since the basic console hello world application has the main method class in a package (called "pkg"), you have to put in the "Start Class within project" field: "pkg/Program"
It's simple. If your main method is in Class1.java file.
You go to properties of your project, go to debug tab, and set "Start class within project" as "YourProjectName/Class1". (Your project name is where the Class1.java is located.)
In vs2015, like hbrtxito says, just set 'pkg/Program' in PropertiesDebug->Start action -> Start class within project
This is not a code-related, but a pure IDE work efficiency question.
Is there any Eclipse plugin or built-in feature to provide "links" (shortcuts) to open other relevant .java files in the current project (or any files for that matter) from within a file.
To be more specific, here is an example of what I want to do:
I added new functionality to a class called MyClass in my project.
I also have a unit test file for that class called MyClassTest within another "test" project under a parent project.
Now I want to jump to MyClassTest.java and add new unit tests.
I'm lazy so I don't want to browse with the mouse in the Project Explorer (too many packages) and don't want to press Ctrl+Shift+T and type the class name.
I want some sort of shortcut planted in MyClass.java (or even a side panel window) which when clicked, opens MyClassTest.java for me.
This can be useful for the programmer to "link" related files (.xml, .java, .jsp) so he/she can open them quicker.
The MoreUnit plugin solves exactly this problem for unit tests. You press Ctrl-J while in a class to jump to its test class (and vice versa).
It even simplifies the process of creating the test class in the first place, with naming conventions and method stubs.
Typically in your described scenario I will right click on the "MyClass" (the text name in source) and go "References -> Workspace". This will show me all other "related" classes referring to MyClass. I can then double click on any of them to open which have appeared in the bottom search tab.
This also works great on methods to find out who is using the method in a particular class.
You can make the "Open type" dialog work more easily in this case, if you have selected the name of the current class before opening the dialog. Your current class name is then already filled in.
Then hit End or Cursor right in the open type dialog to remove the selection, type T (for Test) and hit Enter to open the test class.
It's like "Ctrl-shift-T" combination, but for package name instead of class name. I have a project with lots of hierarchy package, and when I need to add a new class, it's hard to find the right one.
I think there must be some way in Eclipse to quickly navigate to a package. Does anyone know about this thing?
1) Open Eclipse->windows->Preferecnces->General->Keys
2) Find the Entry Goto Package
3) If not configured, configure it witha key config like Cntrl+Shift+G it should be in the In Windows type. Now Click Ok..
4) Get your work done with that key combination
I don't think there is a standard way of doing this. As a hint I could propose using:
Ctrl+Shift+T together with wildcards.
Suppose we have the same class in two different packages:
com.mycompany.myapp.foo.bar.MyClass
and
com.mycompany.myapp.baz.bar.MyClass
using: *baz*.MyClass inside Open Type window will do the trick (open the second class inside Eclipse editor).
Now assuming you have Link with editor option enabled, now whenever you press Ctrl+Shift+N to create a new class, your package will be filled automatically from the resource previously opened.
Ok, I have a(n) RCP application (that I didn't write), and an application I've developed using just SWT. What I want to do is basically import and launch the main method of the SWT application with arguments, such that it runs in another window, like it's another process. The argument I want to pass is a complex data structure that I don't want to serialize.
I originally thought I could just design my SWT app to be a library and import it, have it spawn its shell, etc. But I neglected to think about how the SWT app's main loop has to run on the main thread, which seems problematic.
So I started looking into integrating it with the eclipse plugin architecture. Problem: I don't know anything about the eclipse plugin architecture or RCP, and when I try to learn, I run into an inscrutable wall of things that are totally unlike what I want to do (ie building new buttons onto the eclipse workbench). How do I get started developing a plugin that just launches another window?
You will need some kind of button to launch your application so just must hook into the Eclipse menu system.
Try:
1) In Eclipse, File -> New Project-> Plug-in project
2) Make sure you check "This plug-in will make contributions to the ui"
3) Uncheck "generate activator" since you won't be needing it
4) Select "Hello World command" from the code template
Now you will have a sample handler and a method called execute where you could call your SWT-application with the display you're using in the RCP-application. If you really must call void main(String[] args) you could get the display by calling Display.getDefault(), which will either create a new display or use the one from the RCP-application.
You will also have to modify the plugin.xml file so it points to the correct menu in your RCP-application. If you want your launch command to be in the file menu etc.
Finally, right-click on your project and select Export -> Plug-in Development and create a jar-file where you launcher will be in. Drop that jar into the plugins folder of the RCP-application and you should be able to launch the SWT-application from the command you've just created.
There will probably be a couple of bumps on the way, but that's roughly what you will have to do.