How do I structure an ear file in JBoss AS 7 to avoid class cast exception? - jboss7.x

Currently we are using JBoss AS 5 and using single ear file with the deployment structure as follows
company.ear
|_ webapp1.war
|_ webapp2.war
|_ lib
| |_ ejb1.jar
| |_ ejb2.jar
|_ META-INF
| |_application.xml
|_ thirdparty1.jar
|_ thirdparty2.jar
All ejb which are common to web application are kept in lib and thirdparty jars are kept in ear root path. This is working fine.
Now, we are migrating the same to JBoss 7.1.1. and we have tried with following deployment structures.
1. company.ear
|_ webapp1.war
|_ webapp2.war
|_ lib
| |_ thirdparty1.jar
| |_ thirdparty2.jar
|_ META-INF
| |_application.xml
| |_jboss-deployment-structure.xml
|_ ejb1.jar
|_ ejb2.jar
2. company.ear
|_ webapp1.war
|_ webapp2.war
|_ lib
| |_ ejb1.jar
| |_ ejb2.jar
|_ META-INF
|_application.xml
|_jboss-deployment-structure.xml
In the second deployment structure, we have defined thirdparty jars in modules folder and added global dependency in the stanalone.xml.
Though we are following JBoss AS 7 migration document and some work-around, we are getting ClassCastExceptions during deployment.
how do I keep from getting these exceptions in my deployment file?
Or how can we force JBoss SA to load all EJB jars by a single class loader.

Related

How to build and deploy an external library with CMake [duplicate]

This question already has answers here:
CMake link to external library
(6 answers)
Closed 6 months ago.
I would like to use and deploy an external library in my program.
My project's structure is as follow (simplified):
ProjectDir
|_ _build
|_ CMakeLists.txt
|_ Src
| |_ CMakeLists.txt
| |_ .h and .cpp files
|_ ThirdParty
|_ CMakeLists.txt
|_ ExternalLib
|_ includes
| |_ .h files
|_ lib
|_ Windows
| |_ .dll files
|_ Linux
|_ .so files
For this library, I've only the include files and the binaries for Windows and Linux.
I'm able to find the includes files by using target_include_directories() in the CMakeLists.txt of the ThirdParty directory but I cannot build my program even by declaring the libraries with :
target_link_libraries(${CMAKE_PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/ExternalLib/lib/Windows/extLib)
Note: this command is also in the CMakeLists.txt of ThirdParty directory.
I get the following error:
'../../../ThirdParty/ExternalLib/lib/Windows/extLib', needed by 'program' missing and no known rule to make it
I develop on a Windows platform with VS2022 and my program will be build and installed on a Linux server.
On Windows I've the latest version of CMake but on Linux the version is 3.16.
Can somebody help me in fixing this error?
You should import library as a target of you project.
For instance something like
add_library(your_lib SHARED IMPORTED)
set_property(TARGET your_lib PROPERTY
IMPORTED_LOCATION
"${CMAKE_SOURCE_DIR}/ThirdParty/ExternalLib/lib/Linux/extLib.so") # to be adapted for windows
target_include_directories(your_lib
PUBLIC
${CMAKE_SOURCE_DIR}/ThirdParty/ExternalLib/include)
then you should be able to use it as any other library in cmake:
target_link_libraries(yourExecutable PRIVATE your_lib)
see doc in details here:
https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html

How to make intermediate object file not a library using qmake?

Filesystem layout:
MyProject
|_ myproject.pro
|_ FuncA
|_ core.cpp
|_ core.h
|_ core.pro
|_ app
|_ main.cpp
|_ app.pro
I want just to compile "core.cpp" in FuncA to make a object file not a library. That is "gcc -c core.cpp". And in app I want to make main program linking core.o created previously.
In this case how do I make core.pro? Which TEMPLATE should I use?
Use can use generic app template for core.pro. It will create intermediate core.o anyway, which you can link later in app.pro like so:
LIBS += $$PWD/../FuncA/core.o
I solved this problem with "static library config" so that it will not make ".so" libs and then link that static library with main program.
TEMPLATE = lib
CONFIG += staticlib

How to add source files in another folder

I'm using cmake to build my project in C++. Assume I have the following directories on my Source folder
Source
|_Dir1
| |_Class.cpp
| |_Class.hpp
|
|_Dir2
|_Main.cpp
In Dir1 there's a class with its header and implementation files (Class.cpp and Class.hpp).
In Dir2 there's the main application which uses the class in Dir1
What is the good way to tell the CMakeLists in Dir2 to build the executable with Dir1/Class.cpp file?
EDIT: To be more specific, I want to define that the source file for Class.cpp has to be used in Dir1's CMakeLists.txt, and not in Dir2's. Doing it the other way feels plain wrong to me and it's hard to use, so if there's a reason they're enforcing me to do this some clarification on the topic would be nice.
What I'm currently doing is hard-coding the Class.cpp file location in Dir2/CMakeLists.txt but that just doesn't scale when I've got a bunch of classes interacting together.
Supposed you have a single CMakeLists.txt file at the Source directory, you'll create two variables using different file() commands
file(GLOB Dir1_Sources RELATIVE "Dir1" "*.cpp")
file(GLOB Dir2_Sources RELATIVE "Dir2" "*.cpp")
and add both sets generated by the file() commands to your target's source list:
add_executable(MyProgram ${Dir1_Sources} ${Dir2_Sources})
Alternatively you can place a CMakeLists.txt file under Dir1 and Dir2 (Main) looking as follows
Source
|
|_ CMakeLists.txt
| > project(MyProgram)
| > cmake_minimum_required(VERSION 3.8)
| > add_subdirectory("Dir1")
| > add_subdirectory("Dir2")
|
|_ Dir1
| |_ CMakeLists.txt
| > file(GLOB Sources "*.cpp")
| > add_library(Dir1 STATIC ${Sources})
|_ Dir2
|_ CMakeLists.txt
> file(GLOB Sources "*.cpp")
> add_executable(MyProgram ${Sources})
> target_link_libraries(MyProgram Dir1)
to add subdirectories as further (static) libraries linked to your main target.

How to set include_directories from a CMakeLists.txt file?

I seem to be having trouble setting the include path (-I) using the include_directories() command in CMake. My project directory is as follows:
Root
| - CMakeLists.txt
| - libs
| - | - CMakeLists.txt
| - | - inc
| - | - | - // lib specific includes
| - | - src
| - | - | - // lib specific sources
| - proj1
| - | - CMakeLists.txt
| - | - inc
| - | - | - // proj1 specific includes
| - | - src
| - | - | - // proj1 specific sources
The root CMakeLists.txt file looks like so:
project(ROOT)
add_subdirectory(libs)
add_subdirectory(proj1)
The CMakeLists.txt file under libs:
project(lib)
add_library(lib STATIC ${lib_hdrs} ${lib_srcs}) // for conciseness, omitted set()
And lastly, the CMakeLists.txt file under proj1:
project(proj1)
include_directories("${ROOT_SOURCE_DIR}/lib/inc") # <- problem line?
add_executable(proj1 ${proj1_srcs})
target_link_libraries(proj1 lib)
The goal is to create the library from the source and header files in libs, then link against the executable generated under proj1. Proj1 has some files that #include stuff in libs include, so I need to add the directories to be used with -I. Based on the documentation, that's what include_directories() is supposed to do. However despite explicitly setting that and following it with a debug message(${INCLUDE_DIRECTORIES}), the INCLUDE_DIRECTORIES variable is an empty string, and no directories are specified for the include path, so my compilation of proj1 fails.
I've also attempted removing the quotes around ${ROOT_SOURCE_DIR}/inc to see if that helped but no luck.
include_directories() populates a directory property called INCLUDE_DIRECTORIES:
http://www.cmake.org/cmake/help/v2.8.12/cmake.html#prop_dir:INCLUDE_DIRECTORIES
Note that CMake 2.8.11 learned the target_include_directories command, which populates the INCLUDE_DIRECTORIES target property.
http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:target_include_directories
Note also that you can encode the fact that 'to compile against the headers of the lib target, the include directory lib/inc is needed' into the lib target itself by using target_include_directories with the PUBLIC keyword.
add_library(lib STATIC ${lib_hdrs} ${lib_srcs}) # Why do you list the headers?
target_include_directories(lib PUBLIC "${ROOT_SOURCE_DIR}/lib/inc")
Note also I am assuming you don't install the lib library for others to use. In that case you would need to specify different header directories for the build location and for the installed location.
target_include_directories(lib
PUBLIC
# Headers used from source/build location:
"$<BUILD_INTERFACE:${ROOT_SOURCE_DIR}/lib/inc>"
# Headers used from installed location:
"$<INSTALL_INTERFACE:include>"
)
Anyway, that's only important if you are installing lib for others to use.
After the target_include_directories(lib ...) above you don't need the other include_directories() call. The lib target 'tells' proj1 the include directories it needs to use.
See also target_compile_defintions() and target_compile_options().

Copy artifacts of each module in multi-module project to specific folder [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Maven multi-module project - copying all “package” JARS from submodules into parent/target/
I have an pom structure:
project1
|
|______ pom.xml
|______ module 1
| |_____ pom.xml
| |_____ dist
| |_____ bin
| |_____ lib
|______ module 2
| |_____ pom.xml
| |_____ dist
| |_____ bin
| |_____ lib
|______ dist
| |____ bin
| |____ lib
Requirements:
+ When build each module, bundle file will be copied to its' dist/bin and dependencies copied to its' dist/lib
+ When build project1, bundle file of each module will be copied to project1/dist/bin and dependencies of all modules copied to project/dist/lib
Can we achieve this??? If it can, how we do it???
Just take a look here: https://github.com/khmarbaise/maven-copy-example . The only thing i changed is not to use a a folder like dist i use target/dist in the maven style.