Expand WAR or EAR files in jBoss AS 7

2019-05-16 13:25发布

问题:

I'm deploying a WebService project into a jBoss AS7, and everything goes OK except that jBoss doesn't expand my WAR or EAR file.

Already tried copying the file to the "jboss-as-7.1.0.Final\standalone\deployments" folder and using the WebConsole, but in both cases the result was the same.

If I deploy from within Eclipse everything runs OK.

I need it to expand my file because in the application initialization I scan the class directories looking for the correct class to instantiate using reflection.

EDIT : Don't know if this a particular situation with jBoss AS 7 or with the jBoss AS family, because I already used WebSphere and jBoss Web and both of them expanded the files.

EDIT2 : Added a System.out with the execution path

MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath();

and it returns the following path

C:\jboss-as-7.1.0.Final\bin\content\ServerEAR.ear\Server.war\WEB-INF\classes

witch doesn't exist. So I did a search for the class name and fount it at

C:\jboss-as-7.1.0.Final\standalone\tmp\vfs\deployment5a9e98d5c43716c3\Server.war-e31a657d2bc3bd0f\WEB-INF\classes\r30

Isn't it possible to force JBoss to extract the files to the deployment folder? Or how can I get the previous path at run time.

回答1:

Had forgotten about this question, so this is the way that I solved it:

public String getRealFilePath(String aFilePath) throws Exception
{
    org.jboss.vfs.VirtualFile vFile = org.jboss.vfs.VFS.getChild(aFilePath);
    URI fileNameDecodedTmp = org.jboss.vfs.VFSUtils.getPhysicalURI(vFile);

    path = fileNameDecodedTmp.getPath();
    System.out.println(path);
    return path;
}

So at runtime I just need to call getRealFilePath() with the original question values, and problem solved ;)



回答2:

I believe that you cannot force Jboss7 to auto expand the war file when deploying.

You can, however, copy the already expanded war and you shouldn't have any problems.

Actually, if you look closely at the Eclipse deployment, you will notice that it copies the whole directory to the deployment directory, not the war file itself.

Why do you need to deploy exploded, by the way? If you need to access and read some files as resources, you can have a look at classpath resources



回答3:

Please check you classpath setting. I faced the same problem recently, and solved it by added system environment variables:

CLASSPATH=.;
C:\Program Files\Java\jdk1.6.0_10\lib;
C:\Program Files\Java\jdk1.6.0_10\lib\tools.jar;
C:\Program Files\Java\jdk1.6.0_10\lib\dt.jar; `