Suppose that I have a small web application (war) which requires 2 jar files; libA.jar and libB.jar. I want to include both of them on build but exclude libB.jar on deploy, since it's already within the classpath of the server.
Is it possible to do that in IntelliJ 13? Note that I am not using any build tools (i.e. Ant, Maven, ...etc).
Try to use scope provided for library libB.jar in tab "Dependencies" of your module.
Related
I have a spring project and it is running well. The problem is, whenever I perform a new deployment using the war file in tomcat, I need to manually copy the libraries in the lib folder. I am wondering if there is any way to add those libraries inside the war file so that every time I don't need to waste my time by copying the libraries in the server. It needs to be automatically included from the generated war file.
This answer depends on how you are building your WAR but I assume you are using one of the popular build tools for Java. Given that your war does not have a populated lib folder I'm assuming you have either not configured the right plugins for these build tools or you are compiling and managing your classpath from the command line like a madman. If the later is the case then I highly suggest you start using a build tool for your projects (All IDE's do this by default), if the former is the case I refer you to the individual pages for the plugins:
Maven:
https://maven.apache.org/plugins/maven-war-plugin/index.html
The war plugin does this by default.
Gradle: https://docs.gradle.org/current/userguide/war_plugin.html
The War plugin for Gradle also does this by default.
Ant: https://ant.apache.org/manual/Tasks/war.html
A glossary reading for the Ant tasks did not reveal if it did so by default but I'm assuming it does.
My directory sturcture is,
C:\Grapher\src\ *.java
C:\Grapher\lib\ *.jar
There are many java files and many jar dependencies. I want to create a tomcat deployable WAR.
Can any one suggest me how to create a WAR using a gradle script? What are the dependencies to be included in Gradle to create a WAR.
Have you read and understood https://docs.gradle.org/current/userguide/war_plugin.html?
The War plugin adds two dependency configurations named providedCompile and providedRuntime. Those two configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. It is important to note that those provided configurations work transitively. Let's say you add commons-httpclient:commons-httpclient:3.0 to any of the provided configurations. This dependency has a dependency on commons-codec. Because this is a “provided” configuration, this means that neither of these dependencies will be added to your WAR, even if the commons-codec library is an explicit dependency of your compile configuration. If you don't want this transitive behavior, simply declare your provided dependencies like commons-httpclient:commons-httpclient:3.0#jar.
If you use providedCompile or providedRuntime, those dependencies will not be added to your war archive.
The folder structure you need to have in your project is:
app
|-src
|-main
|-java
|-webapp
In the java folder you add your own packages and classes. In the webapp folder you add web content if your application makes use of such items.
Hey I am trying to sbt compile a Scala project with 2 external .jar libraries as dependencies. I've added them in the /lib folder and I can see they are recognized by sbt when I run "show unmanagedClasspath" I see the 2 jars. However when I run "sbt assembly", sbt tries to resolve dependencies and fails when it can't download the libraries that are already there.
You don't need to add the jars that you've in the \lib directory again in libraryDependencies. libraryDependencies is part of your managedClasspath and everything in lib directory is part of your unmanagedClasspath, both together forms your dependencyClasspath.
You can see this by typing this on sbt prompt and checking the dependencies section:
inspect externalDependencyClasspath
In this case 'external' just means dependencies that are external to the project (ie not internal project dependencies)
I'm using IBM Integration Designer 7.5, which is a version of Eclipse 3.6 with some added features. I'm building a dynamic web project targeting Tomcat. The web project has a dependency on another project, a utility module.
I've configured the web project to include code from the utility module per this question and it works well. A WAR built from the web project includes a jar containing the class files from the utility module.
The problem is that the utility module includes some junit testcase classes, and they're being included in the jar that goes into the WAR. I'm looking for a way to leave out the junit classes.
In the utility module, the "real" code is in a folder called "src" and the test cases are in a second source folder called "test". I've gone to the Build path->Order and Export tab of the utility project, and it lists both "src" and "test" as exports. It's not possible to uncheck the box for the "test" entry. The eclipse documentation says that source folder are always exported from a project.
Is there a realistic way to fine-tune this setup so that the test cases aren't packaged into the web project?
Do you have the source for the utility modue? What are you using as a build tool? If the answer to the first question is yes and the answer to the second question is not Maven, then use Maven. By default it excludes anything in the src/test directory from the build artifact. You will need to either rearrange your project directories to be the Maven default, or do some configuration of your POM file so that Maven knows which is the test directory.
When using a Eclipse 3.7 Indigo for Java EE Developers, there is something called Deployment Assembly . I could find on google and understood that it is similar to the J2EE Module dependencies where in we could select the jar and which goes and sits in the EAR folder or in WEB-INF/lib in case of WAR. Now the doubt I have is,
I have a JavaProject Dependencies. I have added all the dependent Jars via classpath variable. Now the Dependencies Project is added as dependency to my Web Project TestWebProject. The compilation of the Web Project is correct but during runtime I get an error because some jar was not found. I could fix this my include jar in Deployment Assembly of Dependencies Project, which is a standalone project.
The question is that, why I had to fix the jar in deployment assembly since ,first, its a standalone project and second is if I would not have this deployment assembly , how could this be fixed?
I could find on google and understood that it is similar to the J2EE Module dependencies
It was called "J2EE Module Dependencies" until with Eclipse 3.5. After that version, it was renamed to "Deployment Assembly". But it's effectively the same in case of Java EE web projects.
The question is that, why I had to fix the jar in deployment assembly since its a standalone project
Because this way Eclipse will autobuild a JAR file of the project and put in /WEB-INF/lib of the web project's deployment. If you don't do that, the JAR isn't available during webapp's runtime, but only during compiletime and Eclipse expects that you've already built and placed it anywhere else in runtime classpath, e.g. server's own /lib.
if I would not have this deployment assembly , how could this be fixed?
Manually build/export the JAR and drop in webapp's own /WEB-INF/lib or server's own /lib. The "Deployment Assembly" configuration is however more easy and the recommended way.
See also:
Business Logic Layerin Servlet and JSP
When assembling a WAR, Eclipse cannot tell just by looking at your build path dependencies whether they are something that should be bundled in WAR's WEB-INF/lib directory or if they are something that you expect to be available on your server classpath. Extra metadata is needed to differentiate among those cases.
If you look in your problems view, you should see numerous warnings that look like this:
"Classpath entry [something] will not be exported or published..."
Right click on these and select "Quick Fix". You will see a dialog with available fixes. One of them is going to say something like "Mark the associated classpath entry as publish/export dependency...". Use that option.
The above will make a slight alteration to your Java project's .classpath file to tag the dependencies for inclusion in the assembly. You can test without running by exporting a WAR file and checking the contents of WEB-INF/lib folder.
Build path - place your jar's here directly, it will be available for code runtime and compile time.
Deployment assembly - eclipse expects the projects under this path to be bundled and deployed as .jar in web-inf/lib folder. So that it is available for both compile time and run time. If the project is not deployed in deployment assembly then the code is available only for compile time, eclipse won't bundle it and at run-time dependent projects are unavailable to the code.