[jira] [Commented] (ISIS-2978) [NOT A PROBLEM] Launch packaged SimpleApp 2.0.0-M7 throws JAXB exception

2022-03-21 Thread Jira


[ 
https://issues.apache.org/jira/browse/ISIS-2978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17509809#comment-17509809
 ] 

Miklós Győrfi commented on ISIS-2978:
-

Hi Andi! Even if this issue is closed, there is something to think over.

It is a _valid_ deployment mode to make a _fat_ war/jar For a Spring Boot 
application.  For me, Isis works well in this mode (with the modification 
described here).

Unlike other uber jar solutions, Spring Boot builds a 
[jar|https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html]
 containing jars (not classes) from runtime class path. This technique requires 
a special ClassLoader, which is used to load the whole application context, 
including the beans.

However an ad-hoc thread's (even if it is created a pool) ContextClassLoader 
points nowhere, or it is the system ClassLoader, which does not see the classes 
in the jars in the fat jar. Threads (e.g. workers)  started by Spring has 
properly setted contextClassLoader.

Unfortunately there are many library out there (for example, the JAXB 
solutions, or even the JDBC) which uses the  getContextClassLoader() to access 
the contextual class loader (it is a arguably valid practice in j2EE - this 
contains the class loader of the application, not the container). In Spring 
Boot fat jar case, this can cause a failure (ClassNotFound exception), on a 
random (non Spring) thread.

So this problem is really a *generic* problem, which does not occur in 
one-classpath environment (like maven-started application above), as the class 
loader of the system is exactly the system classloader, contextual loader of 
any thread  is perfectly points to that, but not in case of Spring Boot fat jar 
deployment (or it may fail in an Application Server as well)

That is why I really suggest to change the ContextClassLoader of threads to the 
Spring loader classloader, which is easyly can be looked up with getting the 
classloader of any class, which is loaded by the application startup itself 
(e.g. IsisConfiguration is a good choice, or the _ConcurrentTask itself if you 
don't want to increase the dependency).

As I suggested before, you should change the only code of _ConcurrentTask:
{code:java}
@Override
public final void run() {
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
try {

Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
preCall();
try {
val completedWith = innerCall();
postCall(completedWith, /*failedWith*/ null);
} catch (Throwable e) {
postCall(/*completedWith*/ null, e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}

} {code}
It is a common practice in Spring, the code will be better, and as a side 
effect, it solves this issue too, you can use Spring Boot fat jar as well.

Thanks:

Nick

 

 

 

 

 

 

 

 

> [NOT A PROBLEM] Launch packaged SimpleApp 2.0.0-M7 throws JAXB exception
> 
>
> Key: ISIS-2978
> URL: https://issues.apache.org/jira/browse/ISIS-2978
> Project: Isis
>  Issue Type: Bug
>  Components: Isis Examples
>Affects Versions: 2.0.0-M7
>Reporter: Vladimir Nisevic
>Assignee: Andi Huber
>Priority: Major
> Fix For: 2.0.0-RC1
>
> Attachments: startup.txt
>
>
> h2. Problem description
> Followed guide 
> [https://isis.apache.org/docs/2.0.0-M7/starters/simpleapp.html#downloading-&-running]
>  
> My environment:
>  * Windows 10
>  * openjdk 11.0.2 2019-01-15
>  
> I use in all cases same JDK.
>  
> Launching from IDE (IntelliJ) works fine, but when launching the packaged JAR 
> with
> {code:java}
> somePath\isis-app-simpleapp-jdo\webapp\target> java -jar 
> .\simpleapp-jdo-webapp-2.0.0-M7-exec.jar  {code}
> I get next error - see attached log for whole startup log
> {code:java}
> Caused by: java.lang.ClassNotFoundException: 
> com.sun.xml.bind.v2.ContextFactory
>at 
> jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) 
> ~[?:?]
>at 
> jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
>  ~[?:?]
>at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
>at 
> javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at 
> javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.ContextFinder.find(ContextFinder.java:375) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at 

[jira] [Commented] (ISIS-2978) [NOT A PROBLEM] Launch packaged SimpleApp 2.0.0-M7 throws JAXB exception

2022-03-21 Thread Andi Huber (Jira)


[ 
https://issues.apache.org/jira/browse/ISIS-2978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17509624#comment-17509624
 ] 

Andi Huber commented on ISIS-2978:
--

Hi Vladimir, think of your Apache Isis v2 App as a Spring application. Best 
practices for Spring apply.

That said, my preferred option is to build docker images for my projects. These 
in fact do use maven to launch the app.

> [NOT A PROBLEM] Launch packaged SimpleApp 2.0.0-M7 throws JAXB exception
> 
>
> Key: ISIS-2978
> URL: https://issues.apache.org/jira/browse/ISIS-2978
> Project: Isis
>  Issue Type: Bug
>  Components: Isis Examples
>Affects Versions: 2.0.0-M7
>Reporter: Vladimir Nisevic
>Assignee: Andi Huber
>Priority: Major
> Fix For: 2.0.0-RC1
>
> Attachments: startup.txt
>
>
> h2. Problem description
> Followed guide 
> [https://isis.apache.org/docs/2.0.0-M7/starters/simpleapp.html#downloading-&-running]
>  
> My environment:
>  * Windows 10
>  * openjdk 11.0.2 2019-01-15
>  
> I use in all cases same JDK.
>  
> Launching from IDE (IntelliJ) works fine, but when launching the packaged JAR 
> with
> {code:java}
> somePath\isis-app-simpleapp-jdo\webapp\target> java -jar 
> .\simpleapp-jdo-webapp-2.0.0-M7-exec.jar  {code}
> I get next error - see attached log for whole startup log
> {code:java}
> Caused by: java.lang.ClassNotFoundException: 
> com.sun.xml.bind.v2.ContextFactory
>at 
> jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) 
> ~[?:?]
>at 
> jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
>  ~[?:?]
>at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
>at 
> javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at 
> javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.ContextFinder.find(ContextFinder.java:375) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at 
> org.apache.isis.commons.internal.resources._Xml.contextOf(_Xml.java:224) 
> ~[isis-commons-2.0.0-M7.jar!/:2.0.0-M7]
>... 15 more
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)


[jira] [Commented] (ISIS-2978) [NOT A PROBLEM] Launch packaged SimpleApp 2.0.0-M7 throws JAXB exception

2022-03-21 Thread Vladimir Nisevic (Jira)


[ 
https://issues.apache.org/jira/browse/ISIS-2978?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17509618#comment-17509618
 ] 

Vladimir Nisevic commented on ISIS-2978:


Hi Andi, thanks for reply. What would be the way how to launch application on 
production system? Using maven seem to be am unusual way there?

Regards

> [NOT A PROBLEM] Launch packaged SimpleApp 2.0.0-M7 throws JAXB exception
> 
>
> Key: ISIS-2978
> URL: https://issues.apache.org/jira/browse/ISIS-2978
> Project: Isis
>  Issue Type: Bug
>  Components: Isis Examples
>Affects Versions: 2.0.0-M7
>Reporter: Vladimir Nisevic
>Assignee: Andi Huber
>Priority: Major
> Fix For: 2.0.0-RC1
>
> Attachments: startup.txt
>
>
> h2. Problem description
> Followed guide 
> [https://isis.apache.org/docs/2.0.0-M7/starters/simpleapp.html#downloading-&-running]
>  
> My environment:
>  * Windows 10
>  * openjdk 11.0.2 2019-01-15
>  
> I use in all cases same JDK.
>  
> Launching from IDE (IntelliJ) works fine, but when launching the packaged JAR 
> with
> {code:java}
> somePath\isis-app-simpleapp-jdo\webapp\target> java -jar 
> .\simpleapp-jdo-webapp-2.0.0-M7-exec.jar  {code}
> I get next error - see attached log for whole startup log
> {code:java}
> Caused by: java.lang.ClassNotFoundException: 
> com.sun.xml.bind.v2.ContextFactory
>at 
> jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) 
> ~[?:?]
>at 
> jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
>  ~[?:?]
>at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
>at 
> javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at 
> javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.ContextFinder.find(ContextFinder.java:375) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632) 
> ~[jakarta.xml.bind-api-2.3.3.jar!/:2.3.3]
>at 
> org.apache.isis.commons.internal.resources._Xml.contextOf(_Xml.java:224) 
> ~[isis-commons-2.0.0-M7.jar!/:2.0.0-M7]
>... 15 more
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)