跳至主要内容

Intellij Java EE Errors

Develop a web application using Tomcat

Create project

  • Choose a Java Enterprise project and select the Web application Framework, select your application server( If you don’t have one in idea, just click new and choose the root folder of your server to create one).
  • Click Finish and you are ready to write your servlet

Add JDBC support

using DataSource and JNDI( taking mysql as an example)

  • add driver to server-root-folder/lib/
  • add context.xml to context-root/META-INF/(create one if not exist) with the following content:
<Context>
    <Resource name="jdbc/YourJNDIRegisteredName" auth="Container" type="javax.sql.DataSource" maxTotal="50" maxIdle="30" maxWaitMillis="10000" logAbandoned="true" username="root" password="" driverClassName="com.mysql.jdbc.Driver"            url="jdbc:mysql://localhost:3306/YourMysqlDBName?autoReconnect=true"/>
</Context>
  • remember to change the user, password and db name in above file

    This will register the mysql database to this server using JNDI, which you can access it later by right properties and a simple context.lookup(Name)

Develop EJB (using wildfly)

  • create a EJB project
  • add bean/interface
    - @remote
    - @stateless/stateful
  • change the artifacts of default EJB project from EJB Application: Exploded to JAR or EJB Application: Archive(I don’t know whether it is a bug of wildfly and/or intellij on my platform, but change it indeed make it work. ).

I didn’t change the artifact type at the beginning which cause a serial of errors as the end of post shows. It fails with the error message – Services with missing/unavailable dependencies is somewhat misleading for the beginner like me.

In order to figure out what wrong with it, I have to run same project in Eclipse which uses xxx.jarto deploy project in <server-home>/standalone/deployments/, even though this behavior is discouraged .

[org.jboss.as.server.deployment.scanner] (MSC service thread 1-6) WFLYDS0013: Started FileSystemDeploymentService for directory <server-home>/standalone/deployments

Users, particularly those running production systems, are encouraged to use the JBoss AS management APIs to upload and deploy deployment content instead of relying on the deployment scanner subsystem that periodically scans this directory. ———— “server-home”/standalone/deployments/README.txt

And through comparison between Eclipse and Intellij, I came to realize that it is the way that class packaged differs.

  • EJB Application: Exploded:
    This artifact is an exploded directory where files and folders are presented in the file system as separate items
  • JAR: just a zip file contain the compilation output

So I changed the artifacts of idea and it works like magic.

Invoke EJB bean in the client

  • add jboss-client.jar: Setup the client classpath to include the jboss-client jar that’s required for remote invocation of the EJBs( it will analyse the jboss-ejb-client.properties to connect to server). The location of the jar is WILDFLY_HOME/bin/client/jboss-client.jar..
  • You’ll also need to have your application’s interface for bean and other jars that are required by your application, in the client classpath
  • jboss-ejb-client.properties: The client will have to place this file in the classpath of the application. A sample is like following:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

This will setup a EJB receiver which knows its target address is localhost:8080 which will be capable enough to communicate to the server via the JBoss specific EJB remote client protocol.

Notice:

  • I am using a web project as ejb client to invoke the ejb server, so I have to put the jboss-client.jar file under the WEB-INF/lib and add it to artifact to make it work.

Add data source and using jpa

  • add module.xml and connector.jar in server_home/modules/system/layers/base/com/mysql/main/
  • add <datasource>, <driver>(missing this will also cause error of missing/unavailable dependencies) in standalone.xml
  • add your table mapped entity class
  • start your mysql server before start wildfly server otherwise communication failure( connection refused error) will show

Unsolved error:

  • invisible char behind the tag: A strange standalone.xml parse error. It soon disappear after re-write some xml setting.

More Errors you may encounter:

wrong url cause wrong drive class error

<datasource jta="true" jndi-name="java:/MySqlStudentDS" pool-
name="MySqlDS" enabled="true" use-java-context="true" use-ccm="true">
    <connection-url>jdbc:mysql:/localhost:3306/student</connection-url>
    <driver>mysql</driver>
    <security>
        <user-name>root</user-name>
        <password></password>
    </security>
</datasource>
18:27:58,936 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 58) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
    at ...
Caused by: javax.resource.ResourceException: IJ031083: Wrong driver class [com.mysql.jdbc.Driver] for this connection URL [jdbc:mysql:/localhost:3306/student]
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:314)
    ... 32 more

So this make me remember the url should be jdbc:mysql://localhost:3306/sutdent which has two backslashes before the ip address!

No persistence.xml when using @PersistenceContext:

WFLYJPA0033: Can't find a persistence unit named null in deployment \"TryEJB.jar\""},

which means that I didn’t add persistence.xml to specify a persistence unit.

java.lang.ClassNotFoundException: org.hibernate.collection.internal.PersistentSet

The client need hibernate core jar to receive the collections come from jboss server or you will meet the error like this. I add the hibernate-core-4.3.9.Final.jar to artifact and fix it.

java.lang.IllegalStateException: No EJB receiver available for handling

[appName:xxx,modulename:xxx,distinctname:xxx] combination for invocation context org.jboss.ejb.client.EJBClientInvoc
ationContext@xxxx

Possible causes:

  • wrong JNDI path string to lookup: Check your string with the output of EJB container when deploying. The best way is to copy the output from server and add some slash and distinct name then paste to your client code.
  • missing jndiProperties.put("jboss.naming.client.ejb.context", true); as here state.
  • -

java.lang.IllegalArgumentException: node to traverse cannot be null!

Possible causes:

entityManager.createQuery(someNamedQuery);
// using the wrong method. change it to 
entityManager.createNamedQuery(someNamedQuery);

What I have learnt from it:

  1. Of course, the knowledge of Java EE and some miscellaneous knowledge.
  2. The way to analyze complex error message: find the root cause
  3. The way to find a solution: what to do, when the error message is not clear enough for you to fix it or even google it can’t find the same problem. I have to use somewhat stupid but useful way: comparison.
    • I use Eclipse and Intellij to run same code with same server to find the problem of Artifact.
    • I use others and my configuration file to run same code to find my configuration lack a backslash

Ref:

  1. EJB invocations from a remote client

The long strange error messagem which fixed by change artifact.

ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."learnEJB_ejb_exploded.rar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."learnEJB_ejb_exploded.rar".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "learnEJB_ejb_exploded.rar"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
    at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.process(ParsedRaDeploymentProcessor.java:231)
    at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.deploy(ParsedRaDeploymentProcessor.java:129)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
    ... 5 more
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
    at org.jboss.jca.common.metadata.spec.ResourceAdapterImpl.validate(ResourceAdapterImpl.java:228)
    at org.jboss.jca.common.metadata.spec.ConnectorImpl.validate(ConnectorImpl.java:350)
    at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.process(ParsedRaDeploymentProcessor.java:205)
    ... 7 more
10:24:27,634 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "learnEJB_ejb_exploded.rar")]) - failure description: {
    "WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment \"learnEJB_ejb_exploded.rar\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
    Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"},
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.InstanceName is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]",
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.InAppClientContainer is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]",
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.Validator is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]",
        "jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".batch.environment is missing [jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".beanmanager]",
        "jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".beanmanager]",
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.ValidatorFactory is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]"
    ]
}
10:24:27,638 ERROR [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0021: Deploy of deployment "learnEJB_ejb_exploded.rar" was rolled back with the following failure message: 
{
    "WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment \"learnEJB_ejb_exploded.rar\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
    Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"},
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.InstanceName is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]",
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.InAppClientContainer is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]",
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.Validator is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]",
        "jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".batch.environment is missing [jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".beanmanager]",
        "jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".beanmanager]",
        "jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.ValidatorFactory is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]"
    ]
}
...
Artifact learnEJB exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment \"learnEJB_ejb_exploded.rar\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
    Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"},"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".beanmanager]","jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.Validator is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]","jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".batch.environment is missing [jboss.deployment.unit.\"learnEJB_ejb_exploded.rar\".beanmanager]","jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.InstanceName is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]","jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.ValidatorFactory is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]","jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB.InAppClientContainer is missing [jboss.naming.context.java.comp.learnEJB_ejb_exploded.learnEJB_ejb_exploded.HelloEJB]"]}

Written with StackEdit.

评论

此博客中的热门博文

Spring Boot: Customize Environment

Spring Boot: Customize Environment Environment variable is a very commonly used feature in daily programming: used in init script used in startup configuration used by logging etc In Spring Boot, all environment variables are a part of properties in Spring context and managed by Environment abstraction. Because Spring Boot can handle the parse of configuration files, when we want to implement a project which uses yml file as a separate config file, we choose the Spring Boot. The following is the problems we met when we implementing the parse of yml file and it is recorded for future reader. Bind to Class Property values can be injected directly into your beans using the @Value annotation, accessed via Spring’s Environment abstraction or bound to structured objects via @ConfigurationProperties. As the document says, there exists three ways to access properties in *.properties or *.yml : @Value : access single value Environment : can access multi

Elasticsearch: Join and SubQuery

Elasticsearch: Join and SubQuery Tony was bothered by the recent change of search engine requirement: they want the functionality of SQL-like join in Elasticsearch! “They are crazy! How can they think like that. Didn’t they understand that Elasticsearch is kind-of NoSQL 1 in which every index should be independent and self-contained? In this way, every index can work independently and scale as they like without considering other indexes, so the performance can boost. Following this design principle, Elasticsearch has little related supports.” Tony thought, after listening their requirements. Leader notice tony’s unwillingness and said, “Maybe it is hard to do, but the requirement is reasonable. We need to search person by his friends, didn’t we? What’s more, the harder to implement, the more you can learn from it, right?” Tony thought leader’s word does make sense so he set out to do the related implementations Application-Side Join “The first implementation

Implement isdigit

It is seems very easy to implement c library function isdigit , but for a library code, performance is very important. So we will try to implement it and make it faster. Function So, first we make it right. int isdigit ( char c) { return c >= '0' && c <= '9' ; } Improvements One – Macro When it comes to performance for c code, macro can always be tried. #define isdigit (c) c >= '0' && c <= '9' Two – Table Upper version use two comparison and one logical operation, but we can do better with more space: # define isdigit(c) table[c] This works and faster, but somewhat wasteful. We need only one bit to represent true or false, but we use a int. So what to do? There are many similar functions like isalpha(), isupper ... in c header file, so we can combine them into one int and get result by table[c]&SOME_BIT , which is what source do. Source code of ctype.h : # define _ISbit(bit) (1 << (