AspectJ project as a jar to another project - aop

I have 2 projects.
Project A - This is an aspectJ project. For example: It prints the method name and time taken, in console after execution of each method.
Project B - It is a sample web project.
I want to add Project A as a Jar to Project B. So whenever I run Project B, it should display what are the method names and time taken.
Since I am new to AspectJ , could someone explain how to do this. Please explain with some sample projects.
Thanks in advance.

You have several options:
Use A as an aspect library when compiling B with the AspectJ compiler Ajc. This can be done from command line, from IDE with the right project configuration or, most conveniently, via AspectJ Maven plugin.
Use A as an aspect library and B as a weave dependency in a post-processing step with Ajc. As before, this can be done from command line, from IDE with the right project configuration or, most conveniently, via AspectJ Maven plugin.
Use load-time weaving (LTW) via -javaagent:/path/to/aspectjweaver.jar command-line switch when starting your Java application containing B and put A on the classpath as an aspect library.
For more information please use your favourite web search engine, specifying search terms like "aspectj ltw", "aspectj maven plugin", "aspectj ajc" or similar.
P.S.: Why should anyone provide one or multiple full sample projects if you are too lazy to provide a single line of code?

Related

How to import a Kotlin Library in IntelliJ

So i want to use the Serialization Library in my kotlin project, and from what i can gather from this page, i must use this: "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2", to do so, now i use "IntelliJ" as my build system, so i went to the project structure, and in libraries, clicked the + sign, clicked on "From Maven" and put this as the link to the library, and it downloaded it and i set it as a dependency of my project, it even shows as a external library, like this:
But when i try to import the lib, it gives error:
Apparently you can indeed use IntelliJ IDEA as a build system without maven or gradle, but I don't think this is a supported way to use kotlinx-serialization.
I'd advise to pick either maven or gradle as your build system for your project (this can be done through IntelliJ, just create a new project and pick either one).
Then you can just follow the relevant paragraph at https://github.com/Kotlin/kotlinx.serialization#setup for either maven or gradle.

Gradle project with no project classes but with some buildscript-accessible custom classes?

I am thinking to use Gradle to manipulate with mysql database. It will read some files from filesystem, analyse them and populate database accordingly.
Such project will not produce any project code, because all output will go to database tables. On the other hand, gradle script should access some custom java or groovy classes to facilitate working with source data.
Is this a possible Gradle usage? Where to put gradle-accessible classes then? I don't want to have separate project, producing JAR for this project. I wan't single project, so that Gradle first compiles classes and the utilizes them in the script.
Is this possible?
Gradle is extensible, so you can utilize buildSrc for such scenarios. It works in the following way:
along build.gradle in the project there is buildSrc dir with custom build.gradle
in buildSrc/build.gradle you can define the script dependencies itself, implement plugins and tasks
finally you can apply a plugin from buildSrc to build.gradle.
It's quite handy, since e.g. IntelliJ can import such project and provide code completion for instance.
Another way is to put all the necessary stuff in build.gradle itself.
Such buildSrc project can be compiled to a jar, published and provided as a plugin, or it can be a separate project on github to be downloaded and used to manipulate data. Also, there no need to implement Plugin, you can use static methods e.g. Have a look at the demo.

How to automatically generate JAXB classes on build in IDEA?

I have an IDEA project that uses auto-generated JAXB classes from .xsd files. I have “client” and “server” modules that include a “common” module that contains, among other things, the JAXB classes.
I do not want to keep generated code under source control, but if the generated java classes do not exist, “client” and “server” modules do not compile. How to make IntelliJ automatically run JAXB before building?
There is no direct way to do it only with IntelliJ IDEA, you will need to use Ant or Maven or some other external process that will perform the code generation.
Check out jaxb2-maven-plugin.
In IntelliJ IDEA you can execute Maven or Ant before compilation.
In the build system's tool window you can bind a phase or a plugin goal to IDEA's build process.
For example the jaxb2-maven-plugin can be executed Before Rebuild or Before Build with a secondary click on the goal:
Another option would be to bind the goal to a lifecycle phase and execute the phase like 'generate-sources' before rebuild. In case of the jaxb2-maven-plugin the goal xjc is by default bound to the generate-sources phase of Maven.

How to add the target jar as a test resource of the same project?

I'm developing a Solr plugin and using the Solr test-framework I place a test SOLR_HOME dir under test/resources with /conf/ and /lib . Now the framework inistantiates a SolrCore and loads my plugin from /lib. Not an issue to output the jar of the plugin to /lib, but the issue is that the plugin is not yet available since it still needs to past the test (chicken and the egg).
How do you recommend solving this? I see those options:
Create another project for the tests with a dependency on the plugin, and in it run the tests. Simple enough, but how do I ensure that everytime the plugin is built also the tests of this other project is built? The point of the automated tests at every build is to having a new plugin jar which breaks the tests.
In dp4j pom.xml I build the project on 2 phases, in the 1st I <include> only the annotation processors while in the other I compile the tests which rely on the annotation processors compiled in the eariler phase.
I'm in favor of 2 since copy-pasting the configuration doesn't seem a bad option, and makes it seem less complicated than it probably is. I don't remember if I had asked about it here - what do you recommend? Any other case studies /working code to look at?
there's a 3rd. most probably best solution ~ do nothing!
I was under the impression that the Solr Testframework need to load my plugin from /lib but apparently it doesn't need to, it can load it from test-classes, all on its own!

Looking for a simple example to fire "make" from Maven2

This is a transitional solution.
I don't want to write my own plugin.
I have too many small, scattered makefiles to convert to pom.xml all at once.
I'm trying to move to Maven2 as a skunkworks project and gradually migrage new + changing code to pom.xml files.
The arch-independent C/C++ solutions are not needed - plus the Makefile run multiple scripts to generate code before compilation.
Any pointers to extending "mvn deploy" to handle "make deploy" would be great.
Thanks
AJ
You should check Codehaus' related CBUILDS project. It may help you with downloading dependencies, unpacking, patching, and invoking make.
I'm a bit confused as to why you're moving towards maven with C projects, but if I were you, I'd look at gmaven-plugin to execute an inline groovy script to invoke what you need. Then, if you want to create a plugin later, it should be easy to migrate to one.