adding node.js application as a dependency to a java maven project - java

is there anyway to append node.js application to java maven project as a dependency and to run it from inside the java maven project?
I know I can add it as a module inside the java project and run it via ProcessBuilder
but I got a requirement:1. this module will be built out of the java maven project and will be added to the java maven project as a dependency (with all the required node modules etc compiled inside ) 2. this module will be executed from the java maven project , is there any way to do that ?
Thanks.

Related

Intellij : import project as library for another project

I am developing a project A (Java Maven) which uses a library B (a JAR file)
I have the source code of library B, and I want to change code in project B, while it's used as library for project A.
Is that possible in Intellij to replace a JAR library by its source code ?
I'd configure a multi-module Maven project with the parent aggregate pom.xml and 2 sub-modules: for the app and for the library with their own pom.xml files.
Define a dependency on the lib module for the app module. IDE will resolve such dependencies via the sources and you will see the changes in the project instantly without the need to compile. Refactorings will also work across the modules so that you can rename a method from the usage in the app and it will automatically rename it in the lib.

I just started learning Maven. How does Eclipse build without it?

I've been coding Java in Eclipse for awhile without needing to specify dependencies. Now that I learned how Maven does it, I'm wondering: how did Eclipse build projects on its own? How did Eclipse figure out which versions of imports, and which dependencies of dependencies, are needed to make everything work?
Finally, what are the advantages and disadvantages of building a project in Eclipse by starting with New->Other->Maven Project instead of New->Java Project?
To the first question: Eclipse doesn't add any dependency in a standard Java project. You have to manually add to the Build Path all needed JARs, otherwise you'll have compilation errors.
To the second question: if you create a standard Java project Maven is not used, even if you create a pom.xml file in the root of the project. You can always convert a standard Java project in a Maven project (see Convert Existing Eclipse Project to Maven Project).
Your dependencies has always to be in the classpath
When you start a project with Maven, Eclipse will automatically add the Maven repository to the classpath.
When you start a Java project you have to link your library manually in Eclipse and the version of the library is the one you've downloaded.
You can see the difference in your project's Properties > Java Build Path > Libraries

Gradle multi projects and tomcat

I use Gradle to configure my new projects and import them into eclipse.
The project A (wtp) depends on project B (pure java).
Root
A (web application)
B (java dependencies)
I try to use gradle's multi project settings. In Project A build.gradle I've added
compile(project(":B")).
Inside eclipse I'm able to use the project B class, but I'm not able to run it in tomcat because of the following error:
"Could not publish to the server. Path for project must have only one segment."
Do You have any suggestions?

Maven: How to generate a standalone application?

I am using Maven to manage a console application project. On my machine, I type mvn exec:java and Maven handles everything. What I want is, however, to execute the same application on a different machine without the help of Maven.
In NetBeans, Ant projects have a dist directory with all the necessary files. All you have to do is to type java -jar dist/App.jar. How can I make Maven generate such distributable directory or archive?
PS: Although seems relevant, this is not a duplicate of Create a standalone application with Maven.
I have used in maven.
http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/
The Application Assembler Plugin is a Maven plugin for generating scripts for starting java applications. All dependencies and the artifact of the project itself are placed in a generated Maven repository in a defined assemble directory. All artifacts (dependencies + the artifact from the project) are added to the classpath in the generated bin scripts.
and http://maven.apache.org/plugins/maven-assembly-plugin/
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
You can build an executable jar file with the maven-jar-plugin; more info on their examples page here: http://maven.apache.org/shared/maven-archiver/examples/classpath.html
That will simply create an all-in-one jar that can be executed through java -jar

Can't add Java Project nature to nested m2Eclipse project

I have a nested m2Eclipse project in Indigo. The parent project contains the src folder that is used by the nested modules (see structure below).
parent
src
pom.xml
module1
pom.xml
module2
pom.xml
Running mvn package from the Maven run configurations builds all the modules, so dependency management appears to be working. However, I don't have a MAVEN DEPENDENCIES folder and I can't use Java content-assistance or any other Java Project capabilities on any of the source files. I tried converting the project to faceted form and adding the java facet, and that didn't work either.
It is because the parent is not a java project but a pom project.
While developing a maven project SET in eclipse using m2e, you are supposed to import all the projects into your workspace and you should do java development in module1 & module2.
With the current way of editing java source files, you are in detached mode and none of the advanced instruments from JDT is available to you as this java file is not part of a known java model to eclipse.
Try right clicking on your project and do Import... -> Existing Maven Projects. This way you should end up with three projects in your workspace one being the pom project and other two (supposedly both) java projects. Then all java development should be done in project1 and project2. M2e is smart enough to create in-workspace dependencies for the java projects.
Hasan Ceylan

Categories