I have a web project Web1.war which have some jar file in its libraries (let's call it lib.jar). That is Web1.war --> lib.jar.
Then I did convert to jar file that web project: Web1.jar. Afterwards add the Web1.jar file to another java web project Web2.war.
How to refer that library lib.jar from current project (Web2.war) through jar file (Web2.war --> Web1.jar --> lib.jar) ?
Java only supports JAR level dependencies. You mention having converted you 'web project' to a JAR but don't give the details of how you did this.
By default, Java uses the classpath to find dependencies. In a 'web project' (WAR) the classpath is the WEB-INF/classes directory and any JARs in the WEB-INF/lib.
If you have classes in one 'web project' (WAR) that you need to use in another 'web project' (WAR) then you have a couple of options, both of which will involve modifying your build:
put shared classes are in their own jar, which you include in both 'web projects' (WARs).
or
unpack the first 'web project' (WAR) adding the classes (and/or libraries) to the second 'web project' (WAR).
Update
You cannot covert a WAR to a JAR as you have suggested in your edits. While it's possible to create a custom archive format, a JAR cannot (and should not) contain other JARs.
Related
I have created a JavaFX application using NetBeans IDE and below is my folder structure.
I want to a build a single jar file including all dependencies for this jar to work properly.
This jar requires testplanner and batch folder from project root directory and files inside dist folder to work properly.
How can I package all this to a single jar file?
Theoretically JAR files cannot contain dependencies within, as java does not support it out of the box. WAR and EAR archives can. What You want to do is not standard, but is named fat jar. Fat jars are used i.e. by spring-boot maven plugin, but you could try this:
https://dzone.com/articles/how-build-fat-jar-using
And some more explanation:
NetBeans - deploying all in one jar
Use tecreations Deploy. Put all your sources into a path declared as Tecreations.getProjectPath(), run BuildAll to create your corresponding classes, put your jars in projectpath/jars and select the appropriate settings, whether to include jars, sources or classes. Select your main class and click Deploy. Unsigned and signed output jars are produced in user/Documents.
Download: https://tecreations.ca/java/downloads/release.
I built my netbeans project and it created a .war file including all the .jar libraries. I need to remove my all libraries from .war file. I tried to untick them from library folder but then the project does not deployed. How can I remove my libraries from the .war file and if I remove them where should I put them correctly. In jboss also there is a folder called lib in standalone folder.Should I put them there? If so how to do it. I am not using maven.
If you are using Maven set the dependency scope to the libraries you would like omitted to have scope provided. You can add the dependencies of your WAR to the MANIFEST.MF file or the jboss-deployment-structure.xml file using Maven. If the lirbaries are not JBoss modules by default, eg Orcale JDBC driver, then you will need to create these modules yourself. See the JBoss AS 7 documentation on how to do this.
You can try following approach. I haven't worked on Jboss so don't have detail idea about it.
Deploy each logical library (like "OpenJPA" or "Log4J") as a module, including its api and impl jars and any dependency JARs that aren't already provided by other AS7 modules. If there's already a module add a dependency on it rather than adding a JAR to your module. If several different libraries share some common dependencies, split them out into modules and add them as module dependencies in module.xml.
Use jboss-deployment-structure.xml to have your deployment .war / .ear / whatever declare a dependency on the module if it isn't autodetected and autoloaded.
Courtesy #Craig Ringer.
For complete thread go here
I'm packaging an ear file with maven for an IBM Content Navigator plugin project. This product requires to have an ear, which includes a war, and that war should include the plugin as jar in the root of the war. So not in the WEB-INF/lib. The ear and the war are just empty containers.
So I've created 3 projects, an ear, a web project, and a simple java project. All of these projects have a pom.
How can I create a war which includes the simple java project (jar) in the root of the war? It is not just a dependency as it must not end up in the WEB-INF/lib.
Thanks in advance,
Roeland Bestman
You need to use the maven-dependency-plugin's copy goal and place the jar in a directory under the target directory. Then you'll need to include it from there into your war using the maven-assembly-plugin.
What is the difference between "Module Dependencies" and "Libraries" in IntelliJ IDEA when you want to add a .jar library to your project? Also, What is the "Export" check box when you are adding your .jar library to the "Module Dependencies" in IntelliJ IDEA?
In each of these ways, how are the classes and code inside the included .jar library integrated into your final project (code) when creating the newly generated .jar file?
Module dependencies are classes, archives, libraries and resources that your module files references. While a library is a set of class files stored in an archive or directory.
Export check means if checked then this library will be implicitly added to the other module that references this one.
To create a .jar file you need create an artifact. Artifact is a placeholder of the building output. There's predefined templates for creating .jar, .war, .ear archives. You can choose jar to build a jar artifact. By default it's defined empty and you need to define content of the artifact. You can drag-n-drop compiled output to it but don't do it with library archives. Because libraries in this case will be packaged inside the .jar file and you will be required to create a separate classloader to load them before your application start. Instead you change the artifact type to Other and drag .jar and dependent libraries into output root. This way library archives will be copied along with created .jar. You also need to create a MANIFEST.MF and specify Class-Path there for dependent libraries. All files will be stored in the directory you specify for building the artifact. You can build it using Build Artifact menu.
If your project contains multiple modules, "module dependency" defines dependencies between these modules, but libraries are compiled classes (usually jar files, optionaly containing theirs sources and javadocs) that are used by your module.
Each module can have its own libraries and artifacts (for example a result jar file), and can depend on other modules without circular dependency.
Module Dependencies tab can contain Libraries, Export means that a library from the module will be also available to another module that depends on this module.
Final jar with all the dependencies can be created using Artifacts.
"In IntelliJ IDEA, libraries can be defined at three levels: global (available for many projects), project (available for all modules within a project), and module (available for one module)."
Global library is set via Project Structure\Platform Settings\Global Libraries
Project library is set via Project Structure\Project Settings\Libraries
Module library is set via Project Structure\Project Settings\Modules\Dependencies
I setup a Google App Engine project in Eclipse. I added a root level folder to contain libraries for my project. I added all of these libraries to the build path for my project. The code compiles without any errors. When I run the project, I get startup errors NoClassDef errors. When I add these libraries manually to the war directory's lib folder, these errors disappear.
Why isn't Eclipse deploying the libraries on my build path for me? Do I need to have a build script in place for Eclipse to run? A build script that will copy my libraries to the war dir's lib folder?
For standard Java EE project libraries have to be under {web-app}/WEB-INF/lib folder. GAE requires them to be there too to upload to the engine with your code.
Alternatively you can use Maven to define your dependencies and deploy to GAE
UPDATE: GAE project follows standard Java EE project structure to build and deploy a war file. The convention is that your lib folder is in {web-app}/WEB-INF/lib. Google plugin automatically generates such a structure (example from plugins docs):
MyTestProject
src/
log4j.properties
META-INF/
jdoconfig.xml
com/
mytestproject/
MyTestProjectServlet.java
war/
index.html
WEB-INF/
appengine-web.xml
web.xml
logging.properties
classes/
lib/
...App Engine JARs...
The plugin does allow to change location for your "war" directory, but not the location of your libraries since it should follow the Java EE standard.
You can add the libraries to your war/lib directly, and then right click on the libraries to add them to your build path.
Not sure why it doesn't deploy libs on your build path, but I have been working with Eclipse for years and have always done it the way I described. Then I just deploy through eclipse and don't use a build script.
If the library which was not added to lib folder is being developed in the same workspace, I would suggest to enable the "Utility Module" facet in project properties of the library project. Sometimes Eclipse doesn't copy a jar into WEB-INF/lib folder even if the Deployment Assembly and everything else was configured properly.