requireFilesDontExist - Maven Plugin - How to? - java

I'm trying to fail the maven build when certain files are present anywhere in build path.
Looking at enforcer plugin: requireFilesDontExist. But we need to know absolute file path for it to work.
How to use it (or create new) when i have only file names and it can be anywhere in build path?

Related

Maven creates sub folders in M2_REPO Directory

After running Maven - clean, I see sub folders in my M2_REPO folder. junit.jar was created in M2_REPO/junit/junit/4.11/ alone with some other files. Because of this sub folder structure, eclipse is not able to recognize the junit.jar file. What am I missing?
You're looking in the wrong directory. Eclipse shouldn't read the jars directly from this directory, it is the local cache of what maven manages.
The pom.xml is where you should put your dependencies, and eclipse will then use the maven libraries to get the required jar file, put it on the build path, and possibly cache it in the directory you are looking at.
Note that if you want the junit jar file for testing purposes, the typical file in src/main/java will not see it, because testing source code goes in src/test/java.
This means that maven provides (through the libraries) (at least) two classpaths. One for typical compilation and one for test compilation and execution. Adding in a <dependency> tag section puts it on the compilation and run paths; but, to make it "test only" you need a nested <scope> tag.
Maven correctly is creating those directories the first time it tries to acquire those artifacts.
For integrating maven and eclipse, try running mvn eclipse:eclipse
This should enable eclipse to see the jars maven has downloaded.
That is the path of the local M2 repository and the sub-folder structure is exactly how it should look.
Make sure that you import the project in eclipse as a maven project by doing
File -> Import -> Maven -> Existing maven project

Link maven dependencies on non maven project

I have two projects in Eclipse, the first project depends on maven, the second project which dependent on the first one does NOT depend on maven.
The first project downloads external libraries like jar files and natives to the .m2 maven folder. However the second project gives a ClassNotFoundException since it cant find the jar files and the native files from the first project.
Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties?
I would appreciate any help.
In your Maven project, use Assembly plugin to create an Uber-jar that contains the project build artifact and all its dependencies (mvn assembly:assembly -DdescriptorId=jar-with-dependencies). Then, reference that from project #2, either with a relative path or by using an ant build task to copy it into your other project's lib directory (assuming you have such a directory). Also, although it's frowned upon, you could configure the assembly plugin so that your Uber jar artifact always has the same finalName.
Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties?
I don't think so.
But maybe you could create a 3rd project (which is a Maven project) that depends on the first one, and on the JAR (or whatever) file created by the 2nd one as a non-repository dependency.
Having said that, anything you do is going to be a bit of a hack. You'd be better of either turning the 2nd project into a proper Maven project, or creating a custom build script that manually pulls the 2nd project's dependencies from somewhere. (I think that Ivy could help you with that ... assuming you use Ant in the 2nd project.)

Build Path Issue

In Eclipse we have a project where we reference an external jar in the build path. When I upload my project to the repository and my colleagues check it out, the build path looks for the jar file in the same place. One of us uses a Mac so doesn't even have a C: drive and my other colleague has a different partition containing the jar, so it always breaks.
How do we fix this issue? Ideally the jar file would be included as part of the project but it seems that the svn commit doesn't include the referenced library.
Thanks
I would suggest you use a build tool (maven, ant/ivy, gradle, etc) along with a repository manager (such as nexus or archiva), depending on what you use to build your project. These store libraries in a central location(s) and then users get the libraries from there.
In eclipse, when you include your .classpath file in the checkin, you will have the issues you are describing, since the .classpath file will contain the path to the file, and then you all must have the files in the same locations. A workaround for this is to create a "lib" directory and put all of the libraries in there. Each of the users can then add all of the libraries in that directory to their path (but do not checkin the .classpath file). This is an older way of doing things before the concept of dependency managers.
Add the jar as part of the project (say in a lib folder in your project) and commit it to svn.
Start using Maven, to resolve your dependencies.
Worst case : Commit the external jar into another project called MyProjectDependencies
You can use Apache Maven to avoid incident like this and to get many others pluses.
You can find many guides on maven, for example this one.
Eclipse has integration with maven.
1.) Check in JAR in a directory inside the project.
2.) Use Maven (or something similar) to manage your dependencies.
3.) Create a User Library referencing the JAR and refer to it this way in your project. Each user will need to create the User Library in their install of Eclipse, but it sounds like you're already doing something similar by referencing the library externally anyway.
if you don't want to use a dependency management tool like Maven, a simple solution in your case would be to use an Eclipse Classpath Variable. All projects can reference the variable, but it will have a different value for each developer.
Set up a Classpath Variable with:
Right click on the Project, select Project Properties
Click Add Variable
Configure Variables
New...
Name the variable and point to a Folder
Now commit your .classpath file. The variable will be referenced in the .classpath. Each developer can configure to their particular directory, and Extend the variable to a specific jar file.

Ignoring files from Android APK

Is it possible to ignore files from being packaged into the Android APK? For instance, I have my .psd files in the same folder as their .png counterparts, and all the .psd files get packaged up.
I know I can move them outside of the folder, but I like having them in all together and would prefer not to if possible
This is actually supported in the Android Asset Packaging Tool (AAPT).
I always put my psd-like files in the resource directories like this:
/res/drawable/_pre_production/ic_launcher.psd
Any _pre_production directory will not be added to the APK.
With this approach they're in a sub-directory of the actual images' directory, but I don't see the problem with that. It is still neatly organized. ;)
An Ant script will do the trick. If you are using proguard, even that script may be good enough for u.
Use the Maven Android Plugin and declare your resources with a matching pattern that excluded the relevant file types you dont want added (e.g. */.psd). Check out the documentation for the resource plugin and look at the Maven Android Plugin Samples project .. specifically the MorseFlash application I created and the resource plugin related setup.
You can try using the maven android plugin and adding some logic to the build phase.
If you are using Eclipse, right-click the file and select "Exclude from build path"

Adding plugin.jar to the build path in eclipse in a machine indepenent way

I'm working on a project that uses JSObject from the jre's plugin.jar, which isn't included in the build path normally. I can get things to compile fine by adding the jar to the classpath. Currently I'm doing this in eclipse via Project->Configure Build Path->Libraries->Add External JARs... -> find the jar in jdk/jre/lib/plugin.jar. This results in a machine specific path in my .classpath file (like C:/Program Files/Java/jdk1.6.0_16/jre/lib/plugin.jar). Checking this into our repository obviously breaks the build for developers with different Java install paths or non-windows operating systems. Is there a way to add jars from the system library using relative paths?
I don't know if it's the "right way", but I solve this by creating a named "user" library, like "LIVE_CONNECT", whose sole content is the plugin.jar. Each developer will still have to configure their own workspace to have such a user library, but at least it will kind of document itself!

Categories