I'm on a Enterprise Project that requres a lot of Java Plug-ins.
Every plug-in has the same structure, that is something like
com.mysite.XXXX
---com.mysite.XXXX
------Activator.java
---com.mysite.XXXX.impl
------XXXXMyClass1.java
------ ..............
------XXXXMyClassN.java
---META-INF
------MANIFEST.MS
---XXXXFolder
------XXXX.xml
this structure is repeated for 4-5 times for each development, so I waiste a lot of time just for creating the project structure copy-pasting and renaming a blank template, and every member of my team has this problem.
I'd like to create a way to auto-generate the java projects and the relative structures. This pattern will remain the same for years. I'm not looking for the cleanest and finest solutions, something dirty but working would be ok :) .
Can you help me? What technologies can I use?
I would try creating a custom Maven archetype
We use maven archetypes to create plug-in projects with associated test fragments. The approach is described here in more detail.
As others have said, generate your bundles using Maven.
You can use the maven-bundle-plugin to create your OSGi manifest rather than creating it manually.
Once you have a working Maven build, as mentioned above, create an 'archetype' for that, and your other developers can use that to create the framework of a plugin application.
Related
I want to create a simple Java library with some common utils/helper functionality I use on several projects.
I'd like to use the mvn archetype:generate for this, but there are thousands of archetypes to choose from and it's rather difficult to figure out which would be suitable for my need.
Maybe the maven-archetype-quickstart is good enough, but I'm wondering if there is not a better one for this.
In my eyes maven-archetype-quickstart fits the best for your project. It provides the default project structure for Java Projects. You could use maven-archetype-simple also. It is adding the site.xml file. All other default maven archetypes would not fit for your simple Java project. Have a look at
https://maven.apache.org/archetypes/index.html
You should configure the version of Java Compiler for Maven to use other than default 1.4. https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
EDIT: You could use the java-archetype from Olivier Cailloux on GitHub https://github.com/oliviercailloux/java-archetype which claims to improve the created project configuration.
I have a project which has a large number of classes(>1000) which are archived into 7 jars. All these jars are built separately (using ant). If some one has changed one of these classes, there may be numerous other classes that depends on this one, and all those will fail runtime. How can i check the dependency to a class file from other jars?
Thank you.
Your best bet is to use an IDE like Eclipse or NetBeans. There are many ways that an IDE can help you with this issue.
If you don't have the source code or source jars for the projects, you should create some integration tests that can assist you in regression testing (actually, most will say that you should do this anyway). You can start by looking at JUnit. After a change, if any test fails, you know that you will need to look into the usage of the class/API.
If you utilize something like NetBeans you could have all the projects open and use 'Find Usages'.
You could use the Class Dependency Analyzer tool.
I'm using m2e (1.0.100), Eclipse (Indigo SR1) and hibernate-jpamodelgen (1.1.1.Final).
I want to have hibernate generate the Canonical metamodel from my entities when I compile the projects.
I was able to do this previously when I was working on a non-maven project and I followed the numerous tutorials there are on how to configure the eclipse project to use this jar.
However, to the best of my understanding, when using m2e it is best (mandatory?) to let it do the eclipse configuration for you and so I'm not sure how this should be done.
This hibernate tutorial explains how to use the generator with maven and eclipse but separately.
I think what I'm missing is gluing my pom, which was generated as a simple no archetype pom, and my eclipse project configuration so that they enable me to do some JPA magic.
BTW, following the above tutorial for maven caused my maven-generated jars to contain the _ classes but these are not seen by eclipse since they are only in the jars and not in the actual projects.
Thanks in advance
I've asked the same question on the m2e-users mailing list and got the following answer (link for those wanting the full thread):
Basically one should manually configure (for example using the above mentioned hibernate tutorial) eclipse to use the generator and configure the same directory maven uses (for me it was target/generated-sources/annotations) as the output directory.
According to the committers of m2e, the project currently does not change these eclipse files and so this won't be overriden from them.
The problem I did face was that this information is lost (and so the manual change is needed again) when using GIT and switching between branches as I don't want to commit any eclipse related files to the SCM.
Currently this is an acceptable solution and I hope m2e will be able to add this missing feature.
Update
The information that is lost, at least according to my experience, is the definition of the target/generated-sources/annotations folder as a source folder. Just as an FYI.
I develop a little java utility library using maven. Now I'd like to add some demo / sample code to show how to use the library.
Where is the best place to put it?
In a sub-package with the other code. I don't like this since it means the demos will be included in the library jar file.
In a new maven artifact. That works, but I'd prever to have the demos closer connected to the library source.
As a sub-artifact. Haven't tried this yet. Seems to make everything a bit complex for something that should be simple.
Is there any common pattern to do this?
If it's some sample code snippets that run by themselves and just demonstrate how to use the library, then write them as unit tests, in the same module.
If it's more like a separate demo application (that a user might even interact with), then create a separate artifact. It's the standard way of doing it. If you really want to you could put it in the same module, but in a different source directory, but that's just making it harder on yourself.
Your library and you demo should probably share a parent module (of type "pom", not "jar" like the others), giving you a multi-module project. Then you can build both by launching maven from this parent module.
If you want to release your library and demo together (you can, but you don't have to), you can do that from the parent too.
In other words, it's not because they are separate modules, packaged in different artifacts, that they cannot be closely connected anymore. The different modules of a multi-module project still form one whole project.
You hadn't written what kind of utility library it is, but if it's something like apache commons, then most of the demos can be written as JUnit tests, which are placed in the same artifact. Good designed JUnit tests both tests your code and provide example how to use your utilities.
I prefer a new maven artifact, it can make your own artifact clean
I would recommend create a maven multi-module project where one module is the core and one module is the demo code. That way the user can choose if he wants to create both modules (they become separate artifacts) or if he just wants the core.
What is the easiest way to see the libraries dependencies in Java project (eclipse)?
I am using Spring MVC and Hibernate so right now there are a lot of jar files and I even do not remember which one of them are responsible for what.
check out tattletale.
http://www.jboss.org/tattletale
See them how?
If you're using maven, use the dependency plugin's dependency:tree to get a hierarchical representation of what depends on what.
If you're not, ew; manual management of transitive dependencies sucks! You can use something like Dependency Finder or JDepend to provide similar info.
Not sure if this is what you mean, but to start with you can right-click the project (in Eclipse) and look at Properties -> Java Build Path. The Libraries tab should list what libraries you're using on your build path. (But you probably knew that.)
If it's a simple standalone project, you could of course always remove a library and see what interesting new errors pop up ;-)
For more complicated projects with interdependencies, it can take quite a bit of fiddling to get all your dependencies right. I generally recommend setting up a "core" project which holds (and exports) most of your third-party JARs (better yet, use user libraries, and putting that project on the build path of your other projects.
Edit after reading your comment: Ah, gotcha... you might be interested in the Plug-in Dependency Visualisation incubator project then - haven't used it myself but it sounds like it could do what you're after. Hope that helps!