从批处理文件运行Java程序的问题,在IDE中运行良好 [英] Issue running java program from batch file, runs fine in IDE

查看:111
本文介绍了从批处理文件运行Java程序的问题,在IDE中运行良好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为新笔记本电脑上的类做一些基本的Java作业-问题是,我似乎无法按照讲师给我的指导从批处理文件编译和运行该程序.

I'm doing some basic java homework for a class on my new laptop - issue is, I can't seem to get the program to compile and run from my batch file using the directions the instructor gave me.

我已经在环境变量"设置中将Path变量设置为我的JDK.

I've set the Path variable to my JDK inside the Environment Variables settings.

我的程序是一个简单的货运程序,用于跟踪货运信息-我的程序在NetBeans中运行正常(我们的讲师建议我们使用该程序来开发代码),但是他将使用批处理文件对其进行测试,因此,我们还建议在上交之前先用我们创建的系统在我们的系统上对其进行测试-相当简单.

My program is a simple shipping program to keep track of shipment information - I have the program working flawlessly in NetBeans (which our instructor advised us to use for developing the code), but he's going to be testing them using batch files, so we're also advised to test them on our systems with one we create prior to turning them in - pretty straightforward.

问题是,我似乎无法使它正常工作.我以前从未做过,但是我使用过.bat文件来编译和运行C ++程序,以及在unix系统上使用makefile,所以我觉得我很傻,因为我自己都不搞清楚这一点. ,但我的搜索都没有返回任何有益的解决方案.

Issue is, I cannot seem to get this to work. I've never done it before, but I've used .bat files to compile and run C++ programs, as well as using makefiles on a unix system, so I feel like I'm absolutely stupid for not figuring this out on my own, but none of my searches have returned any fruitful solutions that help at all.

我的程序包含3个.java文件:

My program consists of 3 .java files:

Shipment.java -一个包含在ShipmentHW1类中实现的抽象方法的接口

Shipment.java - an interface that contains abstracted methods that are implemented in the ShipmentHW1 class

ShipmentHW1.java -一个类,用于实现Shipment中的抽象方法并具有构造函数等以创建可用的对象

ShipmentHW1.java - a class that implements the abstracted methods from Shipment and has constructors, etc to create a usable object

TestShipment.java -该程序的主类,它根据预设参数利用和创建ShipmentHW1对象.这是超级duper的基础知识,再次,它在NetBeans IDE中运行得非常好.

TestShipment.java - the main class of this program, which utilizes and creates ShipmentHW1 objects based on preset parameters. This is super duper basic stuff here, and again, it runs perfectly fine inside the NetBeans IDE.

提供给我们的说明要求将批处理文件放在包目录中(在这种情况下,我已经在桌面上预留了一个单独的文件夹,名称为"shipping",即包名称,不应为任何其他名称)问题),以及3个.java文件所在的位置.

The instructions given to us state to have the batch file inside the package directory (which in this case I've set aside a seperate folder on my desktop titled "shipping", which is the package name - shouldn't be any issues there), where the 3 .java files are located as well.

他们说,如果您不需要显式列出JDK的路径,则只需拥有

They say if you don't need to explicitly list the path to the JDK, then you can simply have

    javac TestShipment.java
java TestShipment.java
pause

此后,我在谈论如何找不到符号Shipment s = new ShipmentHW1();"时出错. 我尝试添加导入,但是由于它们位于同一个程序包中,所以甚至都不是问题.

Afterwards I get errors talking about how it "cannot find symbol Shipment s = new ShipmentHW1();" I've tried adding imports, but since they're in the same package it shouldn't even be an issue.

目录路径为

C:\Users\X\Desktop\shipping

所有7个文件都包含在以下内容中:

All 7 files are contained within:

TestShipment.java
TestShipment.class
Shipment.java
Shipment.class
ShipmentHW1.java
ShipmentHW1.class
doHW1.bat

有人有什么主意吗?如果我不太清楚,我可以提供更多信息

Does anyone have any idea? I can provide more information if I've been too vague

此外,如果有任何不同,我正在Windows 8上

Also, I'm on Windows 8 if that makes any difference

推荐答案

已解决

批处理文件现在可以读取

Batch file now reads

javac TestShipment.java Shipment.java ShipmentHW1.java
cd ..
java shipment.TestShipment
pause

,它就像一种魅力.任何人都知道为什么我不得不调用package.class而不是仅仅定期对其进行编译?

and it works like a charm. Anyone have any ideas why I had to call the package.class instead of just compiling it regularly?

这篇关于从批处理文件运行Java程序的问题,在IDE中运行良好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆