java -classpath ccc/WEB-INF/classes com.world.install.Installer
pause
因为要依赖很多其他的包,怎么把那些依赖的包也添加进来。
这个bat文件该怎么写
12 个解决方案
#1
[root@AY1403221420500563ebZ classes]# java com.gt.world.oa.install.Installer
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.getMethod0(Class.java:2937)
at java.lang.Class.getMethod(Class.java:1771)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
[root@AY1403221420500563ebZ classes]#
比如按照我上面那么运行,可定是没有办法找到那些依赖包的,所以报错了。那到底该怎么把那些依赖包依赖进来呢?
#2
把你的程序打成jar包.然后用bat执行你的jar包不就可以了?
#3
@echo off
set CLASS_PATH=..\bin;..\lib\hsqldb.jar
set hqsl_jar=..\lib\hsqldb.jar
java -cp %hqsl_jar% -classpath %CLASS_PATH% j2se.csdn.DemoTable
#4
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
导出时选中包含所有lib
#5
你说的这种方式,能给个例子吗?
#6
如果程序是war包怎么办?
#7
有直接执行war的吗??war都是放在tomcat的webapp下得
#8
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
就是要部署web程序,需要先初始化表结构还有部分舒适化数据,需要先执行某个java文件
#9
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
就是要部署web程序,需要先初始化表结构还有部分舒适化数据,需要先执行某个java文件
建议写一个初始化servlet。在初始化servlet的init方法里做这样的事情
#10
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
就是要部署web程序,需要先初始化表结构还有部分舒适化数据,需要先执行某个java文件
建议写一个初始化servlet。在初始化servlet的init方法里做这样的事情
初始一些权限数据,所以只能初始化一次,不能每次启动都往数据库里面写一遍
#11
参考
public class InitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory
.getLog(com.cemso.util.InitServlet.class);
private UserDao userDao = new UserDaoImpl();
private TreenodeDao treenodeDao = new TreenodeDaoImpl();
private static boolean isWindows = true;
private static boolean isTest = false;
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public TreenodeDao getTreenodeDao() {
return treenodeDao;
}
public void setTreenodeDao(TreenodeDao treenodeDao) {
this.treenodeDao = treenodeDao;
}
public void init() {
if (log.isInfoEnabled()) {
log.info("init servlet called...");
}
if(isTest){
int size = treenodeDao.queryTreeNodes().size();
if(size == 0){
TreeNodeDTO treeNode = new TreeNodeDTO();
long current = System.currentTimeMillis();
int months = 6;
long expms = current + 30l*months*24*3600*1000;
treeNode.setIndexid(10001);
treeNode.setId("10001");
treeNode.setText(String.valueOf(expms));
treenodeDao.addTreeNode(treeNode);
}
}
// check os type
isWindows = isWindows();
XmlOperationTool.isWindos = isWindows;
ActionContext context = ActionContext.getContext();
Map<String,Object> session = null;
if(context != null){
session = context.getSession();
}
if(session != null){
session.put("widonws", isWindows);
session.put("isTest", isTest);
}
XmlOperationTool.isWindos = isWindows;
XmlOperationTool.isTest = isTest;
// set log4j.properties listener
String log4jConfig = null;
if(isWindows){
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(6);
}else{
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(5);
}
PropertyConfigurator.configureAndWatch(log4jConfig, 60 * 1000);
boolean flag = false;
if(isWindows){
flag = createConfigFolders() && createResourceFolder();
}else{
flag = createLinuxConfigFolders() && createLinuxResourceFolder();
}
if (userDao.nameNotExist("admin1")) {
flag &= createDefaultUser();
}
if (log.isInfoEnabled()) {
log.info("Device Status checker starting...");
}
CheckDeviceStateExcuter.checkStart();
}
private boolean isWindows() {
boolean flag = false;
String os = System.getProperties().getProperty("os.name");
if (log.isInfoEnabled()) {
log.info("OS is : " + os);
}
if (os.toUpperCase().indexOf("WINDOWS") != -1) {
flag = true;
}
return flag;
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(6);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml has been exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createLinuxConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createLinuxConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(5);
System.out.println("pathConfig:"+pathConfig);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("LINUX_PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("LINUX_CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
#12
参考
public class InitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory
.getLog(com.cemso.util.InitServlet.class);
private UserDao userDao = new UserDaoImpl();
private TreenodeDao treenodeDao = new TreenodeDaoImpl();
private static boolean isWindows = true;
private static boolean isTest = false;
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public TreenodeDao getTreenodeDao() {
return treenodeDao;
}
public void setTreenodeDao(TreenodeDao treenodeDao) {
this.treenodeDao = treenodeDao;
}
public void init() {
if (log.isInfoEnabled()) {
log.info("init servlet called...");
}
if(isTest){
int size = treenodeDao.queryTreeNodes().size();
if(size == 0){
TreeNodeDTO treeNode = new TreeNodeDTO();
long current = System.currentTimeMillis();
int months = 6;
long expms = current + 30l*months*24*3600*1000;
treeNode.setIndexid(10001);
treeNode.setId("10001");
treeNode.setText(String.valueOf(expms));
treenodeDao.addTreeNode(treeNode);
}
}
// check os type
isWindows = isWindows();
XmlOperationTool.isWindos = isWindows;
ActionContext context = ActionContext.getContext();
Map<String,Object> session = null;
if(context != null){
session = context.getSession();
}
if(session != null){
session.put("widonws", isWindows);
session.put("isTest", isTest);
}
XmlOperationTool.isWindos = isWindows;
XmlOperationTool.isTest = isTest;
// set log4j.properties listener
String log4jConfig = null;
if(isWindows){
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(6);
}else{
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(5);
}
PropertyConfigurator.configureAndWatch(log4jConfig, 60 * 1000);
boolean flag = false;
if(isWindows){
flag = createConfigFolders() && createResourceFolder();
}else{
flag = createLinuxConfigFolders() && createLinuxResourceFolder();
}
if (userDao.nameNotExist("admin1")) {
flag &= createDefaultUser();
}
if (log.isInfoEnabled()) {
log.info("Device Status checker starting...");
}
CheckDeviceStateExcuter.checkStart();
}
private boolean isWindows() {
boolean flag = false;
String os = System.getProperties().getProperty("os.name");
if (log.isInfoEnabled()) {
log.info("OS is : " + os);
}
if (os.toUpperCase().indexOf("WINDOWS") != -1) {
flag = true;
}
return flag;
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(6);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml has been exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createLinuxConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createLinuxConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(5);
System.out.println("pathConfig:"+pathConfig);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("LINUX_PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("LINUX_CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
膜拜一下
#1
[root@AY1403221420500563ebZ classes]# java com.gt.world.oa.install.Installer
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.getMethod0(Class.java:2937)
at java.lang.Class.getMethod(Class.java:1771)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
[root@AY1403221420500563ebZ classes]#
比如按照我上面那么运行,可定是没有办法找到那些依赖包的,所以报错了。那到底该怎么把那些依赖包依赖进来呢?
#2
把你的程序打成jar包.然后用bat执行你的jar包不就可以了?
#3
@echo off
set CLASS_PATH=..\bin;..\lib\hsqldb.jar
set hqsl_jar=..\lib\hsqldb.jar
java -cp %hqsl_jar% -classpath %CLASS_PATH% j2se.csdn.DemoTable
#4
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
导出时选中包含所有lib
#5
@echo off
set CLASS_PATH=..\bin;..\lib\hsqldb.jar
set hqsl_jar=..\lib\hsqldb.jar
java -cp %hqsl_jar% -classpath %CLASS_PATH% j2se.csdn.DemoTable
你说的这种方式,能给个例子吗?
#6
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
#7
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
#8
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
就是要部署web程序,需要先初始化表结构还有部分舒适化数据,需要先执行某个java文件
#9
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
就是要部署web程序,需要先初始化表结构还有部分舒适化数据,需要先执行某个java文件
建议写一个初始化servlet。在初始化servlet的init方法里做这样的事情
#10
建议导出jar包在用java -jar xxx.jar执行你的程序。
导出时选中包含所有lib
如果程序是war包怎么办?
有直接执行war的吗??war都是放在tomcat的webapp下得
就是要部署web程序,需要先初始化表结构还有部分舒适化数据,需要先执行某个java文件
建议写一个初始化servlet。在初始化servlet的init方法里做这样的事情
初始一些权限数据,所以只能初始化一次,不能每次启动都往数据库里面写一遍
#11
参考
public class InitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory
.getLog(com.cemso.util.InitServlet.class);
private UserDao userDao = new UserDaoImpl();
private TreenodeDao treenodeDao = new TreenodeDaoImpl();
private static boolean isWindows = true;
private static boolean isTest = false;
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public TreenodeDao getTreenodeDao() {
return treenodeDao;
}
public void setTreenodeDao(TreenodeDao treenodeDao) {
this.treenodeDao = treenodeDao;
}
public void init() {
if (log.isInfoEnabled()) {
log.info("init servlet called...");
}
if(isTest){
int size = treenodeDao.queryTreeNodes().size();
if(size == 0){
TreeNodeDTO treeNode = new TreeNodeDTO();
long current = System.currentTimeMillis();
int months = 6;
long expms = current + 30l*months*24*3600*1000;
treeNode.setIndexid(10001);
treeNode.setId("10001");
treeNode.setText(String.valueOf(expms));
treenodeDao.addTreeNode(treeNode);
}
}
// check os type
isWindows = isWindows();
XmlOperationTool.isWindos = isWindows;
ActionContext context = ActionContext.getContext();
Map<String,Object> session = null;
if(context != null){
session = context.getSession();
}
if(session != null){
session.put("widonws", isWindows);
session.put("isTest", isTest);
}
XmlOperationTool.isWindos = isWindows;
XmlOperationTool.isTest = isTest;
// set log4j.properties listener
String log4jConfig = null;
if(isWindows){
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(6);
}else{
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(5);
}
PropertyConfigurator.configureAndWatch(log4jConfig, 60 * 1000);
boolean flag = false;
if(isWindows){
flag = createConfigFolders() && createResourceFolder();
}else{
flag = createLinuxConfigFolders() && createLinuxResourceFolder();
}
if (userDao.nameNotExist("admin1")) {
flag &= createDefaultUser();
}
if (log.isInfoEnabled()) {
log.info("Device Status checker starting...");
}
CheckDeviceStateExcuter.checkStart();
}
private boolean isWindows() {
boolean flag = false;
String os = System.getProperties().getProperty("os.name");
if (log.isInfoEnabled()) {
log.info("OS is : " + os);
}
if (os.toUpperCase().indexOf("WINDOWS") != -1) {
flag = true;
}
return flag;
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(6);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml has been exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createLinuxConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createLinuxConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(5);
System.out.println("pathConfig:"+pathConfig);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("LINUX_PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("LINUX_CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
#12
参考
public class InitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory
.getLog(com.cemso.util.InitServlet.class);
private UserDao userDao = new UserDaoImpl();
private TreenodeDao treenodeDao = new TreenodeDaoImpl();
private static boolean isWindows = true;
private static boolean isTest = false;
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public TreenodeDao getTreenodeDao() {
return treenodeDao;
}
public void setTreenodeDao(TreenodeDao treenodeDao) {
this.treenodeDao = treenodeDao;
}
public void init() {
if (log.isInfoEnabled()) {
log.info("init servlet called...");
}
if(isTest){
int size = treenodeDao.queryTreeNodes().size();
if(size == 0){
TreeNodeDTO treeNode = new TreeNodeDTO();
long current = System.currentTimeMillis();
int months = 6;
long expms = current + 30l*months*24*3600*1000;
treeNode.setIndexid(10001);
treeNode.setId("10001");
treeNode.setText(String.valueOf(expms));
treenodeDao.addTreeNode(treeNode);
}
}
// check os type
isWindows = isWindows();
XmlOperationTool.isWindos = isWindows;
ActionContext context = ActionContext.getContext();
Map<String,Object> session = null;
if(context != null){
session = context.getSession();
}
if(session != null){
session.put("widonws", isWindows);
session.put("isTest", isTest);
}
XmlOperationTool.isWindos = isWindows;
XmlOperationTool.isTest = isTest;
// set log4j.properties listener
String log4jConfig = null;
if(isWindows){
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(6);
}else{
log4jConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "log4j.properties").substring(5);
}
PropertyConfigurator.configureAndWatch(log4jConfig, 60 * 1000);
boolean flag = false;
if(isWindows){
flag = createConfigFolders() && createResourceFolder();
}else{
flag = createLinuxConfigFolders() && createLinuxResourceFolder();
}
if (userDao.nameNotExist("admin1")) {
flag &= createDefaultUser();
}
if (log.isInfoEnabled()) {
log.info("Device Status checker starting...");
}
CheckDeviceStateExcuter.checkStart();
}
private boolean isWindows() {
boolean flag = false;
String os = System.getProperties().getProperty("os.name");
if (log.isInfoEnabled()) {
log.info("OS is : " + os);
}
if (os.toUpperCase().indexOf("WINDOWS") != -1) {
flag = true;
}
return flag;
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(6);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml has been exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
// create playlist CONFIG WEB_CONTENT folders
private boolean createLinuxConfigFolders() {
if (log.isInfoEnabled()) {
log.info("InitServlet.createLinuxConfigFolders() called...");
}
try {
String pathConfig = (Thread.currentThread().getContextClassLoader()
.getResource("") + "pathconfig.properties").substring(5);
System.out.println("pathConfig:"+pathConfig);
File pf = new File(pathConfig);
// 生成文件输入流
FileInputStream inpf = new FileInputStream(pf);
// 生成properties对象
Properties p = new Properties();
p.load(inpf);
XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER = p
.getProperty("LINUX_PLAYLIST_TEMPFILE_FOLDER");
XmlOperationTool.CONFIG_FOLDER = p.getProperty("LINUX_CONFIG_FOLDER");
XmlOperationTool.WEB_CONTENT = getServletConfig()
.getServletContext().getRealPath("/");
// 创建资源文件夹
if (!(new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder does not exist...");
log.info("create "
+ XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder is starting...");
}
new File(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.PLAYLIST_TEMPFILE_FOLDER
+ " folder has been exist...");
}
}
// create configuration folder
if (!(new File(XmlOperationTool.CONFIG_FOLDER).exists())) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder does not exist...");
log.info("create " + XmlOperationTool.CONFIG_FOLDER
+ " config folder is starting...");
}
new File(XmlOperationTool.CONFIG_FOLDER).mkdirs();
} else {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ " config folder has been exist...");
}
}
if (new File(XmlOperationTool.CONFIG_FOLDER + "tree.xml").exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.CONFIG_FOLDER
+ "tree.xml exist...");
}
File f = new File(XmlOperationTool.WEB_CONTENT + "tree.xml");
if (f.exists()) {
if (log.isInfoEnabled()) {
log.info(XmlOperationTool.WEB_CONTENT
+ "tree.xml has been exist...");
log.info("start to delete :"
+ XmlOperationTool.WEB_CONTENT
+ "tree.xml ...");
}
f.deleteOnExit();
}
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"), new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"));
} else {
FileOperationTool.ChannelCopy(new File(
XmlOperationTool.WEB_CONTENT + "tree.xml"), new File(
XmlOperationTool.CONFIG_FOLDER + "tree.xml"));
}
return true;
} catch (FileNotFoundException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
} catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
e.printStackTrace();
log.error(e.getMessage());
}
return false;
} catch (Exception e) {
if (log.isErrorEnabled()) {
log.error("create config folders files failed...");
log.error(e.getMessage());
}
return false;
}
}
膜拜一下