artifact:pom command not recognized in one workspace but not another - java

I have 2 workspaces in which I am trying to use an ANT build to build an ear file. The one workspace uses 3 different projects to build the ear. I needed to create a single workspace to create the same ear. I migrated all of the source code, properties files, etc. to build this ear. The compile is breaking on this line:
<artifact:pom id="parent-pom" file="./mvn/parent/pom.xml" >
<profile id="${deploy.name}" />
</artifact:pom>
I have the pom file in the folder in the project.
The error is:
Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:pom
This build file has the artifact added at the top of the file:
<project name="Ant XML Library for Deploying" default="usage" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
The 2 workspaces are using the same compute and same Eclipse environment. I searched the other projects for the jar, maven-ant-tasks.jar but it is not any of the projects in the workspace that is correctly building the ear file.
The only jar files that are in a lib folder in one of the projects are these:
ant-contrib.jar
cm-anttasks.jar
jsch-0.1.41.jar
log4j-1.2.8.jar
I tried adding these to the workspace that is not working but it does not work.
Any ideas as to what I need to add to the workspace?
Thanks.

I added maven-ant-tasks.jar to my project and it now recognizes the commands.
However, my initial workspace did not need this jar included into the project. It recognized the commands.

Related

How to identify project type from project folder

Recently i have received a project as a zip. I have unzipped and now i want to import the same in eclipse. But am unable to identify what type of project(maven, java, gradle, etc) it is. I have tried importing as existing project into work-space. But its not identifying as a project when searching in eclipse.
For maven projects, it will have a pom.xml, this one don't have one.
Similarly is there any other ways to identify what type of project it is from the project folder?
Thanks in advance!
I have received partial answer from the commends of #Sangeeta and #carchingUp. I want to add all details to a single answer so that it will be helpful to others.
Inputs from Sangeeta: if pom.xml is present you can infer its a maven project. If build.sbt, then its an sbt project. If build.gradle, You can know its a gradle project and build.xml for ant projects
In my case i was having build.xml from which we can identify as ant project.
When you import the project as ant project to eclipse and if you have the below scenario,
"package name is com.abc.xyz, present in src/main/java and when importing as ant project, main.java.com.abc.xyz becomes the project and am getting error for all the java files for package name mismatch", follow the below steps.
right click the src folder >build path >remove from build path
right click the java folder > build path > use as source folder.

How do I create a runnable JAR in IntelliJ as I would in Eclipse

My process for creating a runnable JAR from a project with many libraries with Eclipse has been.
Export > Runnable JAR > Select launch configuration > Package required libraries into generated JAR > Finish
This creates a single JAR in my export destination which I FTP to my server and run fine.
I recently switched to IntelliJ for various reasons and it has been an improvement in all cases except for building my JARs which forces me to go back to eclipse temporarily.
With IntelliJ I:
Open Project Structure > Artifacts and create a new JAR from modules with dependencies. I then have my output layout with the name of the JAR, a META-INF inside it and all my libaries with the format Extracted <lib.jar/> (sorry I can't upload screenshots on this VPN.)
I build my artifact (which is about 15MB bigger) and FTP it to my server, try to run it and I get the error:
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
How do I mimic how I do it in Eclipse?
EDIT
The two JARs that are created differ considerably:
The valid jar that Eclipse creates looks like this:
Whereas the invalid .JAR looks like this:
You're facing two issues one seems major and one is minor:
Major: signature exception
Minor: size of the jar is 15 MB greater than the jar produced by eclipse.
The solution of both of the issues lies in the way you are building the artifact. First of all, remove all extracted *.jar then add all the jar's from the available elements pan as shown in the figure.
It is obvious that adding packaged(compressed) jars only, will decrease the size. But it also solves the signing issue. For more explanation, please have a look at this article. I'll only quote one line.
It's probably best to keep the official jar as is and just add it as a
dependency in the manifest file......
It seems that some of the dependencies are signed and repackaging messes up the META-INF of your project.
If you are using Maven you need to put META-INF directory under /main/resources folder instead of main/java.
Reference: Intellij - Nikolay Chashnikov
Then you can execute the runnable jar normally with java -jar filename.jar
You can these steps:
1) File -> Project Structure -> Project Settings -> Artifacts -> Jar -> From modules with dependencies
2) Check the Include in project build checkbox.
3) Right mouse click on module -> build module 'ModuleName'
you could try using a gradle script. eclipse will make you a gradle project. you can use that build file with any ide. it has a built in jar task.

Jar missing generated pom.properties file when built in Eclipse

My project refers to the generated pom.properties file that Maven generates in:
META-INF/maven/${groupId}/${artifactId}
Which is included (in a Jar) as a dependency in another project. When I build / package the main project with Maven outside of Eclipse, the dependency Jar is built as expected (containing the pom.properties file) and all is well.
However, when I build / run the same (parent) project within Eclipse, it's not there. What am I missing?
Using Eclipse, a Jar library of the dependency is there (in the lib folder), containing everything except the Maven generated files. So in my case:
META-INF/
META-INF/persistence.xml
META-INF/MANIFEST.MF
~~~ snip ~~~
The dependency project exists in the same workspace and I have "Workspace Resolution" enabled.
Looking at the build target folder in Eclipse (\target\classes), I can see all the files that Eclipse uses for the Jar, so I can only assume that Eclipse treats it as a "regular" Java project (despite the parent project listing it as a Maven dependency in the POM) - so Maven doesn't get involved in the packaging.
How can I get Eclipse to treat the project dependency as a Maven project / so that the generated pom.properties will be included in the Jar used by the parent project?
Update
For the parent (War) project, the following structure is generated whenever I use Eclipse to build the project (using "Build Project" or "Build Automatically" not "Maven build"):
target\m2e-wtp\web-resources\META-INF\maven\${groupId}\${artifactId}\pom.properties
This is referenced in the Eclipse deployment assembly:
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
So that when the War is deployed to Tomcat, the META-INF\maven... structure exists at the root of the archive.
The dependency / Jar project obviously has the same "Deployment Assembly" facility in Eclipse, so I just need to figure out what creates the m2e-wtp folder on build and apply it to that project too.
Actually, I don't think you can with the default Eclipse Jar-Export.
The best you can do if you want to do it from within Eclipse is to have a Maven Build run configuration which doesn't do much differently than using Maven outside Eclipse. But at least you have a button in Eclipse to click do generate the jar, if that's the main reason. But the normal Eclipse functionality to produce a jar (File > Export...) ignores all Maven settings.
Workspace Resolution only works for compiling and running code, but not for other Maven functionality.

"Could not find or load main class" after removing Maven nature and files (pom.xml, target/) from an Eclipse Project

I accidentally converted my project to Maven by going to Configure > Convert to Maven Project. Now I want to undo this. I read that I need to right click Maven > Disable Maven Nature and that worked fine. However I want to totally remove Maven, so I deleted the pom.xml and the target folder. When I try to run my code now, I get the error:
Error: Could not find or load main class
So what am I missing? How do I revert from a Maven project to a non-Maven project?
When you convert a Java project to a Maven project in Eclipse, the Maven Integration for Eclipse (m2eclipse) configures the Java incremental compiler to put the compiled class files in the same location as Maven would put them, i.e. target/classes.
So when you remove the Maven nature and delete the target folder, you now also have deleted the compiled class files and your project can no longer run. AFAIK, the incremental compiler doesn't detect when you remove its output files, so you need to trigger a rebuild by cleaning the project (Project > Clean...)
This will fix the problem that you can not launch your project, but may re-create a target folder. If you also want this to be "fixed", you can switch back to some other folder name for the binaries, e.g. bin, in the project's Java Build Path configuration on the Source tab.
Is it basically a Maven project, i.e., do you have and maintain it through a pom.xml? Then my suggestion is to delete the project in Eclipse but keep the files on the disk (i.e., it removes it from the workspace). Then, run a simple mvn eclipse:clean eclipse:eclipse which creates a simple Java project without the Maven nature based on the POM (so the libraries are linked and the source/output directories are set up correctly - this may solve your ClassNotFoundError).
If it's a simple Java project, I would advise deleting it from the workspace, removing the .classpath and .project files and importing it again with the Create a Java project with existing sources wizard.
Either way, make a backup of your project before you start doing anything :-)

Eclipse - Create Dist directory

Recently I was forced into using Eclipse because of TFS plugins:
I have a few projects that I'm converting to Eclipse projects from Netbeans. Some of these projects reference each other. After starting to convert these projects I quickly found that Eclipse doesn't want to jar projects post-build. So I used an build.xml and created a new 'builder' for each project (whose bright idea was it to not allow me to reuse builders across multiple projects?). After I got all that working I was sitting back thinking about how I would go about building for deployments, and it occured to me that eclipse is not including any of the referenced assemblies in the build output directory. This sucks, because manually creating lib folders and copying over all of the jar files which are required will be error prone, and time consuming. So heres the question. Is there any reasonable way to set up a builder, or property on an eclipse project such that when I build it, it will create a 'dist' directory, containing both the jar'ed project classes, and a lib folder with all of the referenced jars attached to the project?
Is there any reasonable way to set up a builder, or property on an eclipse project such that when I build it, it will create a 'dist' directory, containing both the jar'ed project classes, and a lib folder with all of the referenced jars attached to the project?
Yes, right-click on the Project and select Export. Type "jar" into the search box and select Runnable JAR file. In the export dialog, select the "Copy required libraries..." option. There should also be an option there to save this export as an Ant script.
I dont know how to resolve a list of dependencies using ANT
Next, you should consider using Ivy. This will add dependency management to your build script. There's probably some learning curve here, but these tutorials should help.

Categories

Resources