For example I have a regular Java project and multiple EAR projects JSF + EJB inside EAR. Each EAR project has as a dependency, my Java project, for example it might be a library of composite JSF components.
Is it possible to define that when I exporting an EAR project it will compile depended Java project into jar and put it as a library inside EAR\libs?
Same thing regarding committing project via RTC, now I need manually build jar and add it to my EAR project, is it possible to do it automatically?
RTC wouldn't provide any additional compilation feature compared to the platform (Eclipse) it is installed on.
It does provide however RTC Builds, and you could use that task scheduler to, on demand, trigger the compilation of the Java project and its import into the ear/libs.
That supposes first that you can do those tasks in a script (using any scripting technique you want: ant, maven shell, bash, anything).
Then you can define a build definition using that script.
Related
I created a Java project called TotalBeginner, and exported as a jar. I then reference it in a desktop app with a SWT GUI, called MyLibrary. I now want to be able to run MyLibrary outside of the Eclipse IDE (I am running Luna 4.4.0). In following the advice of other answers to questions on Stack Overflow, I export as Runnable JAR File. I pick "Package required libraries into generated JAR" - so if I understand correctly, referenced libraries like TotalBeginner.jar should be included in the MyLibrary.jar, correct? However, when I run it, it returns to the command prompt with absolutely nothing appearing to happen. Task Manager (Windows 7) shows no Javaw process. What am I missing? Thanks.
C:\Users\jimerman\>javaw -jar MyLibrary-app.jar
C:\Users\jimerman\>_
No errors, no dialogs.
I suspect in your JAR you only have classes of your own project (which is fine in fact) and you haven't put all dependent JARs in classpath (As it is complaining for unable to find org/eclipse/swt/events/DisposeListener)
It may be tedious to find out all dependent JARs and put it in classpath of java command manually.
Consider making use of build tools like Maven and Gradle, which will save you trouble in collecting dependencies, and there are plugins for them to help you to construct artifacts that makes execution easier.
For example by using Maven, what you need is to prepare a POM, put SWT (and other dependencies) as dependencies of your project.
Then by making use of shade, appassembler or assembly plugins, you can easily have a uber-jar that contains all dependencies, or have a zip files that all dependencies are put in a specific directory and you can easily execute using generated command.
Sorry, I'm very new to java servlets. I have an existing java package (that I built and ran in eclipse, did not compile) that runs fine on its own. I have a sample servlet in another folder. I'd like to compile all of this so it can run on a tomcat server. I know a javac will compile a class, but which one do I compile if this is a servlet AND another package? Do I have to list ALL classes, can I list just the package names? Do I need to create a single .war file or multiple .war/.jar files?
Sorry, my use of Java up to now has been in Eclipse. I can compile and run a single class, but a complex environment with multiple packages with a target platform of tomcat is leaving me lost as to 'where I begin.
You can do following:
1) First project should be able to create a jar file.
2) In the Second project ( Servlet) ,you can right click on the folder of the dynamic web project( I assume you have created it as DWP) , and click Properties --> Deployment assembly. Here you can add reference to other projects and external jars.
3) Once you are able to do this setup, you can try 'exporting' your second project as war.
This is just a naive way to start as I do not want you to overwhelm with complexity of multi module development for a beginner. But will point you to m2e plugin in eclipse for something called "Dependency Management" . This plugin will help you manage much more bigger and complex projects. Do spend some time on http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/ to understand maven and how to it works before attempting Maven in eclipse with m2e plugin.
I'm working with some very old, monolithic software that is basically a heavily customized JBoss deployment. Unfortunately, this means that JBoss can't be started from the "Servers" view in Eclipse, it must be started as a Windows service or via the command line. There are multiple WARs/EARs, but the WAR classloaders are rarely used and most of the actual class files are located in jboss/shared/lib as .jars.
We need a way to run a Maven build in Eclipse (via m2e) and deploy the class files in the resulting .jar to C:/product/jboss/shared/lib so that when we start JBoss, we can use Eclipse to debug (as a remote java application). Ideally, the artifact that Maven pushes will not overwrite the existing .jar file that was originally installed. For example, if the Maven project builds an artifact named myjar-1.0.0.jar, we need a way to deploy the classes inside of myjar-1.0.0.jar to C:/product/jboss/shared/lib/classes so that they are picked up by the classloader prior to C:/product/jboss/shared/lib/myjar-1.0.0.jar, which was installed with the product.
Currently, our (very hacky) solution is this:
Under the project configuration's Java Build Path > Source tab, we use the "symlink" functionality under Advanced to map the Default Output Directory (e.g. project/target/classes) to a class folder (e.g. C:/product/jboss/shared/lib/classFolder). This modifies the .project file, which is checked into source control.
We build the project normally with a m2e launcher (e.g. clean install).
Assuming the Maven build is successful, we run an Eclipse project build. This pushes the class files to C:/product/jboss/shared/lib/classFolder:
We restart JBoss. Since classFolders take precedence over jars, JBoss will load the classes in C:/product/jboss/shared/lib/classFolder, which are identical to the classes in our Eclipse workspace.
We attach to JBoss and debug the project as a remote java application.
Pros:
We're able to push our new classes to JBoss and test them without backing up the original jars and copy/pasting the new ones by hand (jar hell).
Cons:
We're compiling twice -- once with the maven-compiler-plugin, and
once with an Eclipse project build (Java Builder).
The symlink functionality is hit or miss in my experience. Sometimes we need to
do the refresh project/close project/build project dance to get it to
work.
Is there a better way to do this? I cannot force them to restructure the project so heavily that all deployables are container-agnostic WARs, but our developers need to be able to make changes and quickly test them without manually copy/pasting .jars.
How old is old?
Have you looked at the Cargo plugin?
http://cargo.codehaus.org/Quick+start
It can deploy to JBoss 3.x.
It has a Java API so you should be able to write something to extend it to do what you want.
Why are you trying to deploying classes instead of jar files?
You can still remote debug via Eclipse with jar files.
Worst case scenario - use Ant.
Maven is not designed for this kind of stuff, trying to force it to work will just cause you pain.
Once you have got Maven generated the right artifacts, work out what you would do manually and then script it via Ant.
I would try looking at the maven-dependency-plugin which has the possibility of copying artifacts to different location.
Please check your Deployment Assembly (project -> properties -> Deployment Assembly) and verify if your maven libs are there.
I have let's say 4 eclipse projects.
Each references some other until one contains the actual main application.
Meaning that the idea is that each eclipse project is meant to be a library for a main application.
Each eclipse project references some other libraries e.g. spring, commons etc.
My question is the following:
I could write I guess some ant script that copies all the jars to a directory and builds the projects until we get the deliverable that has the classpath configured but is it possible to do something like this automatically via Eclipse?
I tried for example to do export as runnable jar and did not work.
All the referenced jar was not exported.
So is there some automatic way via eclipse or is ant the only option?
UPDATE:
I have no problem running the application inside Eclipse.The main eclipse project has references to the other projects it needs. My problem is the delivery of the application.
I.e. some runnable jar that runs standalone
Yes, you can do this, and you don't have to export any jars. When you modify the build path in eclipse (Build Path --> Properties), there is a section for referenced projects. Add the projects you need to reference to the main project and eclipse will treat them as dependencies.
So I started with a web services project (just a dynamic web project) that builds and debugs correctly from eclipse. We've pulled a chunk of common code out that we want to put into a shared library so now those classes are going into a separate jar project that the web project references.
On the web project, I did Project->Properties->Java Build Path->Projects->Add and added the jar project. And this correctly solved all the compile-time classpath problems and everything builds fine. But at runtime, when the tomcat server fires up, spring attempts to inject some of the classes contained in the jar file and I get a NoClassDefFoundError.
My .class and properties files and the contents of my META-INF directory are showing up in the ./build directory, but my WEB-INF/lib directory seems to be referenced in-place, and the jar dependency doesn't get copied in to it to show up as part of the Web App Library.
What is the magical incantation to tell eclipse that the other jar project needs to be available to tomcat at runtime? From our ant build script, we first just build the other project into WEB-INF/lib and everything works fine, but not for eclipse debugging.
I figured this out after spending some time on it. If you are in Eclipse Helios , go to properties > deployment assembly > add > project and select the dependent project you wish to add.
Java EE module dependencies would solve this problem.
You have already done the task of extracting your common classes into its own project, possibly because other projects depend on these classes. Either way, you'll have to ensure that this is a Utility project (appears under Java EE in the project wizards), and not just a plain Java project.
One that is done, you can proceed to add the Utility project to your build path (compile-time path) as you have figured out.
The additional (final) step is to establish a Java EE module dependency between your Dynamic Web project and the shared library, which causes the utility's classes to be placed in WEB-INF\lib during deployment, and even during export of the WAR. To do so, visit the dynamic web project's properties, and browse to the Java EE module dependencies. Ensure that your utility project is selected here. Redeploy/publish your application and you should be good to go.