如何从现有 Java 项目中提取主类?
我有一个大型 Struts1 Web 项目,也使用 Hibernate。
我们的包之一是:
com.company.examples.users
。
另一个是:
com.company.examples.orders
。
每个包中都有一个用于测试的 main.java
文件(实际上是从 Netbeans 中运行该文件)。
因此,我可以右键单击主文件并让它运行,输出将显示在日志窗口中。那很好。但我希望能够将它们提取到实际的 JAR 文件中,以便它们可以单独运行。
这些文件还依赖于整个更大的项目。很多包裹等等,
我该怎么办?
I have a large Struts1 web project that also uses Hibernate.
One of our packages is:
com.company.examples.users
.
Another is:
com.company.examples.orders
.
Within each of those packages is a main.java
file that is used for testing (actually running the file from within Netbeans).
So I can right-click the main files and tell it to run and the output is displayed in the log window. That is fine. But I want to be able to extract them out into actual JAR files so that they can be ran individually.
These files also rely on the entire, larger project. Lots of packages, etc.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种快速但肮脏的 dos 方法。创建一个文件夹并
cd
进入其中。将 WAR 文件、
prepare-tests.bat
和make-classpath.bat
文件复制到该文件夹中。其中
prepare-tests.bat
是:make-classpath.bat
是:基本上,这些步骤将解压 WAR、打包 WAR 的类(如果有)并创建指向这些类以及 WEB-INF/lib 文件夹中所有 JAR 的类路径。
然后,您可以通过以下方式运行测试(从您创建的
test
文件夹中):不过,您最好使用 Maven 和 JUnit 等工具来自动化/简化您的测试。
Here's a quick and dirty dos way. Create a folder and
cd
into it.Copy your WAR file, the
prepare-tests.bat
andmake-classpath.bat
files into that folder.Where
prepare-tests.bat
is:And
make-classpath.bat
is:Basically, these steps will unpack the WAR, jar up the WAR's classes (if any) and create a classpath that points to those classes plus all the JARs in your
WEB-INF/lib
folder.You can then run tests (from within the
test
folder you created) by:You'd be much better off using tools like Maven and JUnit to automate/facilitate your testing though.