上传速度受限,如何缩短远程测试服务器Jar包部署时间?
Hey there, I feel your pain—15 minutes waiting for a jar upload every time you want to test is a huge drain on your workflow. Since you can't tweak the raw upload speed (thanks, client constraints!), let's focus on reducing the amount of data you need to transfer or finding smarter ways to deploy. Here are actionable steps tailored to your RHEL 6.5 environment:
1. Deploy Incrementally Instead of Full Jars
Instead of uploading the entire jar every time, only send the parts that changed. rsync is perfect for this—it checks file differences at the block level and only transfers what's new. Use this command:
rsync -avz --checksum your-app.jar user@test-server:/opt/app/
-apreserves permissions/ownership,-vgives verbose output,-zenables compression (helpful even for jars, since they often contain uncompressed metadata)--checksumforces rsync to compare file content instead of just timestamps/size, which is critical if your build tool regenerates the jar with a new timestamp even when code changes are minimal
If your jar includes large, rarely changing dependencies (like Spring, Hibernate, etc.), split your deployment into two parts:
- A static
lib/directory on the server with all dependency jars—upload these once, then never touch them again - Only upload your small, frequently changing application jar (or even just the compiled class files) to a separate directory, then update the classpath in your startup script to point to both
2. Build Directly on the Test Server
This is the biggest win if you can pull it off. Instead of building locally and uploading the jar, push your code changes to the server and build there. Here's how:
- Install JDK, Maven/Gradle (whichever you use in Eclipse) on the RHEL 6.5 server
- Set up a Git repo (or use rsync) to push only your code changes to the server—this is way smaller than a full jar
- Create a simple bash script to trigger builds and restart the app:
#!/bin/bash cd /opt/app-source git pull origin main mvn clean package -DskipTests cp target/your-app.jar /opt/app/ systemctl restart your-app.service
Now you just run this script after pushing code, and you skip the jar upload entirely.
3. Optimize SSH Compression
Even if you can't speed up the network, squeezing more data into each packet helps. Enable SSH compression for your transfers:
- For
scp: use the-Cflag:scp -C your-app.jar user@test-server:/opt/app/ - For regular SSH sessions, you can add this to your local
~/.ssh/configto auto-enable compression for this server:Host test-server HostName your-server-ip User your-username Compression yes
Note: If your jar is already heavily compressed (most are), this might only give a small boost—but it's free to try.
4. Cache Dependencies on the Server
If building on the server isn't an option, pre-cache all your project dependencies on the test server so you only upload your application code. For Maven:
- Copy your local
~/.m2/repositoryto the server's~/.m2/repositoryonce (this is a one-time upload, but since dependencies don't change often, it's worth it) - When building locally, use
mvn package -Dmaven.test.skip=true -Ddependency.locations.enabled=falseto build a "thin jar" that only contains your code, not dependencies - Upload this thin jar to the server, and run it with a classpath that includes the cached dependencies on the server
5. Use Fast File Swap with Symlinks
Once you have a few versions of your jar on the server, use symlinks to quickly switch between versions without re-uploading. For example:
- Upload new jars to
/opt/app/versions/your-app-v1.2.3.jar - Create a symlink
/opt/app/current.jarthat points to the active version - When you upload a new version, just update the symlink:
ln -sf /opt/app/versions/your-app-v1.2.4.jar /opt/app/current.jar
This doesn't reduce upload time, but it cuts down on post-upload setup time and makes rollbacks instant—super helpful for testing cycles.
Pick the option that fits your setup best—building on the server is the gold standard, but incremental rsync or splitting dependencies will still cut your wait time drastically.
内容的提问来源于stack exchange,提问作者Walter Colchado

