How to avoid copying 40M of java lib's within

2019-04-27 22:57发布

At the moment my build process consists of repackaging the war file with all required java libraries under WEB-INF/lib and then copying the war file to development/demo/production server to be redeployed by tomcat.

The packaged war file's size is about 41M and it has at the moment something like 40M of external java libraries. There has to be a better way. How have you solved this issue?

My development machine is a windows box with Eclipse as my IDE and Ant as my build tool. The servers are all linux boxes with Tomcat 5.5.

Should I maybe add the jar files to the war package at server side?

9条回答
\"骚年 ilove
2楼-- · 2019-04-27 23:27

Tomcat has a shared/lib directory, which is the proper place for global application dependencies. However, these will be visible to all applications, which will affect dependency management and may have consequences for things like static variables. I'm not sure if you can configure anything better in Tomcat.

An alternative is to switch to a more sophisticated web container. For example, WebSphere Application Server Community Edition (a blue-washed version of Geronimo) supports per-asset libraries. Other free and commercial servers support this, too. I know WebSphere Application Server does and I'm pretty sure you can do it in Glassfish.

查看更多
Explosion°爆炸
3楼-- · 2019-04-27 23:27

What you need is a version control tool and a build process.

Use CSV,SVN,GIT or whatever fit you to keep your source under control. use a build tool to build your application : Maven,ant,...

Now, when you want to deploy your application on your server ,you just have to commit your updates on your computer,update your source on your server,build your application and deploy it from the server.

This way , the server will just have to load your modifications and it should be much faster.

查看更多
叛逆
4楼-- · 2019-04-27 23:30

I can see what you are saying, and have had the same frustration with some of our webapps, but for consistency sake, I would suggest you keep things as they are. If copying the libraries to the tomcat/lib directory you may run into issues with the system classpath vs. the webapp classpath.

By keeping things as they are you are sure you are deploying the same stuff in development/demo as you are in production. Life sucks when you are manually tweaking stuff in production, or you have some crazy error because you forgot to update XYZ.jar from version 1.6 to 1.6.1_b33 in production and now it's behaving differently than what you believe is the exact same code on demo.

When working with something vital enough to have dev/demo/production systems, I think consistency is much more of an issue than .war file size.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-04-27 23:38

We use the rsync tool for this (in our case, using cygwin under windows) to copy the deployments to the servers (which run linux). We use exploded WAR/EAR files (i.e. a directory structure called MyApp.war rather than a zip file called MyApp.war), rsync will only transfer the files that have changed.

In general use, rsync will transfer our 30-40 megabyte exploded EARs in about 5 seconds.

查看更多
Deceive 欺骗
6楼-- · 2019-04-27 23:38

Can you add the non-changing Jars to the Java Library Path on the server side, and only include the regularly changing Jars in your WAR?

查看更多
何必那么认真
7楼-- · 2019-04-27 23:40

you could include the external java libraries in the Tomcat/lib directory. That way they stay on the server.

查看更多
登录 后发表回答