如何从Java SE中的GlassFish服务器获取初始上下文?

我有一个类如下: public class Poligon { public static void main(String[] args) { try { Context ctx = new InitialContext(); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(“jms/javaee7/ConnectionFactory”); Destination destination = (Destination) ctx.lookup(“jms/javaee7/Topic”); JMSContext context = connectionFactory.createContext(); OrderDTO order = context.createConsumer(destination).receiveBody(OrderDTO.class); System.out.println(“Order received: ” + order); } catch (NamingException ex) { Logger.getLogger(Poligon.class.getName()).log(Level.SEVERE, null, ex); } } } 我想得到InitialContext()表单在localhost上运行的服务器(glassfish),但是我收到以下错误: SEVERE: null […]

在没有本地结账的情况下通过SVNKit提交更改的文件?

我正在使用SVNKit从我们的存储库中获取文件的内容。 我想在代码中更改内容并提交更改,而不必先检出文件。 我已经在网上搜索过,只找到了需要结账到本地文件系统的解决方案。 有谁知道这样做的方法?

Java相当于Ant的Java任务中的fork?

Ant Java任务提供了fork参数,根据定义“如果启用则触发另一个VM中的类执行” 。 当我们处理大量数据时,设置此参数可以使我们免于耗尽Java堆空间。 我们希望能够通过Java类做同样的事情。 实现fork提供的function的最佳方法是什么?

如何在Spring Data Rest应用程序中创建实体之间的引用

我正在尝试使用Spring Boot + Data Rest + JPA构建简单的应用程序。 A具有一对多关系的Category和Book实体: @Entity public class Category { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; @OneToMany(cascade = CascadeType.ALL, mappedBy = “category”) private Set books; …getters & setters next… } 和 @Entity public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; @ManyToOne private […]

我怎样才能在java日期对象中更改月份?

我有java日期对象。 如何在不改变年份的情况下更改月份。 例如 14年12月1日 我想把它改成 12/3/14和12/10/14 我基本上想在不改变年份的情况下将月份改变+/- x月。 可以吗?

有多少人被Java子串内存问题所困扰?

我最近发现java.lang.String.substring方法不返回一个新字符串,而是返回一个包含原始字符串的视图。 这可能会对记忆产生影响。 例如,如果您正在读取ascii文件,并使用子字符串解析文件中的标记并将子字符串的结果存储在内存中 – 您实际存储在内存中的是子字符串操作之前的整个字符串! 您当然可以通过在自己的版本中包装子字符串来解决此问题,该子字符串返回子字符串结果的新字符串。

我该如何解决MongoWaitQueueFullException?

我运行一个java程序,它是一个线程执行程序,它将数千个文档插入mongodb中的表。 我收到以下错误 Exception in thread “pool-1-thread-301” com.mongodb.MongoWaitQueueFullException: Too many threads are already waiting for a connection. Max number of threads (maxWaitQueueSize) of 500 has been exceeded. at com.mongodb.PooledConnectionProvider.get(PooledConnectionProvider.java:70) at com.mongodb.DefaultServer.getConnection(DefaultServer.java:73) at com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:221) at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:508) at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:456) at com.mongodb.DBTCPConnector.getPrimaryPort(DBTCPConnector.java:414) at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:176) at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:159) at com.mongodb.DBCollection.insert(DBCollection.java:93) at com.mongodb.DBCollection.insert(DBCollection.java:78) at com.mongodb.DBCollection.insert(DBCollection.java:120) at ScrapResults103$MyRunnable.run(MyProgram.java:368) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at […]

Java SimpleDateFormat解析Timezone,如America / Los_Angeles

我想在Java中解析以下字符串并将其转换为日期: DTSTART;TZID=America/Los_Angeles:20140423T120000 我试过这个: SimpleDateFormat sdf = new SimpleDateFormat(“‘DTSTART;TZID=’Z’:’yyyyMMdd’T’hhmmss”); Date start = sdf.parse(“DTSTART;TZID=America/Los_Angeles:20140423T120000”); 和这个: SimpleDateFormat sdf = new SimpleDateFormat(“‘DTSTART;TZID=’z’:’yyyyMMdd’T’hhmmss”); Date start = sdf.parse(“DTSTART;TZID=America/Los_Angeles:20140423T120000”); 但它仍然无效。 我认为问题出在America / Los_Angeles。 你能帮我吗? 谢谢

Roboelectric给了我一个java.lang.IllegalArgumentException:需要INTERNET权限

我正在将UnitTests改造为现有的应用程序。 当我运行这个简单的unit testing时 import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; import static junit.framework.Assert.assertTrue; @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, packageName = “com.blah.blah” ) public class TestThis { @Test public void blah(){ assertTrue(true); } } 我收到这个错误 java.lang.IllegalArgumentException: INTERNET permission is required. at com.segment.analytics.Analytics$Builder.(Analytics.java:585) at com.segment.analytics.Analytics.with(Analytics.java:115) at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:140) at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:433) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:240) at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188) at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) […]

初学者挥动递归

第一次在这里发帖 这个编程任务让我难以接受,代码如下: import java.awt.*; import javax.swing.*; public class HTree extends JPanel { private Color color = new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256)); public void draw(Graphics g, int n, double sz, double x, double y) { if (n == 0) return; double x0 = x – sz/2, x1 = x + sz/2; […]