How to build 4 projects(example) and make them access each other? - java

How do I make something like 4 project and make them see each other, like a .xhtml to a Bean and a Bean to the interface that implements the method to save or read something from the database?

The other solution would be to:
use only one workspace (meaning each components see each other)
define task context with Mylyn in order to switch from one component to another and see only what you need.

You cannot split workspace. You can create as many workspaces as you want and add there as many projects as you want. To create new workspace just create directory and then start eclipse and give it this directory as a workspace. It will do everything automatically.
Unfortunately your second question is unclear.

Right-click on the project; choose Properties. Click on Project References and select the other projects.

Related

Eclipse doesns't show project explorer properly

I'm using eclipse neon. I have created a maven project and create a package com.prueba.account and then I have created many packages inside.
But eclipse shows me all packages as an independent project and without the full path like in the image. Notice that checking package is inside com.prueba.account
Just Click on the Drop Down in Project explorer. All you need is to change Package presentation from Hierarchical to Flat.
Hope it helps !!!!
First of all, welcome to Stack Overflow Gary.
Then to extend on Adyas Answer:
In Eclipse there are two ways to display the package-structure.
Hierarchical :
And Flat:
I personally find the Hierarchical view way more convenient, for when you're working on a bigger project, you often get really long package names which, when in Flat view, might clutter the whole window.
But in the end, it's up to your personal taste.
The way to change between this two modes is to click on the down arrow icon at the top of the Project Explorer and under Package Presentation you can choose between the two.

How to add project to Create Project Wizard in Eclipse

In Eclipse while creating new project, the following window opens (consider the area surrounded by red lines in the image).
From that we can select project as Java Project or as per our requirement.
Now my question is, is it possible to add Custom Java Project as a project template in select Project Wizard ? If yes, how?
I want to create (please look the area surrounded by black lines in the image) a project having the name IoTSuiteSpecification as a default Project template in Select Project Wizard with mentioned four files and package.
For example, while creating new project, IoTSuiteSpecification is there in Select Project Wizard. Let me know if you need more clarity.
As you did not provide detail about what function you want to implement. This answer will just focus on how to create a new project wizard, but not the functionality details.
In short: you need to write a plugin and install that on every Eclipse you want to have this function.
I would like to keep this answer short, so the following content assumes you have basic knowledge about Eclipse Plugin Development, and have already created a plugin project. If not, please refer to tutorials such as Your First Plugin or Google "Eclipse Plug-in Tutorial".
Step 1: Create an extension for your project wizard
Go to plugin.xml -> Extensions -> Add -> org.eclipse.ui.newWizards, choose the "New File Wizard" template, click next.
Name your Classes properly. I will call everything NewWizard. So the wizard class is NewWizard, and the wizard page class is NewWizardPage, etc. Do not care about the "File Extension" and "Initial File Name", we won't need them.
Click Finish
Step 2: Implement the classes
After the previous step, you will have a package containing the wizard classes you just created. It should have two classes NewWizard and NewWizardPage.
First, you need to customize NewWizardPage to provide controls for your user to specify information such as Project name, etc. Refer to org.eclipse.ui.dialogs.WizardNewProjectCreationPage for an example of how to create a new Project Wizard page.
When you gather information from user, you should do some setup of your new project. Open class NewWizard, and find the function performFinish. In this function you should create your new project and setup it such as adding project natures. org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard is the eclipse wizard for creating a new general project. It provides a good reference for how to do these. If you have no idea, read or just copy their code.
Step 3
That's it! Enjoy your new project wizard!
Examples
As an example, you can look at my project https://github.com/harperjiang/TeXDojo. This is a plugin I wrote for Eclipse to edit and compile latex files. It contains a complete project wizard implementation in the package LaTeXEditorPlugin/src/hao.tex.dojo.latexeditor.wizards

Eclipse Hotkey to quickly locate a package

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.

Getting a Class from another project programatically

I want to access a class which is present in another project . For that i use java reflections,but first i need to get the class object which is in another project.I want to get it programatically.I can do that like right click on my project then go to build configure path and then to project tab and add project.I want to do it programmatically .How can i do that?Help
You need a custom class loader.
tutorial link1
tutorial link 2
I think you can do it by creating a jar of the dependent project and adding it to class path before you run your application.
It seams you are working in eclipse and want do use the classes from projet B in projet A, is it so?
If so you could specify in eclipse that project A depends from project B by adding the project in the 'java build properties'.
Do get the right answer, you ask to be more specific in your question like Steven wrote.

How do I conditionally include or exclude a file from an archetype when project is generated?

I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the following prompt:
Define value for groupId: : com.example
Define value for artifactId: : myproject
Define value for package: com.example: :
Define value for includeGradleSupport: : y
Based on the value of includeGradleSupport, I want to include (or not include) the build.gradle file in the generated project. If the user does not want Gradle support, I don't want to clutter up the generated project with unnecessary files.
Another example is that I might need to provide a Jetty web fragment (to activate a listener perhaps) if the user wants Jetty support.
It's all about customization of the project based on what the developer intends to use. While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
Is there a way to control this behavior using the archetype-metadata.xml descriptor?
I personally would move the parts that can be removed/added on user request and put the into different maven profiles so u can build different part using different profiles
I can have a look into what coding it would take to enable this in the archetype plugin.
I think the primary vehicle to do this today would be to conditionally produce two different archetype artifacts during the original build. The archetype user would then explicitly use yourarchetype-withthing or yourarchetype-withoutthing.
I know this isn't perfectly what you are after and I agree that what you are asking for is a sensible use case.
While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.
This sentence made me think...
It seems like you have a default project structure.
Let's suppose it is big, has many files. Of course, you don't want to duplicate the logic and the files in a different archetype.
Now sometimes, a project has an additional behavior (related to Gradle).
This sound a typical use-case for another archetype that does not start from nothing, but that comes after the first one. I've seen several examples of such archetypes on the web. The developper triggers this archetype only if the project needs Graddle. :-)
So I suggest : create your Graddle archetype, that adds only the files relevant to Graddle.
Thanks for the info Dan !
I just looked at looked at archetype plugin source code, and http://jira.codehaus.org/browse/ARCHETYPE-58 doesn't appear to have resolved this issue.
Just created http://jira.codehaus.org/browse/ARCHETYPE-424 to track it.

Categories