I have a Java project which is separated into 23 sub-projects that are all checked into a subversion repository. When they are checked out (not using the Eclipse SVN tool) there's a .svn directory on several levels of each sub-project. Then I run mvn eclipse:clean eclipse:eclipse on the whole thing (as these are Maven projects) I can import them into Eclipse and work there. So far, so good.
Here's the problem: When I deploy the project to Tomcat in Eclipse (oh yes, it's a web project) the .svn directories are also deployed. I can circumvent this by adding Resource filters in Eclipse (project properties -> Resource -> Resource Filters -> Add -> Exclude all, Files and folders, All children (recursive), Project Relative Path matches **/.svn) but every time I recreate the projects with maven (which I have to do ever so often) I have to recreate the filters for each of the 23 projects. Is there a better method to exclude resources for the tomcat deployment?
Note: I'm using
Java 1.6,
Eclipse Juno,
Tortoise SVN 1.7.6 (which comes with Subversion 1.7.4),
Maven 3.0.3 and
Tomcat 7.0.35
I am, sadly, not allowed to update anything. An ideal solution for me would be something like a global resource filter in Eclipse or some setting which would make Maven create Eclipse projects with such resource filters already set.
if you have the option to change the pom.xml, then I would expect that you can use sourceExcludes. That would be the automated version of your manual handlings.
There's also an example with svn files:
http://maven.apache.org/plugins/maven-eclipse-plugin/examples/specifying-source-path-inclusions-and-exclusions.html
Just use latest svn client - it will create only one .svn folder at parent folder.
Also, latest eclipse can import maven project without mvn eclipse:eclipse.
Related
I am trying to build a spring-mvc project that has another project (core, as .jar) as dependency.
If I disable "Resolve dependencies from workspace projects" in eclipse, install the core into my maven repo and run it from eclipse, the application works!
What I want to do, is re enable "Resolve dependencies from workspace projects", but there is the problem: When I try to run the project on tomcat (after maven clean, project clean), I get a "FileNotFoundException". The file in question is under src/main/resources/META-INF/spring/applicationContext-core.xml
It seems, the File can not be found in the classpath.
I looked up the deployment location and found out, that everything of the core is under the following folders:
WEB-INF
classes
So the file I am missing can be found here:
/WEB-INF/classes/META-INF/spring/applicationContext-core.xml
But it schould be here:
/META-INF/spring/applicationContext-core.xml
Why is the structure of my core dependency so messed up when I enable the workspace resolution and how can I fix this?
I am using eclipse mars with m2e..
Thanks for any help.
Edit:
Project structure (core) looks like this:
project structure
I am using Eclipse Kepler for Java. Normally you can add internal/external .jars to a Java project in the build path located in the properties. Why, when I clone a git repo and import it into my projects, do I lose that ability? I don't understand. I kinda need to do that.
This is probably because the .gitignore has been configured to ignore .jar
Open the .gitignore file and remove the line *.jar, you should be able to add it.
======
As an aside - usually, for Java projects .jar files are not committed to repository (as they are large & it can slow down repository cloning), instead maven or gradle is used to configure dependencies. Example - http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/
Then when you want to work with eclipse just run mvn eclipse:eclipse to generate the necessary files. .gitgnore is usually set up to ignore *.class, *.jar, .project, .settings, .classpath
I found that if you open the run configurations and go to the Classpath tab that you can add internal/external .jars. The run configuration can be accessed by clicking Run > Run configurations. I added my .jar to the user entries. The bootstrap entry caused a null pointer.
When a project relies on libraries/modules, it's best to use a build tool for dependency management. JVM ecosystem is dominated with three build tools: Gradle, Maven and Ant.
How it works:
In a build script we declare dependencies of the project. This tells the build tool where to retrieve libraries/modules our project depends on. Dependencies are resolved at runtime; downloaded from a remote repository, retrieved from a local directory or if required another project to be built in a multi-project setting.
I have a fine running project that uses Maven for dependency management. The project itself is run by eclipse (Run As...).
In the project menu > Deployment Assembly, I have included the MAVEN_REPO.
Problem: when I run the project, everything gets copied correctly to war/WEB-INF/lib.
BUT I'm constantly getting an error that PersistenceProvider cannot be found.
IF I copy manually all libraries from deployed war dir to src/main/webapp/WEB-INF/lib, and then restart the application, everthing works fine!
So I can conclude that my jpa/hibernate config in general is fine.
But how can I come over the need to add all libraries manually to the src lib folder?
So, when you do 'Run As - Web Applicaiton' eclipse/google plugin uses the War directory path you specify. To change this, you right click on your project, and select properties. Then under the google drop down, select 'Web Applicaiton'. There, you can edit the 'WAR directory' path. this is probably set to src/main/webapp, which is NOT what you want.
When maven builds your war, it takes all built class files and libraries, and packages them into the target directory. This is the directory you want to use as the 'War directory'. This will be something like '/target/myappname-1.0.0'
Sidenote: If you are using gwt/maven, you'll probably want to use the command 'mvn gwt:run' versus running using the google/eclipse plugin. This allows maven to do some work (like resolve dependencies) before the dev server is run.
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.
(Am a maven noob)
Have a maven built webapp which uses spring, etc.
When I run "mvn clean install", it generates a .war file in the target directory.
I copy the .WAR file to tomcat for deploying the app.
Debug the app
Edit the code
This process takes a lot of time. When I earlier used ant, I would point tomcat's server.xml to my webapps directory. Also, Eclipse would put all of its classfiles in my webapp\WEB-INF\classes folder. If I had to modify any JSPs, I would just edit and there was no need of additional copying. If I modified a .java file, Eclipse would build it and put the .class file in the WEB-INF\classes folder so that Tomcat would pick it up.
Now, each time I make changes to a .jsp, I need to manually copy the .jsp to tomcat's webapps directory. Isn't there a way that a maven built app can optimize this process ?
So, where do you point your tomcat at that makes development productive?
project (where pom.xml resides)
src
main
java
resources
webapp
WEB-INF
target
webapp
webapp.war
Basically, I would like to know how to configure eclipse(3.7.1) and tomcat/maven so that the edit/deploy/debug cycle is really fast.
UPDATE1
1) I was able to get m2e(http://download.eclipse.org/technology/m2e/releases/) installed in indigo(v. 3.7.1 of eclipse). it had 2 components
a) maven integration for eclipse
b) slf4j logging
It installed successfully asking me to restart eclipse. I restarted.
2) Next, I installed m2e-wtp (at http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/)
It had 3 components
a) maven integration for eclipse
b) maven integration for eclipse Extras
c) maven integration for WTP.
When I selected all 3, I got some error. So, I unselected the 1st two and only selected the 3rd one and then it installed successfully asking me to restart eclipse. I restarted.
#Raghuram
I ran the 4 steps that you suggested below. Only the 4th step resulted in an error and my webapp could not get deployed. It resulted in an error "File not found --- .svn/.wcprops/.
http://i.imgur.com/Pg1aq.png
What should I make of it ?
Thanks again,
I'd recommend you to use cargo to deploy automatically to a local container (that can be downloaded and started)
Maven+Cargo
Then having that started with jpa activated (so that you can remotly debug your code) you just have to attach a listener and debug from eclipse, intellij, whatever.
For JSP, talking Intellij, you must tell your IDE where to package files (right-click 'package file") which is done in the project setup (output classes dir in WEB-INF/classes)
Check Tomcat 7 - Maven Plugin? for an example cargo configuration for Tomcat 7. After the confiuration is valid you can deploy to your Container using mvn cargo:deploy and mvn cargo:redeploy
If you use Eclipse Indigo with m2e and m2e-wtp, you can pretty much develop and debug your web application without any manual step.
Add tomcat as a server in Eclipse
Import your maven project as a maven project in Eclipse.
Build the project (using Eclipse or using maven)
Choose "Run as server...".
Eclipse will pretty much take care of hot deploying jsps as well as classes on changes.