I have built a Java application that has some dependencies (~10). I would like to easily package this application up and deploy it as a single file to a CD or USB drive.
There doesn't seem to be any "nice" wizard to search the project, grab the dependencies and setup the classpath on the target computer. I have to do this manually.
Is there a better way? Something simple, easy and straight-forward. A link to a tutorial on this would be great.
Seems to me that this should be a built-in feature to eclipse. Deployment of a web application seems easy enough, but not a Java application.
Have a look at the Fat Jar Plug-In.
That's because desktop deployment isn't well defined.
You are heading into release issues which is a huge can of worms.
I assume you have some form of version control like SVN or git? If so check out maven with the release plugin and maven-assembly-plugin
It'll take a lot of work to setup, but once you get it going you'll be cross linking and deploying distribution packages in no time!
Plus you'll have access to the vast maven repos on the web right now
Related
I'm used to Visual Studio, so Eclipse is very new for me.
I have to start (ASAP) developing a project that contains 3 subprojects:
1 - Business logic library with Hibernate support
2 - JavaFX configuration utility
3 - Spring MVC app with a lot of JavaScript inside
2 and 3 use 1 as a core.
I've tried to google manual but all of them were about parts of this task, nothing about the complete solution.
I can create all 3 projects and put them in same subdirs in a solution directory. But how to connect them to core lib? Maven looks great for it, but I can't explain him how modules have to be connected.
How to make such a structure?
At the risk of being shot down in flames, in my opinion Eclipse does not handle structured projects as well as Visual Studio. (I program Java/Eclipse at work and use VS aka Atmel Studio at home for hobbyist C++/Arduino projects).
In Eclipse, I have found to best to check out each component to the top level and compile each component separately (mvn clean install). The output of this is generally a .jar file that will be installed in your local maven repository. You then list that jar as a dependency in the pom.xml file of the higher-level components.
I suggest you install M2Eclipse or some other Maven client into Eclipse. They are not perfect, but are far more productive than doing everything manually.in my opinion.
Also Eclipse supports multiple workspaces quite well. One workspace per major multi-component project works well.
I do have own developed Java library (MyLib), which I later publish on private Maven repository and have it as Maven dependency in another webapp project (MyWebapp). If I have both projects - MyLib and MyWebapp at the same time opened in Eclipse - is there a way somehow to configure MyWebapp so, that local changes made to MyLib would be directly added to MyWebapp while building/deploying it? The issue is that during development it is not really comfortable always to make some changes in MyLib, make a build, deploy to Maven repository and then make a MyWebapp build, deploy it and only then I can see how the changes are affecting the webapp project...
I would like to reduce the overhead while developing and willing to see how changes are working out. Of course when it comes to real releases the above described flow does really make sense and works great.
Thanks!
There is no simple "just tick this option" solution, unfortunately. You can chose between these options:
Convert MyLib into a Maven module and add it to the sources of MyWebapp. This, of course, will make it harder later to reuse the library alone.
Stop deploying the application. If you look at the classpath in Eclipse, m2e should have added the dependency as a project from the workspace (instead of depending on the JAR in the repository). If not: There is an option for this.
The next step is to create another project which depends on Jetty and MyWebapp. Create a Java application in there (i.e. a file with main()) which creates a Jetty server and configure it to use the current classpath. That way, you can start the webapp just like any other Java application without deploying - Jetty will simply load classes from the classpath that m2e assembled.
I am a newbie to J2EE and I am not able to understand the directory structure created on building the java web project. After bit of googling i understood what we store in WEB-INF but
1)i am not able to understand that what we store in META-INF ?
2)how target folder get created?
3)where we mention that what all files should be placed in target folder?
I am using Maven to build the project which is a spring-hibernate based project.
thanks in advance
1) What's the purpose of META-INF?
2) Maven creates the target folder for you. It's where all of the Maven plugins dump their work by default.
3) Maven has mechanisms for excluding files from it.
The key to understanding Maven is that Maven works on conventions. That means that Maven will do a lot of things really well with almost no effort on your part if you structure your project according to Maven's expectations. For example, this is how you differentiate between Java classes and resources in the source directory:
src/main/java/com/mycompany/MyObj.java
src/main/resources/my/company/spring.context.xml
src/test/java/com/mycompany/MyObjTest.java
src/test/resources/my/company/spring.context.xml
When you run mvn test it will compile all of that, move it appropriately over to the target folder, load the JUnit runner and give you a classpath that will let Spring have easy access to the spring context under the test folder. It'll run the tests and drop the reports under target.
Maven is not like Ant. In Ant, you have to tell it everything. Maven works on the opposite end in that it assumes everything by default until you tell it otherwise.
This is a common problem because java has grown so big. Its often hard to tell where one technology ends and another begins. You need to familiarize yourself with the documentation for all the various components you are using.
For instance, if you have a 'target' folder then I assume you are using maven. Maven is a java utility used for dependency management. When you 'mavenize' a project, you agree to adhere to a bunch of standards and maven in turn does a lot of the grunt work for you(compiling code, finding dependent libraries, and running tests). Part of what maven does is create standard maven directories in this case 'target'
more maven info - http://maven.apache.org/
As for META-INF this is part of the Java EE spec. It does have a purpose concerning packaging and deployment, but you'll generally not finding yourself using it very often. Its generally the same principle as maven. You adhere to the Java EE standard and the Java EE compliant tools do most of the work for you.
For more info look at this link - http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/packaging_deployment/index.html
In general to understand these you should check out some tutorials on Java EE and refer to your container's examples and documentation.
1) What is the purpose of the META-INF
2-3)Target folder creates Macven, it manages all dependensies, etc: one, two
Perhaps the reason I stalled learning Java until now is because I HATE how Java handles external libraries. I'm stuck keeping them in one place, adding them individually, fixing problems with versioning and every time I move/rename them, and copying and writing the classpath over and over each time I release a Java application.
There has to be an elegant solution to all of this. I keep all of my libraries (regardless of task, platform, or other) in their own little folder inside a "lib" folder in my development folder, kind of like this:
Dev
-lib
+JS-jQuery
+Flex-Degrafa
-Java-Xerces
+Xerces-1.2.3
+More libraries
I can use either Netbeans or Eclipse for Java dev, but none of them provide a very streamlined (and not to mention idiot-proof) way of managing all of these.
A nudge in the right direction or an online article/tutorial on this would be greatly appreciated.
You can either use Ant + Ivy or Maven to manage your library dependencies.
If it is only dependency management you're after and you're happy with the rest of your build process, I would use Ivy, as it can unobtrusively manage your dependencies, leaving your existing build process intact. There is a plugin for Eclipse called IvyIDE that contributes your dependencies via a classpath container.
Maven 2 has a steeper learning curve but provides a much richer set of functionality for building your projects and Eclipse integration through m2eclipse or IAM.
Personally I use Maven as I have a large number of projects to work with and Maven is particularly suited to efficient development across lots of projects.
Have a look at the introductory documentation to see what works for you.
Ivy Tutorial
Maven Getting Started Guide
Netbeans 6.7.1's Maven support is quite good and comes out of the box with the IDE.
The Eclipse addon was frustrating enough that I gave Netbeans another try.
A third choice besides ChssPly76's options is to use Ant with the Maven Ant Tasks. I don't know if I'd call any of these solutions particularly "elegant," but they do spare you the need to manage your own lib/ directory and classpath variables.
If you're working on Linux you can install Java libraries with APT or RPM.
Otherwise, I normally check precompiled JARs into a lib directory in my project's version control repository and make sure the names of the JAR files include full version information. E.g. lib/foo-1.5.6.jar, not lib/foo.jar.
To avoid having to manually set the classpath before running your app, you can set the classpath in the Manifests of the JARs themselves to define the dependencies of each JAR file. The JVM will follow all the dependencies when loading classes.
Maven is often more trouble than it's worth, but the ability to open a maven project directly into IDEs such as IntelliJ is excellent. For example, IntelliJ will download all dependencies and have them available without having to run a build first, or an mvn command and then a project refresh. It also isn't necessary to re-generate the project every time a dependency is added. I work with a number of Eclipse developers who switched to IntelliJ for this alone.
However, one shortfall of Maven is that many libraries (or versions of libraries) are not available on public repositories. Therefore it is often necessary to set up a local repository such as archiva. In ant, it would just be a matter of adding it to the lib directory in the repository.
Maven can also attack when you need to do something that maven doesn't directly support via a plugin. What would normally be a few lines of ant can often turn into a morning's worth of work.
Finally, buildr is an excellent way of using Maven's dependency management and plugins, while also supporting ad-hoc tasks.
I need to have a Java EE project generate a WAR file automatically - preferably exploded - as opposed to choosing Export -> War file.
I have played with the various server definitions but have not been able to get either the Java EE preview or the HTTP server to work, and before installing each of the external container specific servers I'd like to hear if anybody has made this work.
So, question is: Which steps to take to have a WAR deployment automatically created and maintained by Eclipse?
EDIT: This is Eclipse 3.5 Java EE, and it is a Dynamic Web project in Eclipse. I want the WAR file/tree to be easily copyable to a network drive to be accessible for the target host. It runs an embedded Jetty, but I am interested in the generic WAR.
MyEclipse can do this, but we are standardizing on plain Eclipse.
EDIT: This particular web application will run inside an embedded Jetty. Since this question was asked we have found empirically that we need to have the complete tree containing the application with embedded Jetty, war file (exploded) and all built by the Hudson server in order to avoid human steps in the build-deploy-process. The answer for us therefore is scripting with ant (using ant4eclipse).
EDIT 2012: The ant4eclipse approach proved to be generally too inflexible and fragile in the long run, so we have switched to Maven. This solved very many problems, this one included.
Make an ant task to build the war (and copy if you like). Then add an Ant builder to the project (project -> properties -> builders). As long as your project is configured to build automatically the war will always be upto date.
This would equally work with maven, or pretty much any other build tool.
You should be able to do this with "File" -> "Export", scroll down to "Web" -> "WAR File" and follow the instructions
Have a look at this question. It refers to 3.2 version, but I believe that it still holds, until up to 3.4 version at least. It seems there is no automatic way of doing the Export - War thing.
Consider the solution given by Pablojim and drop the Export facility.