Use maven + yguard - java

Has anybody used maven and yguard for obfuscating jar files?How to do so?

I have done obfuscation using yguard in Maven. I have used the maven ant run plugin to run the ant tasks.
Steps:
Refer to the build.xml in your pom.xml. Check documentation of Maven Antrun plugin. You have a lot of examples there.
Create the build.xml with the rename elements as required by your project/jar. In case you want to refer to the Maven references like project information, define them as properties in your pom.xml before the ant task is executed
Please let me know if this answers your question

Related

Ant use Maven's library

I wrote a project which use maven. It's good for me.
But, some other people don't have maven, so I am trying to write an ant build.xml for them.
My question is:
Inside "javac" -> "classpath" tag, how could ant get the libs I used in the project from maven? So that could compile & pack all the 3rd-party libs into release via ant.
Is this possible or there are better solution for maven & ant exists in same project.
Ant combined with Ivy is your answer. Ant can use a Maven repository to pull in jars, and can even be made to output a pom.xml, so the jar can be deployed back to a Maven repository.
I have an ivy.dir project on Github that I use to help integrate Ivy into already existing Ant tasks -- especially if they use Subversion as a version control system. You can create a ivy.dir subproject, and make that an external on the Ant project.
Have a look at ivy. Use it to download your dependencies for ant from a maven repository.

Running a Maven project with many dependencies

I'm hacking on a Maven-based project with a lot of dependencies; the project is normally meant to be developed in Eclipse but I need to work on it from the command line.
How to build+execute the project in a sane way? Something like mvn run, but of course Maven is not meant for running Java projects (for some reason).
The problem is specifying all the dependencies on java's commandline, I don't even know how to autogenerate that. I can currently deal with it using the assembly:single maven plugin (using the jar-with-dependencies descriptor) which will package the dependencies to a single .jar for me.
However, there really is a lot of dependencies and the assembly phase can take about two minutes, greatly disrupting my hack-test cycles so I'm looking for other ways to run the project with minimum build overhead - any recommendations, please?
Note: One possibility is running it in Eclipse once and capturing the java commandline. However, that's just a one-time hack, not a general solution in case I change pom.xml later or come to another project from the suite without Eclipse access anymore.
Have a look at the maven exec plugin
mvn exec:java -Dexec.mainClass="com.example.Main"
if you do this frequently, you can of course configure it via plugin configuration.
Regarding finding out project dependencies - you can use maven dependency plugin
http://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html
If you want to put them into file it'd be smth like
mvn dependency:list > dependencies.txt
See this question: How can I create an executable JAR with dependencies using Maven?. You can use the dependency-plugin to generate all dependencies in a separate directory before the package phase and then include that in the classpath of the manifest.
I see three solution to this:
onejar-maven-plugin - faster than assemlby with jar-with-dependencies descriptor
With onejar-maven-plugin, you'll (...) get a nice clean super jar with the dependency jars inside.
Spring Boot Maven Plugin - but this is dedicated to Spring projects
Maven Assembly Plugin with custom descriptor. This custom descriptor should grab all dependencies into lib folder, maven-jar-plugin should set Class-Path in Manifest.fm according to this new location. After this you can simply execute your program or zip your jar with lib folder as distribution.
After this is possible to run your program on your computer or any other with one command:
java -jar myjar.jar

How can I retrieve the classpath string from my Eclipse project that uses Maven?

How can I retrieve the classpath string from my Eclipse project that uses Maven? In eclipse , I have more than 100 .jar files imported via Maven and refrences as a library called "Maven Dependencies". How can I retrieve the "effective" classpath in the form of a string in my project?
The .classpath file does not reveal this.
You can try to use the java development toolkit (JDT) in Eclipse. The class JavaCore in the org.eclipse.jdt.core plugin can take a reference to your java project (an IProject) and return an IJavaProject which adds the behavior of knowing stuff about the classpath. Maven provides a classpath container that should also collaborate with the IJavaProject to answer back the actual source folders and jars on the classpath. Can't provide with any more info off the top of my head, but I think this approach is your only hope.
Unless you write an eclipse plugin that extends the maven plugin. Documentation is sketchy at best, but in theory you can write an extension that is asked to tweak the contents of the maven container in your project's class path. If at that time you were to cache information about the container contents off to your plugin's state folder, you'd be able to reference it when the user wants you to invoke your script. This extension would be invoked whenever maven is asked to update project configuration or dependencies.
I understand that you want to execute that script yourself and you have Maven installed. I guess the easiest way to run your application in this case is to use the Maven Exec Plugin:
http://mojo.codehaus.org/exec-maven-plugin/
(I'm usually using the exec:exec goal to run the application in its own process.)
Edit:
Otherwise have a look at the Maven Dependency Plugin to prepare the classpath if you don't want to use the Maven Exec Plugin:
http://maven.apache.org/plugins/maven-dependency-plugin/

Eclipse maven to manage only dependencies and nothing more

Is it possible for maven plugin to manage only dependencies and nothing more.
I work with "strange" maven project, and want Eclipse/maven plugin only to read dependencies from pom.xml and add it to project classpath. And nothing more.
I don't want it to set exclusion filters, source folders and output folders, or to overwrite other dependencies.
Also, pom.xml is not located in the source folder of Eclipse project. I know I could use mvn eclipse:eclipse task manually, but it mess with my .classpath and .project files, which I don't want to merge manually.
To summary, I want that all dependencies from pom.xml are automatically managed by plugin, but for plugin not to touch anything else.
EDIT: The problem is that whenever something in pom.xml changes, maven plugin changes my project configuration.
EDIT: It has to be maven since there is already pom.xml which I can replace with sbt or ivy or lein or anything eles.
Does it have to be maven? If you don't need any of the plugins, or project organisation you could use apache ivy instead.
Or you could use a even more simple one like SBT
if you have to use maven, just strip out the plugins from the pom.xml file and only add the dependencies and repos and use an IDE to launch the aplication or create a jar.
you will need to run mvn commands thought if you change the dependencies.

Generating a Maven POM from an existing project?

Do any of the IDEs (or any other tool for that matter) have the ability to generate a POM based on an existing project?
I ended up generating the POM with a Maven archetype as Peter and Sal suggested and then moving the existing source in. Thanks for the help guys.
One way to do this it to create a template project via maven archetype then move your existing code to the template. I would recommend this only for really simple projects. It would work something like this.
mvn archetype:generate
mv src/* src/main/java
mv test/* src/test/java
mvn package
You'll get errors. To add the missing dependencies, go here: http://www.mvnrepository.com/ and start looking them up. If you pick an archetype close to what you need, you'll be half way there.
Once it all works.
svn commit -m "hacky maven port"
You can do this in IntelliJ, but the POM it generates may be more complex than if you write by hand. If your project is currently in JBuilder or Eclipse you can import this first.
Instead I would suggest you describe your project in a POM and use it to generate your project information. You can do this for eclipse and idea (and I assume other IDEs)
Your existing project probably does not use Maven, so creating a POM based on it isn't trivial.
The simplest way I can think of is to get the Maven plugin for Eclipse, generate a new maven project and then add your code.
You'll also need to manage external jars using Maven's method. In this case, they would probably be system jars.
In eclipse Galileo if you have the maven2 plugin you can select the project and then right click and go down to Maven2 in the context menu and there should be an option to convert the project to a maven project.

Categories

Resources