You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Cybera的Ubuntu服务器部署含.xml、.jsp等组件的Java网站应用?

Got it, let's get your Java web app up and running on that Ubuntu 14.04 server. I'll break this down into clear, actionable steps so you don't get lost along the way.

1. Install Core Dependencies First

Your Java app needs two key things: a Java Development Kit (JDK) and an application server (like Tomcat, which handles JSPs, servlets, and WAR deployments).

Install OpenJDK 8

Ubuntu 14.04 supports OpenJDK 8, which is stable for most Java apps. Run these commands:

sudo apt-get update && sudo apt-get install -y openjdk-8-jdk

Verify the installation worked:

java -version

You should see output showing OpenJDK 8 is active.

Set Up Tomcat 8

Tomcat is the go-to for Java web apps. Let's install it manually for more control:

  • Download a stable Tomcat 8 release (I'll use 8.5.37, a reliable version):
    wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
    
  • Extract it to /opt (a standard directory for apps):
    sudo tar xzf apache-tomcat-8.5.37.tar.gz -C /opt/
    
  • Rename the folder for easier access:
    sudo mv /opt/apache-tomcat-8.5.37 /opt/tomcat
    
  • Set permissions so your ubuntu user can manage Tomcat:
    sudo chown -R ubuntu:ubuntu /opt/tomcat
    
  • Start Tomcat to test:
    /opt/tomcat/bin/startup.sh
    
    Check if it's running with:
    curl http://localhost:8080
    
    You should get the default Tomcat welcome page HTML.

2. Configure Your Database

Since you have persistence components, let's set up a database (I'll assume MySQL here—adjust if you're using PostgreSQL or another DB):

Install MySQL Server

sudo apt-get install -y mysql-server

You'll be prompted to set a root password during installation—make sure to remember it.

Create Your App's Database & User

Log into MySQL:

mysql -u root -p

Run these commands inside the MySQL prompt to create a database, a dedicated user for your app, and grant permissions:

CREATE DATABASE your_app_db;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON your_app_db.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

If you have a database dump file, import it now:

mysql -u app_user -p your_app_db < /path/to/your/dump.sql

3. Upload & Package Your App

You have .xml, .jsp, .java files—you need to package these into a WAR file (Web Application Archive) for Tomcat to deploy.

Upload Your Code to the Server

Use scp with your SSH key to transfer your project folder:

scp -i /path/to/your/private-key -r your-project-folder ubuntu@10.1.10.0:/home/ubuntu/

Replace /path/to/your/private-key with the path to the key you use to log into the server.

Package the WAR File

If your project uses Maven (common for Java apps), install Maven first:

sudo apt-get install -y maven

Then navigate to your project folder and build the WAR:

cd /home/ubuntu/your-project-folder
mvn clean package

The WAR file will be generated in the target/ subfolder (e.g., target/your-app.war).

4. Deploy & Configure the App

Deploy the WAR to Tomcat

Copy the WAR file to Tomcat's webapps directory—Tomcat will auto-unpack and deploy it:

cp target/your-app.war /opt/tomcat/webapps/

Update Persistence Configs

Edit your app's persistence file (like hibernate.cfg.xml or persistence.xml) to use the database credentials you created earlier. Look for lines like this and update them:

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/your_app_db</property>
<property name="hibernate.connection.username">app_user</property>
<property name="hibernate.connection.password">your_secure_password</property>

If you edited the file directly in the unpacked app folder (under /opt/tomcat/webapps/your-app/), restart Tomcat to apply changes:

/opt/tomcat/bin/shutdown.sh && /opt/tomcat/bin/startup.sh

5. Test the Deployment

Test Locally on the Server

Run this command to check if your app responds:

curl http://localhost:8080/your-app/

Replace your-app with the name of your WAR file (without the .war extension). You should see your app's homepage HTML.

Test from Outside the Server

If you want to access the app externally, make sure Cybera's firewall (security group) for your server allows inbound traffic on port 8080. Then use the server's IP to access it:

http://10.1.10.0:8080/your-app/

Quick Troubleshooting Tips

  • If Tomcat won't start, check the logs for errors:
    tail -f /opt/tomcat/logs/catalina.out
    
  • Double-check that your Java version matches what your app was built with (e.g., if you used Java 8 locally, don't run Java 7 on the server).
  • Ensure file permissions are set correctly—Tomcat needs read/write access to the webapps directory.

内容的提问来源于stack exchange,提问作者KG96

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:33:26