how to open jar selection dialog at the eclipse pulgin code - java

At Project > Properties > Java Build Path > Libraries tab
you click Add Jars button, you will see the JAR Selection dialog.
I like to open this JAR Selection dialog on my plugin code.
How to open this?

With the Eclipse RCP edition (which you must have since you are developing a plugin), you can use the Plugin Spy (Alt+Shift+F1) and see what exact class you need:
alt text http://img541.imageshack.us/img541/2232/eclipsetreesel.png
It is based on org.eclipse.jdt.internal.ui.viewsupport.FilteredElementTreeSelectionDialog (strangely absent from the sources of org.eclipse.jdt.internal.ui.viewsupport), derived from org.eclipse.ui.dialogs.ElementTreeSelectionDialog.
If you want to see how it is opened, you need to have a look to the global window opening that dialog:
alt text http://img41.imageshack.us/img41/1903/eclipselibclass.png
It is the org.eclipse.jdt.internal.ui.preferences.BuildPathsPropertyPage, from which you can infer the various action classes associated with the button and see how it works.

Related

Intellij highlight file in Project Explorer

In Eclipse, one can choose a File in Editor, right click and hight-light the file in Project Explorer. That will expand the tree, and one can see the file highlighted.
I'm wondering how one can accomplish the same in Intellij IDEA.
There is a shortcut: ALT + F1 then select 1.Project View.
Or you can press Scroll from Source button:
If you're a fan of keyboard shortcuts like me, you can also assign one via Settings - Keymap
Adding to Ruslan answer, you can also decide to automate the process and keep the Project ToolWindow always in sync with the currently opened editor.
Just tick the Autoscroll * menu items.

How to set Run Configuration and Debug Configuration in Eclipse to choose the class that has the main method as the start-up class?

I am using Eclipse for Java EE, Mars 2.
I have two classes in my Java (Swing application) project:
Program.java (has the main method)
Foo.java
If I right-click the editor while Program.java is open, the context-menu presents the commands Java Application and Run Configurations under the Run As menu.
The same happens if I right-click the editor surface while Program.java is open and choose Debug As from the context-menu. I see the two sub-menu items namely, Java Application and Debug Configurations.
However, when I have Foo.java open, right-clicking the editor surface presents only one sub-menu item named Run Configurations or Debug Configurations upon choosing Run As or Debug As respectively.
So, every time I want to run my project and I accidentally right-click the editor surface area while Foo.java is open, I then have to go to the editor tab that has Program.java open and right-click again and choose the right menu item.
I am suspecting there is a way in the Run Configurations and Debug Configurations dialog boxes to tell Eclipse to choose the Program.java class to run as the start-up class since it has the main method.
How do I do that?
You should turn to "Project->Properties" and then select "Run/Debug Settings". There you should be able to configure your project so that it always "runs" the same.
Alternatively, some workaround that I often use when doing JUnit testing on different classes: on top of your eclipse window, there are these buttons
The pulldown icon there opens a "history" of your last run/debug/... "runs". So, once you got your program "run"; you can just use that history to invoke it.
Right click on Foo.java and in Run Configurations dialog, add main class, like below :
Another Solution is setting your launching configuration in window -> preferences
and you can run your project using F11 key (or any key that you can config) i

Eclipse class navigation in package/navigator explorer

Is there a plugin in eclipse where when i switch on a open class on eclipse, it will highlight that class name in package explorer or navigator. So i don't want to manually check the package declaration and explore it in package explore or navigator?
first you should check which version of your eclipse, if you version is Java EE dev, then it has this function. just click the button which is 2 arrows that in the top of package explore or navigator, then you see when you change the file in editor, then the package explore or navigator explore will focus on the file that you select in editor.
Not automatic but you can use Alt-Shift-W to open "Show in..." giving you options to show it in either Navigator, Package Explorer, etc.

Debug Java Applet jar file in eclipse

I have a compiled jar file which is a compiled applet. I have the parameters and name of the class with the init method to start the applet.
I have installed jd-eclipse and would like to debug the applet in eclipse?
It should be pretty straightforward to do. Assuming at least Eclipse Galileo:
Create a project in Eclipse and add your applet jar(s) to its build
path. Alternatively you may choose to add the applet jar(s) to the
build path of an existing project.
Right-click your project, select Run As->Run Configurations Select
Java Applet in the left hand pane and click the New button at the top
of the pane
At the top, fill out a name for the new Run configuration, then on the
Main tab click to Search for your applet class.
On the Parameters tab, fill out all parameters from your existing
Applet HTML page.
Optionally, fill out any additional information you want the Applet
to have when it runs, on the other configuration tabs
When done, click Apply, then optionally Run to fire off the test
right away.
Good luck!

How to add directory to classpath in an application run profile in IntelliJ IDEA?

I'm trying to add a directory to the classpath of an application run profile
If I override by using -cp x:target/classes in the VM settings, I get the following error:
java.lang.NoClassDefFoundError: com/intellij/rt/execution/application/AppMain
Any idea on how to add a directory to the classpath for my project?
In Intellij 13, it looks it's slightly different again. Here are the instructions for Intellij 13:
click on the Project view or unhide it by clicking on the "1: Project" button on the left border of the window or by pressing Alt + 1
find your project or sub-module and click on it to highlight it, then press F4, or right click and choose "Open Module Settings" (on IntelliJ 14 it became F12)
click on the dependencies tab
Click the "+" button on the right and select "Jars or directories..."
Find your path and click OK
In the dialog with "Choose Categories of Selected File", choose Classes (even if it's properties), press OK and OK again
You can now run your application and it will have the selected path in the class path
It appears that IntelliJ 11 has changed the method, and the checked answer no longer works for me. In case anyone else arrives here via a search engine, here's how I solved it in IntelliJ 11:
Go to the Project Structure, click on Modules, and click on your
Module
Choose the "Dependencies" tab
Click the "+" button on the right-hand side and select "Jars or directories..."
Add the directory(ies) you want (note you can multi-select) and click OK
In the dialog that comes up, select "classes" and NOT "jar directory"
Make sure you're using that Module in your run target
Note that step 5 seems to be the key difference. If you select "jar directory" it will look exactly the same in the IDE but won't include the path at runtime. There appears to be no way to determine whether you've previously selected "classes" or "jar directory" after the fact.
You can try -Xbootclasspath/a:path option of java application launcher. By description it specifies "a colon-separated path of directires, JAR archives, and ZIP archives to append to the default bootstrap class path."
Set "VM options" like: "-cp $Classpath$;your_classpath"
I am using Idea 8.
in your module dependancies tab (in the project structure dialog). Add a "Module Library". There you can select a Jar Directory to add. Then make sure the run profile is using the Classpath and JDK of the correct module when it runs (this is in the run config dialog.
Simply check that the directory/package of the class is marked as "Sources Root". I believe the package should be application or execution in your case.
To do so, right click on the package, and select Mark Directory As->Sources Root.
You need not specify the classes folder. Intellij should be able to load it.
You will get this error if "Project Compiler output" is blank.
Just make sure that below value is set:
Project Settings -> Project -> Project Compiler output
to your projectDir/out folder
Open Settings
Under project Settings, select "project settings (1)"
On the left, select "modules"
Select the desired module
Select the "Sources" tab
In the tree structure, find the directory you want to add. Then either add as a source or test source.

Categories